Changeset View
Changeset View
Standalone View
Standalone View
src/rcu.h
// Copyright (c) 2018-2019 The Bitcoin developers | // Copyright (c) 2018-2019 The Bitcoin 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_RCU_H | #ifndef BITCOIN_RCU_H | ||||
#define BITCOIN_RCU_H | #define BITCOIN_RCU_H | ||||
#include <boost/noncopyable.hpp> | |||||
#include <atomic> | #include <atomic> | ||||
#include <cassert> | #include <cassert> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <functional> | #include <functional> | ||||
#include <map> | #include <map> | ||||
#include <ostream> | #include <ostream> | ||||
#include <type_traits> | #include <type_traits> | ||||
#include <utility> | #include <utility> | ||||
Show All 34 Lines | class RCUInfos { | ||||
friend class RCULock; | friend class RCULock; | ||||
friend struct RCUTest; | friend struct RCUTest; | ||||
static std::atomic<uint64_t> revision; | static std::atomic<uint64_t> revision; | ||||
static thread_local RCUInfos infos; | static thread_local RCUInfos infos; | ||||
}; | }; | ||||
class RCULock : public boost::noncopyable { | class RCULock { | ||||
RCUInfos *infos; | RCUInfos *infos; | ||||
explicit RCULock(RCUInfos *infosIn) : infos(infosIn) { infos->readLock(); } | explicit RCULock(RCUInfos *infosIn) : infos(infosIn) { infos->readLock(); } | ||||
friend class RCUInfos; | friend class RCUInfos; | ||||
public: | public: | ||||
RCULock() : RCULock(&RCUInfos::infos) {} | RCULock() : RCULock(&RCUInfos::infos) {} | ||||
~RCULock() { infos->readFree(); } | ~RCULock() { infos->readFree(); } | ||||
RCULock(const RCULock &) = delete; | |||||
RCULock &operator=(const RCULock &) = delete; | |||||
static bool isLocked() { return RCUInfos::infos.isLocked(); } | static bool isLocked() { return RCUInfos::infos.isLocked(); } | ||||
static void registerCleanup(const std::function<void()> &f) { | static void registerCleanup(const std::function<void()> &f) { | ||||
RCUInfos::infos.registerCleanup(f); | RCUInfos::infos.registerCleanup(f); | ||||
} | } | ||||
static void synchronize() { RCUInfos::infos.synchronize(); } | static void synchronize() { RCUInfos::infos.synchronize(); } | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 156 Lines • Show Last 20 Lines |