Make critical sections initialization really thread-safe.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61419 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -77,35 +77,35 @@ namespace
|
|||||||
typedef wxVector<wxLogRecord> wxLogRecords;
|
typedef wxVector<wxLogRecord> wxLogRecords;
|
||||||
wxLogRecords gs_bufferedLogRecords;
|
wxLogRecords gs_bufferedLogRecords;
|
||||||
|
|
||||||
|
// this macro allows to define an object which will be initialized before any
|
||||||
// define static functions providing access to the critical sections we use
|
// other function in this file is called: this is necessary to allow log
|
||||||
// instead of just using static critical section variables as log functions may
|
// functions to be used during static initialization (this is not advisable
|
||||||
// be used during static initialization and while this is certainly not
|
// anyhow but we should at least try to not crash) and to also ensure that they
|
||||||
// advisable it's still better to not crash (as we'd do if we used a yet
|
// are initialized by the time static initialization is done, i.e. before any
|
||||||
// uninitialized critical section) if it happens
|
// threads are created hopefully
|
||||||
|
//
|
||||||
|
// the net effect of all this is that you can use Get##name##CS() function to
|
||||||
|
// access the critical function without worrying about it being not initialized
|
||||||
|
//
|
||||||
|
// see also WX_DEFINE_GLOBAL_CONV2() in src/common/strconv.cpp
|
||||||
|
#define WX_DEFINE_LOG_CS(name) \
|
||||||
|
inline wxCriticalSection& Get##name##CS() \
|
||||||
|
{ \
|
||||||
|
static wxCriticalSection s_cs##name; \
|
||||||
|
return s_cs##name; \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
wxCriticalSection *gs_##name##CSPtr = &Get##name##CS()
|
||||||
|
|
||||||
// this critical section is used for buffering the messages from threads other
|
// this critical section is used for buffering the messages from threads other
|
||||||
// than main, i.e. it protects all accesses to gs_bufferedLogRecords above
|
// than main, i.e. it protects all accesses to gs_bufferedLogRecords above
|
||||||
inline wxCriticalSection& GetBackgroundLogCS()
|
WX_DEFINE_LOG_CS(BackgroundLog);
|
||||||
{
|
|
||||||
static wxCriticalSection s_csBackground;
|
|
||||||
|
|
||||||
return s_csBackground;
|
// this one is used for protecting ms_aTraceMasks from concurrent access
|
||||||
}
|
WX_DEFINE_LOG_CS(TraceMask);
|
||||||
|
|
||||||
inline wxCriticalSection& GetTraceMaskCS()
|
// and this one is used for gs_componentLevels
|
||||||
{
|
WX_DEFINE_LOG_CS(Levels);
|
||||||
static wxCriticalSection s_csTrace;
|
|
||||||
|
|
||||||
return s_csTrace;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline wxCriticalSection& GetLevelsCS()
|
|
||||||
{
|
|
||||||
static wxCriticalSection s_csLevels;
|
|
||||||
|
|
||||||
return s_csLevels;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user