12#ifndef ROC_CORE_SINGLETON_H_
13#define ROC_CORE_SINGLETON_H_
18#include "roc_core/atomic_ops.h"
42 static void create_() {
43 T*
inst =
new (storage_.memory()) T;
47 static pthread_once_t once_;
48 static AlignedStorage<
sizeof(T)> storage_;
53template <
class T> pthread_once_t Singleton<T>::once_ = PTHREAD_ONCE_INIT;
54template <
class T> AlignedStorage<
sizeof(T)> Singleton<T>::storage_;
55template <
class T> T* Singleton<T>::instance_;
static T load_relaxed(const T &var)
Atomic load (no barrier).
static void store_release(T1 &var, T2 val)
Atomic store (release barrier).
Base class for non-copyable objects.
Shared ownership intrusive pointer.
static T & instance()
Get singleton instance.
#define roc_panic_if_not(x)
Panic if condition is false.