12 #ifndef ROC_CORE_SINGLETON_H_
13 #define ROC_CORE_SINGLETON_H_
18 #include "roc_core/atomic_ops.h"
33 pthread_once(&once_, create_);
42 static void create_() {
43 T* inst =
new (storage_.
memory()) T;
47 static pthread_once_t once_;
48 static AlignedStorage<
sizeof(T)> storage_;
52 template <
class T> pthread_once_t Singleton<T>::once_ = PTHREAD_ONCE_INIT;
53 template <
class T> AlignedStorage<
sizeof(T)> Singleton<T>::storage_;
54 template <
class T> T* Singleton<T>::instance_;
const void * memory() const
Get storage memory.
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.
static T & instance()
Get singleton instance.
#define roc_panic_if_not(x)
Panic if condition is false.