diff options
author | Russell Yanofsky <russ@yanofsky.org> | 2017-07-26 10:23:01 -0400 |
---|---|---|
committer | Russell Yanofsky <russ@yanofsky.org> | 2018-11-06 11:44:40 -0400 |
commit | 79d579f4e11b57f90fed314bccd25230f918729f (patch) | |
tree | 1886caa0cd9fdf2aaaa84ad7160472d87e0eb68c /src/interfaces/chain.cpp | |
parent | ea961c3d7256c66146b4976ab1293db4a628c0de (diff) |
Remove uses of cs_main in wallet code
This commit does not change behavior.
It is easiest to review this change with:
git log -p -n1 -U0
Diffstat (limited to 'src/interfaces/chain.cpp')
-rw-r--r-- | src/interfaces/chain.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp index 28b36717d5..2571a91031 100644 --- a/src/interfaces/chain.cpp +++ b/src/interfaces/chain.cpp @@ -4,13 +4,37 @@ #include <interfaces/chain.h> +#include <sync.h> #include <util/system.h> +#include <validation.h> + +#include <memory> +#include <utility> namespace interfaces { namespace { +class LockImpl : public Chain::Lock +{ +}; + +class LockingStateImpl : public LockImpl, public UniqueLock<CCriticalSection> +{ + using UniqueLock::UniqueLock; +}; + class ChainImpl : public Chain { +public: + std::unique_ptr<Chain::Lock> lock(bool try_lock) override + { + auto result = MakeUnique<LockingStateImpl>(::cs_main, "cs_main", __FILE__, __LINE__, try_lock); + if (try_lock && result && !*result) return {}; + // std::move necessary on some compilers due to conversion from + // LockingStateImpl to Lock pointer + return std::move(result); + } + std::unique_ptr<Chain::Lock> assumeLocked() override { return MakeUnique<LockImpl>(); } }; } // namespace |