diff options
author | Casey Rodarmor <casey@rodarmor.com> | 2015-09-03 12:53:00 -0400 |
---|---|---|
committer | Casey Rodarmor <casey@rodarmor.com> | 2015-09-03 15:13:40 -0400 |
commit | 86270c816411680c33a60adfa768c7a647fce08f (patch) | |
tree | 8e8e3f427d23ec88dab51cb99ab5314590997f75 /src/reverselock.h | |
parent | da9beb288d2ee35b9c70513dd18f220b2dc32f16 (diff) |
Replace boost::reverse_lock with our own.
Diffstat (limited to 'src/reverselock.h')
-rw-r--r-- | src/reverselock.h | 31 |
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 |