mirror of
https://github.com/apple/foundationdb.git
synced 2025-05-28 02:48:09 +08:00
use std::atomic for threadsaferefcounted
This commit is contained in:
parent
7ab6fedb5b
commit
e616545949
@ -35,10 +35,10 @@ class ThreadSafeReferenceCounted {
|
|||||||
public:
|
public:
|
||||||
ThreadSafeReferenceCounted() : referenceCount(1) {}
|
ThreadSafeReferenceCounted() : referenceCount(1) {}
|
||||||
// NO virtual destructor! Subclass should have a virtual destructor if it is not sealed.
|
// NO virtual destructor! Subclass should have a virtual destructor if it is not sealed.
|
||||||
void addref() const { interlockedIncrement(&referenceCount); }
|
void addref() const { ++referenceCount; }
|
||||||
// If return value is true, caller is responsible for destruction of object
|
// If return value is true, caller is responsible for destruction of object
|
||||||
bool delref_no_destroy() const {
|
bool delref_no_destroy() const {
|
||||||
if (interlockedDecrement(&referenceCount) != 0) {
|
if (--referenceCount != 0) {
|
||||||
#ifdef VALGRIND
|
#ifdef VALGRIND
|
||||||
ANNOTATE_HAPPENS_BEFORE(&referenceCount);
|
ANNOTATE_HAPPENS_BEFORE(&referenceCount);
|
||||||
#endif
|
#endif
|
||||||
@ -60,7 +60,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
ThreadSafeReferenceCounted(const ThreadSafeReferenceCounted&) /* = delete*/;
|
ThreadSafeReferenceCounted(const ThreadSafeReferenceCounted&) /* = delete*/;
|
||||||
void operator=(const ThreadSafeReferenceCounted&) /* = delete*/;
|
void operator=(const ThreadSafeReferenceCounted&) /* = delete*/;
|
||||||
mutable volatile int32_t referenceCount;
|
mutable std::atomic<int32_t> referenceCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Subclass>
|
template <class Subclass>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user