12#ifndef ROC_CORE_SINGLETON_H_
13#define ROC_CORE_SINGLETON_H_
18#include "roc_core/atomic_ops.h"
26template <
class T>
class Singleton :
public NonCopyable<> {
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_;
52template <
class T> pthread_once_t Singleton<T>::once_ = PTHREAD_ONCE_INIT;
53template <
class T> AlignedStorage<
sizeof(T)> Singleton<T>::storage_;
54template <
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).
static T & instance()
Get singleton instance.
General-purpose building blocks and platform abstraction layer.
#define roc_panic_if_not(x)
Panic if condition is false.