ARC SDK
FileLock.h
1 // -*- indent-tabs-mode: nil -*-
2 
3 #ifndef __ARC_FILELOCK_H__
4 #define __ARC_FILELOCK_H__
5 
6 #include <string>
7 
8 #include <arc/Logger.h>
9 
10 namespace Arc {
11 
13 
36  class FileLock {
37  public:
39  const static int DEFAULT_LOCK_TIMEOUT;
41  const static std::string LOCK_SUFFIX;
42 
44 
50  FileLock(const std::string& filename,
51  unsigned int timeout=DEFAULT_LOCK_TIMEOUT,
52  bool use_pid=true);
53 
55 
67  bool acquire(bool& lock_removed);
68 
70 
75  bool acquire();
76 
78 
82  bool release(bool force=false);
83 
85 
93  int check(bool log_error = true);
94 
96  static std::string getLockSuffix();
97 
98  private:
100  std::string filename;
102  std::string lock_file;
104  int timeout;
106  bool use_pid;
108  std::string pid;
110  std::string hostname;
112  static Logger logger;
113 
115  bool acquire_(bool& lock_removed);
116 
118  bool write_pid(int h);
119  };
120 
121 } // namespace Arc
122 
123 #endif