47 #define NCBI_USE_ERRCODE_X Corelib_Static
60 m_LifeSpan(
int(span) + adjust)
66 if (adjust >= 5000 || adjust <= -5000) {
68 <<
"CSafeStaticLifeSpan level adjustment out of range: "
71 _ASSERT(adjust > -5000 && adjust < 5000);
95 return int(s_CreationOrder.
Add(1));
119 #if defined(NCBI_WIN32_THREADS)
146 CMutexGuard guard(CSafeStaticPtr_Base::sm_ClassMutex);
163 CMutexGuard guard(CSafeStaticPtr_Base::sm_ClassMutex);
179 string msg =
"On static data destruction, child thread(s) still running: " + to_string(tc);
194 for (
int pass = 0; pass < 3; ++pass ) {
197 swap(cur_Stack, *stack);
202 guard.
Guard(CSafeStaticPtr_Base::sm_ClassMutex);
224 return &sl_CleanupGuard;
void Guard(resource_type &resource)
Manually force the guard to protect some other resource.
void Release()
Manually force the resource to be released.
static void Destroy(CSafeStaticLifeSpan::ELifeLevel level)
Explicitly destroy all on-demand variables up to a specified level.
static CSafeStaticGuard * x_Get(void)
static TStack *& x_GetStack(CSafeStaticLifeSpan::ELifeLevel level)
CSafeStaticGuard(void)
Check if already initialized.
static bool sm_ChildThreadsCheck
multiset< CSafeStaticPtr_Base *, CSafeStatic_Less > TStack
static void x_Cleanup(CMutexGuard &guard, TStack *&stack)
~CSafeStaticGuard(void)
Check reference count, and if it is zero, then destroy all registered variables.
static void DisableChildThreadsCheck()
Disable checking on child thread(s) running during destruction.
static CSafeStaticLifeSpan & GetDefault(void)
Get default life span (set to eLifeSpan_Min).
ELifeSpan
Predefined life spans for the safe static objects.
@ eLifeSpan_Min
std static, not adjustable
CSafeStaticLifeSpan(ELifeSpan span, int adjust=0)
Constructs a life span object from basic level and adjustment.
ELifeLevel
Predefined life levels for the safe static objects.
@ eLifeLevel_AppMain
Destroyed in CNcbiApplication::AppMain, if possible.
static int x_GetCreationOrder(void)
bool x_IsStdStatic(void) const
~CSafeStaticPtr_Base(void)
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
void swap(NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair1, NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair2)
TValue Add(int delta) THROWS_NONE
Atomically add value (=delta), and return new counter value.
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
void Error(CExceptionArgs_Base &args)
void Warning(CExceptionArgs_Base &args)
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
static unsigned int GetThreadsCount()
Get total amount of threads This amount does not contain main thread.
unsigned int
A callback function used to compare two keys in a database.
Definition of all error codes used in corelib (xncbi.lib).
static CSafeStaticGuard * sh_CleanupGuard
static CSafeStaticGuard sg_CleanupGuard
DEFINE_CLASS_STATIC_MUTEX(CSafeStaticPtr_Base::sm_ClassMutex)
Static variables safety - create on demand, destroy on application termination.
Multi-threading – mutexes; rw-locks; semaphore.
Multi-threading – classes, functions, and features.