31 #include <MUtils/Exception.h> 35 #include <QAtomicPointer> 50 template<
typename T>
class Lazy 53 Lazy(std::function<T*(
void)> &&initializer) : m_initializer(initializer) { }
72 if(T *
const value = m_value)
79 __forceinline T* getValue()
82 while (!(value = m_value))
84 if (m_state.testAndSetOrdered(0, 1))
86 if (value = m_initializer())
88 m_value.fetchAndStoreOrdered(value);
89 m_state.fetchAndStoreOrdered(2);
92 m_state.fetchAndStoreOrdered(0);
93 MUTILS_THROW(
"Initializer returned NULL pointer!");
95 QThread::yieldCurrentThread();
101 QAtomicPointer<T> m_value;
103 const std::function<T*(void)> m_initializer;
This file contains miscellaneous functions that are generally useful for Qt-based applications...
Lazy initialization template class.
Definition: Lazy.h:50
Global MUtils namespace.
Definition: CPUFeatures.h:37