Changeset View
Changeset View
Standalone View
Standalone View
src/rcu.h
Show All 15 Lines | |||||
class RCUInfos; | class RCUInfos; | ||||
class RCUReadLock; | class RCUReadLock; | ||||
class RCUInfos { | class RCUInfos { | ||||
std::atomic<uint64_t> state; | std::atomic<uint64_t> state; | ||||
std::atomic<RCUInfos *> next; | std::atomic<RCUInfos *> next; | ||||
bool isCleaningUp = false; | |||||
class RCUCleanupGuard; | |||||
std::map<uint64_t, std::function<void()>> cleanups; | std::map<uint64_t, std::function<void()>> cleanups; | ||||
// The largest revision possible means unlocked. | // The largest revision possible means unlocked. | ||||
static const uint64_t UNLOCKED = -uint64_t(1); | static const uint64_t UNLOCKED = -uint64_t(1); | ||||
RCUInfos(); | RCUInfos(); | ||||
~RCUInfos(); | ~RCUInfos(); | ||||
Show All 26 Lines | |||||
class RCULock { | 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(); | |||||
infos->runCleanups(); | |||||
} | |||||
RCULock(const RCULock &) = delete; | RCULock(const RCULock &) = delete; | ||||
RCULock &operator=(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); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 160 Lines • Show Last 20 Lines |