Changeset View
Changeset View
Standalone View
Standalone View
src/sync.h
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_SYNC_H | #ifndef BITCOIN_SYNC_H | ||||
#define BITCOIN_SYNC_H | #define BITCOIN_SYNC_H | ||||
#include <threadsafety.h> | #include <threadsafety.h> | ||||
#include <util/macros.h> | |||||
#include <condition_variable> | #include <condition_variable> | ||||
#include <mutex> | #include <mutex> | ||||
#include <thread> | #include <thread> | ||||
///////////////////////////////////////////////// | ///////////////////////////////////////////////// | ||||
// // | // // | ||||
// THE SIMPLE DEFINITION, EXCLUDING DEBUG CODE // | // THE SIMPLE DEFINITION, EXCLUDING DEBUG CODE // | ||||
▲ Show 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | public: | ||||
operator bool() { return Base::owns_lock(); } | operator bool() { return Base::owns_lock(); } | ||||
}; | }; | ||||
template <typename MutexArg> | template <typename MutexArg> | ||||
using DebugLock = UniqueLock<typename std::remove_reference< | using DebugLock = UniqueLock<typename std::remove_reference< | ||||
typename std::remove_pointer<MutexArg>::type>::type>; | typename std::remove_pointer<MutexArg>::type>::type>; | ||||
#define PASTE(x, y) x##y | |||||
#define PASTE2(x, y) PASTE(x, y) | |||||
#define LOCK(cs) \ | #define LOCK(cs) \ | ||||
DebugLock<decltype(cs)> PASTE2(criticalblock, \ | DebugLock<decltype(cs)> PASTE2(criticalblock, \ | ||||
__COUNTER__)(cs, #cs, __FILE__, __LINE__) | __COUNTER__)(cs, #cs, __FILE__, __LINE__) | ||||
#define LOCK2(cs1, cs2) \ | #define LOCK2(cs1, cs2) \ | ||||
DebugLock<decltype(cs1)> criticalblock1(cs1, #cs1, __FILE__, __LINE__); \ | DebugLock<decltype(cs1)> criticalblock1(cs1, #cs1, __FILE__, __LINE__); \ | ||||
DebugLock<decltype(cs2)> criticalblock2(cs2, #cs2, __FILE__, __LINE__); | DebugLock<decltype(cs2)> criticalblock2(cs2, #cs2, __FILE__, __LINE__); | ||||
#define TRY_LOCK(cs, name) \ | #define TRY_LOCK(cs, name) \ | ||||
DebugLock<decltype(cs)> name(cs, #cs, __FILE__, __LINE__, true) | DebugLock<decltype(cs)> name(cs, #cs, __FILE__, __LINE__, true) | ||||
▲ Show 20 Lines • Show All 102 Lines • Show Last 20 Lines |