8 #ifndef NT_ATOMIC_STATIC_H_
9 #define NT_ATOMIC_STATIC_H_
11 #if !defined(_MSC_VER) || (_MSC_VER >= 1900)
18 #define ATOMIC_STATIC(cls, inst) static cls inst
19 #define ATOMIC_STATIC_DECL(cls)
20 #define ATOMIC_STATIC_INIT(cls)
27 #define ATOMIC_STATIC(cls, inst) \
28 cls* inst##tmp = m_instance.load(std::memory_order_acquire); \
29 if (inst##tmp == nullptr) { \
30 std::lock_guard<std::mutex> lock(m_instance_mutex); \
31 inst##tmp = m_instance.load(std::memory_order_relaxed); \
32 if (inst##tmp == nullptr) { \
33 inst##tmp = new cls; \
34 m_instance.store(inst##tmp, std::memory_order_release); \
37 cls& inst = *inst##tmp
39 #define ATOMIC_STATIC_DECL(cls) \
40 static std::atomic<cls*> m_instance; \
41 static std::mutex m_instance_mutex;
43 #define ATOMIC_STATIC_INIT(cls) \
44 std::atomic<cls*> cls::m_instance; \
45 std::mutex cls::m_instance_mutex;
49 #endif // NT_ATOMIC_STATIC_H_