15 #ifndef SHAKA_EMBEDDED_UTIL_PSEUDO_SINGLETON_H_ 16 #define SHAKA_EMBEDDED_UTIL_PSEUDO_SINGLETON_H_ 18 #include <glog/logging.h> 21 #include <type_traits> 45 : value_(instance_.exchange(nullptr,
std::memory_order_acq_rel)) {}
48 T* expected =
nullptr;
49 CHECK(instance_.compare_exchange_strong(expected, value_,
50 std::memory_order_acq_rel));
62 T* expected =
nullptr;
63 CHECK(instance_.compare_exchange_strong(expected, static_cast<T*>(
this),
64 std::memory_order_acq_rel));
68 T* expected =
static_cast<T*
>(
this);
69 CHECK(instance_.compare_exchange_strong(expected,
nullptr,
70 std::memory_order_acq_rel));
74 T* ret = instance_.load(std::memory_order_acquire);
80 return instance_.load(std::memory_order_acquire);
84 static std::atomic<T*> instance_;
92 #endif // SHAKA_EMBEDDED_UTIL_PSEUDO_SINGLETON_H_
static T * InstanceOrNull()
#define NO_SANITIZE(name)