00001
00002
00003 #ifndef __ARC_FILELOCK_H__
00004 #define __ARC_FILELOCK_H__
00005
00006 #include <string>
00007
00008 #include <arc/Logger.h>
00009
00010 namespace Arc {
00011
00013
00034 class FileLock {
00035 public:
00037 const static int DEFAULT_LOCK_TIMEOUT;
00039 const static std::string LOCK_SUFFIX;
00040
00042
00049 FileLock(const std::string& filename,
00050 unsigned int timeout=DEFAULT_LOCK_TIMEOUT,
00051 bool use_pid=true);
00052
00054
00066 bool acquire(bool& lock_removed);
00067
00069
00073 bool acquire();
00074
00076
00079 bool release(bool force=false);
00080
00082
00090 int check(bool log_error = true);
00091
00093 static std::string getLockSuffix();
00094
00095 private:
00097 std::string filename;
00099 std::string lock_file;
00101 int timeout;
00103 bool use_pid;
00105 std::string pid;
00107 std::string hostname;
00109 static Logger logger;
00110
00112 bool acquire_(bool& lock_removed);
00113
00115 bool write_pid(int h);
00116 };
00117
00118 }
00119
00120 #endif