diff --git a/src/addrman.h b/src/addrman.h --- a/src/addrman.h +++ b/src/addrman.h @@ -186,7 +186,7 @@ class CAddrMan { protected: //! critical section to protect the inner data structures - mutable CCriticalSection cs; + mutable RecursiveMutex cs; private: //! last used nId diff --git a/src/banman.h b/src/banman.h --- a/src/banman.h +++ b/src/banman.h @@ -61,7 +61,7 @@ //! clean unused entries (if bantime has expired) void SweepBanned(); - CCriticalSection m_cs_banned; + RecursiveMutex m_cs_banned; banmap_t m_banned GUARDED_BY(m_cs_banned); bool m_is_dirty GUARDED_BY(m_cs_banned); CClientUIInterface *m_client_interface = nullptr; diff --git a/src/chain.h b/src/chain.h --- a/src/chain.h +++ b/src/chain.h @@ -262,7 +262,7 @@ } }; -extern CCriticalSection cs_main; +extern RecursiveMutex cs_main; typedef std::unordered_map BlockMap; extern BlockMap &mapBlockIndex GUARDED_BY(cs_main); diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -198,7 +198,7 @@ void Shutdown(InitInterfaces &interfaces) { LogPrintf("%s: In progress...\n", __func__); - static CCriticalSection cs_Shutdown; + static RecursiveMutex cs_Shutdown; TRY_LOCK(cs_Shutdown, lockShutdown); if (!lockShutdown) { return; diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp --- a/src/interfaces/chain.cpp +++ b/src/interfaces/chain.cpp @@ -144,7 +144,7 @@ }; class LockingStateImpl : public LockImpl, - public UniqueLock { + public UniqueLock { using UniqueLock::UniqueLock; }; diff --git a/src/keystore.h b/src/keystore.h --- a/src/keystore.h +++ b/src/keystore.h @@ -18,7 +18,7 @@ /** A virtual base class for key stores */ class CKeyStore : public SigningProvider { protected: - mutable CCriticalSection cs_KeyStore; + mutable RecursiveMutex cs_KeyStore; public: //! Add a key to the store. @@ -45,7 +45,7 @@ /** Basic key store, that keeps keys in an address->secret map */ class CBasicKeyStore : public CKeyStore { protected: - mutable CCriticalSection cs_KeyStore; + mutable RecursiveMutex cs_KeyStore; using KeyMap = std::map; using WatchKeyMap = std::map; diff --git a/src/net.h b/src/net.h --- a/src/net.h +++ b/src/net.h @@ -378,8 +378,8 @@ const Config *config; // Network usage totals - CCriticalSection cs_totalBytesRecv; - CCriticalSection cs_totalBytesSent; + RecursiveMutex cs_totalBytesRecv; + RecursiveMutex cs_totalBytesSent; uint64_t nTotalBytesRecv GUARDED_BY(cs_totalBytesRecv); uint64_t nTotalBytesSent GUARDED_BY(cs_totalBytesSent); @@ -404,12 +404,12 @@ bool fAddressesInitialized{false}; CAddrMan addrman; std::deque vOneShots GUARDED_BY(cs_vOneShots); - CCriticalSection cs_vOneShots; + RecursiveMutex cs_vOneShots; std::vector vAddedNodes GUARDED_BY(cs_vAddedNodes); - CCriticalSection cs_vAddedNodes; + RecursiveMutex cs_vAddedNodes; std::vector vNodes GUARDED_BY(cs_vNodes); std::list vNodesDisconnected; - mutable CCriticalSection cs_vNodes; + mutable RecursiveMutex cs_vNodes; std::atomic nLastNodeId{0}; unsigned int nPrevNodeCount{0}; @@ -535,7 +535,7 @@ int nPort; }; -extern CCriticalSection cs_mapLocalHost; +extern RecursiveMutex cs_mapLocalHost; extern std::map mapLocalHost GUARDED_BY(cs_mapLocalHost); @@ -644,15 +644,15 @@ size_t nSendOffset{0}; uint64_t nSendBytes GUARDED_BY(cs_vSend){0}; std::deque> vSendMsg GUARDED_BY(cs_vSend); - CCriticalSection cs_vSend; - CCriticalSection cs_hSocket; - CCriticalSection cs_vRecv; + RecursiveMutex cs_vSend; + RecursiveMutex cs_hSocket; + RecursiveMutex cs_vRecv; - CCriticalSection cs_vProcessMsg; + RecursiveMutex cs_vProcessMsg; std::list vProcessMsg GUARDED_BY(cs_vProcessMsg); size_t nProcessQueueSize{0}; - CCriticalSection cs_sendProcessing; + RecursiveMutex cs_sendProcessing; std::deque vRecvGetData; uint64_t nRecvBytes GUARDED_BY(cs_vRecv){0}; @@ -675,7 +675,7 @@ std::string strSubVer GUARDED_BY(cs_SubVer), cleanSubVer GUARDED_BY(cs_SubVer); // Used for both cleanSubVer and strSubVer. - CCriticalSection cs_SubVer; + RecursiveMutex cs_SubVer; // This peer is preferred for eviction. bool m_prefer_evict{false}; // This peer can bypass DoS banning. @@ -699,7 +699,7 @@ bool fRelayTxes GUARDED_BY(cs_filter){false}; bool fSentAddr{false}; CSemaphoreGrant grantOutbound; - mutable CCriticalSection cs_filter; + mutable RecursiveMutex cs_filter; std::unique_ptr pfilter PT_GUARDED_BY(cs_filter); std::atomic nRefCount{0}; @@ -732,7 +732,7 @@ // before sending, as they are always sent immediately and in the order // requested. std::vector vInventoryBlockToSend GUARDED_BY(cs_inventory); - CCriticalSection cs_inventory; + RecursiveMutex cs_inventory; int64_t nNextInvSend{0}; // Used for headers announcements - unfiltered blocks to relay. std::vector vBlockHashesToAnnounce GUARDED_BY(cs_inventory); @@ -759,7 +759,7 @@ std::atomic fPingQueued{false}; // Minimum fee rate with which to filter inv's to this node Amount minFeeFilter GUARDED_BY(cs_feeFilter){Amount::zero()}; - CCriticalSection cs_feeFilter; + RecursiveMutex cs_feeFilter; Amount lastSentFeeFilter{Amount::zero()}; int64_t nextSendTimeFeeFilter{0}; @@ -781,12 +781,12 @@ // Used only by SocketHandler thread. std::list vRecvMsg; - mutable CCriticalSection cs_addrName; + mutable RecursiveMutex cs_addrName; std::string addrName GUARDED_BY(cs_addrName); // Our address, as reported by the peer CService addrLocal GUARDED_BY(cs_addrLocal); - mutable CCriticalSection cs_addrLocal; + mutable RecursiveMutex cs_addrLocal; public: NodeId GetId() const { return id; } diff --git a/src/net.cpp b/src/net.cpp --- a/src/net.cpp +++ b/src/net.cpp @@ -89,7 +89,7 @@ bool fDiscover = true; bool fListen = true; bool fRelayTxes = true; -CCriticalSection cs_mapLocalHost; +RecursiveMutex cs_mapLocalHost; std::map mapLocalHost GUARDED_BY(cs_mapLocalHost); static bool vfLimited[NET_MAX] GUARDED_BY(cs_mapLocalHost) = {}; diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -128,7 +128,7 @@ int64_t nTimeExpire; }; -CCriticalSection g_cs_orphans; +RecursiveMutex g_cs_orphans; std::map mapOrphanTransactions GUARDED_BY(g_cs_orphans); void EraseOrphansFor(NodeId peer); @@ -1268,7 +1268,7 @@ // All of the following cache a recent block, and are protected by // cs_most_recent_block -static CCriticalSection cs_most_recent_block; +static RecursiveMutex cs_most_recent_block; static std::shared_ptr most_recent_block GUARDED_BY(cs_most_recent_block); static std::shared_ptr diff --git a/src/netbase.cpp b/src/netbase.cpp --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -25,7 +25,7 @@ #endif // Settings -static CCriticalSection cs_proxyInfos; +static RecursiveMutex cs_proxyInfos; static proxyType proxyInfo[NET_MAX] GUARDED_BY(cs_proxyInfos); static proxyType nameProxy GUARDED_BY(cs_proxyInfos); int nConnectTimeout = DEFAULT_CONNECT_TIMEOUT; diff --git a/src/rcu.cpp b/src/rcu.cpp --- a/src/rcu.cpp +++ b/src/rcu.cpp @@ -102,7 +102,7 @@ * we rely on as a result. */ static std::atomic threadInfos{nullptr}; -static CCriticalSection csThreadInfosDelete; +static RecursiveMutex csThreadInfosDelete; RCUInfos::RCUInfos() : state(0), next(nullptr) { RCUInfos *head = threadInfos.load(); diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -30,7 +30,7 @@ static std::atomic g_rpc_running{false}; static bool fRPCInWarmup = true; static std::string rpcWarmupStatus("RPC server started"); -static CCriticalSection cs_rpcWarmup; +static RecursiveMutex cs_rpcWarmup; /* Timer-creating functions */ static RPCTimerInterface *timerInterface = nullptr; /* Map of name to timer. */ diff --git a/src/scheduler.h b/src/scheduler.h --- a/src/scheduler.h +++ b/src/scheduler.h @@ -102,7 +102,7 @@ private: CScheduler *m_pscheduler; - CCriticalSection m_cs_callbacks_pending; + RecursiveMutex m_cs_callbacks_pending; std::list> m_callbacks_pending GUARDED_BY(m_cs_callbacks_pending); bool m_are_callbacks_running GUARDED_BY(m_cs_callbacks_pending) = false; diff --git a/src/seeder/db.h b/src/seeder/db.h --- a/src/seeder/db.h +++ b/src/seeder/db.h @@ -278,7 +278,7 @@ */ class CAddrDb { private: - mutable CCriticalSection cs; + mutable RecursiveMutex cs; // number of address id's int nId; // map address id to address info (b,c,d,e) diff --git a/src/sync.h b/src/sync.h --- a/src/sync.h +++ b/src/sync.h @@ -102,7 +102,6 @@ * TODO: We should move away from using the recursive lock by default. */ using RecursiveMutex = AnnotatedMixin; -typedef AnnotatedMixin CCriticalSection; /** Wrapped mutex: supports waiting but not recursive locking */ typedef AnnotatedMixin Mutex; diff --git a/src/sync.cpp b/src/sync.cpp --- a/src/sync.cpp +++ b/src/sync.cpp @@ -61,7 +61,7 @@ struct LockData { // Very ugly hack: as the global constructs and destructors run single // threaded, we use this boolean to know whether LockData still exists, - // as DeleteLock can get called by global CCriticalSection destructors + // as DeleteLock can get called by global RecursiveMutex destructors // after LockData disappears. bool available; LockData() : available(true) {} diff --git a/src/test/denialofservice_tests.cpp b/src/test/denialofservice_tests.cpp --- a/src/test/denialofservice_tests.cpp +++ b/src/test/denialofservice_tests.cpp @@ -49,7 +49,7 @@ NodeId fromPeer; int64_t nTimeExpire; }; -extern CCriticalSection g_cs_orphans; +extern RecursiveMutex g_cs_orphans; extern std::map mapOrphanTransactions GUARDED_BY(g_cs_orphans); diff --git a/src/test/sync_tests.cpp b/src/test/sync_tests.cpp --- a/src/test/sync_tests.cpp +++ b/src/test/sync_tests.cpp @@ -34,7 +34,7 @@ g_debug_lockorder_abort = false; #endif - CCriticalSection rmutex1, rmutex2; + RecursiveMutex rmutex1, rmutex2; TestPotentialDeadLockDetected(rmutex1, rmutex2); Mutex mutex1, mutex2; diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -27,7 +27,7 @@ BOOST_FIXTURE_TEST_SUITE(util_tests, BasicTestingSetup) BOOST_AUTO_TEST_CASE(util_criticalsection) { - CCriticalSection cs; + RecursiveMutex cs; do { LOCK(cs); diff --git a/src/timedata.cpp b/src/timedata.cpp --- a/src/timedata.cpp +++ b/src/timedata.cpp @@ -15,7 +15,7 @@ #include #include -static CCriticalSection cs_nTimeOffset; +static RecursiveMutex cs_nTimeOffset; static int64_t nTimeOffset = 0; /** diff --git a/src/txmempool.h b/src/txmempool.h --- a/src/txmempool.h +++ b/src/txmempool.h @@ -29,7 +29,7 @@ class CBlockIndex; class Config; -extern CCriticalSection cs_main; +extern RecursiveMutex cs_main; /** * Fake height value used in Coins to signify they are only in the memory diff --git a/src/util/system.h b/src/util/system.h --- a/src/util/system.h +++ b/src/util/system.h @@ -168,7 +168,7 @@ unsigned int m_flags; }; - mutable CCriticalSection cs_args; + mutable RecursiveMutex cs_args; std::map> m_override_args GUARDED_BY(cs_args); std::map> diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -181,7 +181,7 @@ static const int64_t DEFAULT_MIN_FINALIZATION_DELAY = 2 * 60 * 60; extern CScript COINBASE_FLAGS; -extern CCriticalSection cs_main; +extern RecursiveMutex cs_main; extern CTxMemPool g_mempool; extern uint64_t nLastBlockTx; extern uint64_t nLastBlockSize; diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -94,7 +94,7 @@ * A lock that must be held when modifying this ChainState - held in * ActivateBestChain() */ - CCriticalSection m_cs_chainstate; + RecursiveMutex m_cs_chainstate; /** * Every received block is assigned a unique and increasing identifier, so @@ -302,7 +302,7 @@ std::multimap &mapBlocksUnlinked = g_chainstate.mapBlocksUnlinked; -CCriticalSection cs_LastBlockFile; +RecursiveMutex cs_LastBlockFile; std::vector vinfoBlockFile; int nLastBlockFile = 0; /** diff --git a/src/validationinterface.h b/src/validationinterface.h --- a/src/validationinterface.h +++ b/src/validationinterface.h @@ -12,7 +12,7 @@ #include #include -extern CCriticalSection cs_main; +extern RecursiveMutex cs_main; class CBlock; class CBlockIndex; struct CBlockLocator; diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp --- a/src/wallet/db.cpp +++ b/src/wallet/db.cpp @@ -57,7 +57,7 @@ } } -CCriticalSection cs_db; +RecursiveMutex cs_db; //! Map from directory name to db environment. std::map> @@ -679,7 +679,7 @@ void BerkeleyEnvironment::ReloadDbEnv() { // Make sure that no Db's are in use AssertLockNotHeld(cs_db); - std::unique_lock lock(cs_db); + std::unique_lock lock(cs_db); m_db_in_use.wait(lock, [this]() { for (auto &count : mapFileUseCount) { if (count.second > 0) { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -810,7 +810,7 @@ * Main wallet lock. * This lock protects all the fields added by CWallet. */ - mutable CCriticalSection cs_wallet; + mutable RecursiveMutex cs_wallet; /** * Get database handle used by this wallet. Ideally this function would not diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -41,7 +41,7 @@ #include #include -static CCriticalSection cs_wallets; +static RecursiveMutex cs_wallets; static std::vector> vpwallets GUARDED_BY(cs_wallets); bool AddWallet(const std::shared_ptr &wallet) { diff --git a/src/warnings.cpp b/src/warnings.cpp --- a/src/warnings.cpp +++ b/src/warnings.cpp @@ -9,7 +9,7 @@ #include #include -CCriticalSection cs_warnings; +RecursiveMutex cs_warnings; std::string strMiscWarning; bool fLargeWorkForkFound = false; bool fLargeWorkInvalidChainFound = false;