aboutsummaryrefslogtreecommitdiff
path: root/src/reverselock.h
diff options
context:
space:
mode:
authorCasey Rodarmor <casey@rodarmor.com>2015-09-03 12:53:00 -0400
committerCasey Rodarmor <casey@rodarmor.com>2015-09-03 15:13:40 -0400
commit86270c816411680c33a60adfa768c7a647fce08f (patch)
tree8e8e3f427d23ec88dab51cb99ab5314590997f75 /src/reverselock.h
parentda9beb288d2ee35b9c70513dd18f220b2dc32f16 (diff)
Replace boost::reverse_lock with our own.
Diffstat (limited to 'src/reverselock.h')
-rw-r--r--src/reverselock.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/reverselock.h b/src/reverselock.h
new file mode 100644
index 0000000000..567636e16a
--- /dev/null
+++ b/src/reverselock.h
@@ -0,0 +1,31 @@
+// Copyright (c) 2015 The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#ifndef BITCOIN_REVERSELOCK_H
+#define BITCOIN_REVERSELOCK_H
+
+/**
+ * An RAII-style reverse lock. Unlocks on construction and locks on destruction.
+ */
+template<typename Lock>
+class reverse_lock
+{
+public:
+
+ explicit reverse_lock(Lock& lock) : lock(lock) {
+ lock.unlock();
+ }
+
+ ~reverse_lock() {
+ lock.lock();
+ }
+
+private:
+ reverse_lock(reverse_lock const&);
+ reverse_lock& operator=(reverse_lock const&);
+
+ Lock& lock;
+};
+
+#endif // BITCOIN_REVERSELOCK_H