summaryrefslogtreecommitdiff
path: root/lib/common/NamedLock.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/common/NamedLock.h')
-rw-r--r--lib/common/NamedLock.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/common/NamedLock.h b/lib/common/NamedLock.h
new file mode 100644
index 00000000..a7d0d778
--- /dev/null
+++ b/lib/common/NamedLock.h
@@ -0,0 +1,50 @@
+// --------------------------------------------------------------------------
+//
+// File
+// Name: NamedLock.h
+// Purpose: A global named lock, implemented as a lock file in file system
+// Created: 2003/08/28
+//
+// --------------------------------------------------------------------------
+
+#ifndef NAMEDLOCK__H
+#define NAMEDLOCK__H
+
+// --------------------------------------------------------------------------
+//
+// Class
+// Name: NamedLock
+// Purpose: A global named lock, implemented as a lock file in file system
+// Created: 2003/08/28
+//
+// --------------------------------------------------------------------------
+class NamedLock
+{
+public:
+ NamedLock();
+ ~NamedLock();
+private:
+ // No copying allowed
+ NamedLock(const NamedLock &);
+
+public:
+ bool TryAndGetLock(const std::string& rFilename, int mode = 0755);
+# ifdef WIN32
+ bool GotLock() {return mFileDescriptor != INVALID_HANDLE_VALUE;}
+# else
+ bool GotLock() {return mFileDescriptor != -1;}
+# endif
+ void ReleaseLock();
+
+private:
+# ifdef WIN32
+ HANDLE mFileDescriptor;
+# else
+ int mFileDescriptor;
+# endif
+
+ std::string mFileName;
+};
+
+#endif // NAMEDLOCK__H
+