aboutsummaryrefslogtreecommitdiff
path: root/odb/details/lock.hxx
diff options
context:
space:
mode:
Diffstat (limited to 'odb/details/lock.hxx')
-rw-r--r--odb/details/lock.hxx46
1 files changed, 46 insertions, 0 deletions
diff --git a/odb/details/lock.hxx b/odb/details/lock.hxx
new file mode 100644
index 0000000..0ee5a6d
--- /dev/null
+++ b/odb/details/lock.hxx
@@ -0,0 +1,46 @@
+// file : odb/details/lock.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_DETAILS_LOCK_HXX
+#define ODB_DETAILS_LOCK_HXX
+
+#include <odb/details/posix/mutex.hxx>
+
+namespace odb
+{
+ namespace details
+ {
+ struct lock
+ {
+ lock (mutex& m)
+ : mutex_ (m), locked_ (true)
+ {
+ mutex_.lock ();
+ }
+
+ ~lock ()
+ {
+ if (locked_)
+ mutex_.unlock ();
+ }
+
+ void
+ unlock ()
+ {
+ if (locked_)
+ {
+ mutex_.unlock ();
+ locked_ = true;
+ }
+ }
+
+ private:
+ mutex& mutex_;
+ bool locked_;
+ };
+ }
+}
+
+#endif // ODB_DETAILS_LOCK_HXX