#pragma once #include #include #include namespace NPrivate { template struct TFastThreadSingletonHelper { static inline T* GetSlow() { return SingletonWithPriority, Priority>()->GetPtr(); } static inline T* Get() { #if defined(Y_HAVE_FAST_POD_TLS) Y_POD_STATIC_THREAD(T*) fast(nullptr); if (Y_UNLIKELY(!fast)) { fast = GetSlow(); } return fast; #else return GetSlow(); #endif } }; } template static inline T* FastTlsSingletonWithPriority() { return ::NPrivate::TFastThreadSingletonHelper::Get(); } // NB: the singleton is the same for all modules that use // FastTlsSingleton with the same type parameter. If unique singleton // required, use unique types. template static inline T* FastTlsSingleton() { return FastTlsSingletonWithPriority::Priority>(); }