diff options
author | Billy Donahue <billy.donahue@mongodb.com> | 2020-09-29 21:59:56 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-10-02 01:52:40 +0000 |
commit | 9c5456e9d9efc288b8ac46820adc59ba58d1ea63 (patch) | |
tree | 8451126856966d7320750b800f937dca0f4fb157 /src | |
parent | 0e13f542973a557db3b2d1f6872a30e1d7dc23fd (diff) | |
download | mongo-9c5456e9d9efc288b8ac46820adc59ba58d1ea63.tar.gz |
SERVER-51165 SyncUnique Use atomic swap in setter, and AtomicWord<T*>
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/service_context.h | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/mongo/db/service_context.h b/src/mongo/db/service_context.h index 7299d459190..f59d31ddd49 100644 --- a/src/mongo/db/service_context.h +++ b/src/mongo/db/service_context.h @@ -626,13 +626,11 @@ private: } void set(std::unique_ptr<T> p) { - T* old = get(); - _ptr.store(reinterpret_cast<uintptr_t>(p.release())); - delete old; + delete _ptr.swap(p.release()); } T* get() const { - return reinterpret_cast<T*>(_ptr.load()); + return _ptr.load(); } T* operator->() const { @@ -648,7 +646,7 @@ private: } private: - AtomicWord<uintptr_t> _ptr{0}; + AtomicWord<T*> _ptr{nullptr}; }; class ClientObserverHolder { |