use static functions instead of static variables for critical sections to avoid crashing if a log function using a CS is called during static objects initialization
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@52594 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -14,10 +14,6 @@
|
|||||||
|
|
||||||
#include "wx/defs.h"
|
#include "wx/defs.h"
|
||||||
|
|
||||||
#if wxUSE_THREADS
|
|
||||||
class WXDLLIMPEXP_FWD_BASE wxCriticalSection;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// common constants for use in wxUSE_LOG/!wxUSE_LOG
|
// common constants for use in wxUSE_LOG/!wxUSE_LOG
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -324,9 +320,6 @@ private:
|
|||||||
// with the number of times it was repeated
|
// with the number of times it was repeated
|
||||||
static bool ms_bRepetCounting;
|
static bool ms_bRepetCounting;
|
||||||
|
|
||||||
#if wxUSE_THREADS
|
|
||||||
static wxCriticalSection ms_prevCS; // protects the ms_prev values below
|
|
||||||
#endif
|
|
||||||
static wxString ms_prevString; // previous message that was logged
|
static wxString ms_prevString; // previous message that was logged
|
||||||
static unsigned ms_prevCounter; // how many times it was repeated
|
static unsigned ms_prevCounter; // how many times it was repeated
|
||||||
static time_t ms_prevTimeStamp;// timestamp of the previous message
|
static time_t ms_prevTimeStamp;// timestamp of the previous message
|
||||||
@@ -345,9 +338,6 @@ private:
|
|||||||
// disabled
|
// disabled
|
||||||
static wxString ms_timestamp;
|
static wxString ms_timestamp;
|
||||||
|
|
||||||
#if wxUSE_THREADS
|
|
||||||
static wxCriticalSection ms_traceCS; // protects ms_aTraceMasks
|
|
||||||
#endif
|
|
||||||
static wxTraceMask ms_ulTraceMask; // controls wxLogTrace behaviour
|
static wxTraceMask ms_ulTraceMask; // controls wxLogTrace behaviour
|
||||||
static wxArrayString ms_aTraceMasks; // more powerful filter for wxLogTrace
|
static wxArrayString ms_aTraceMasks; // more powerful filter for wxLogTrace
|
||||||
};
|
};
|
||||||
|
@@ -63,6 +63,30 @@
|
|||||||
#include "wx/msw/private.h" // includes windows.h
|
#include "wx/msw/private.h" // includes windows.h
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if wxUSE_THREADS
|
||||||
|
|
||||||
|
// define static functions providing access to the critical sections we use
|
||||||
|
// instead of just using static critical section variables as log functions may
|
||||||
|
// be used during static initialization and while this is certainly not
|
||||||
|
// advisable it's still better to not crash (as we'd do if we used a yet
|
||||||
|
// uninitialized critical section) if it happens
|
||||||
|
|
||||||
|
static inline wxCriticalSection& GetTraceMaskCS()
|
||||||
|
{
|
||||||
|
static wxCriticalSection s_csTrace;
|
||||||
|
|
||||||
|
return s_csTrace;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline wxCriticalSection& GetPreviousLogCS()
|
||||||
|
{
|
||||||
|
static wxCriticalSection s_csPrev;
|
||||||
|
|
||||||
|
return s_csPrev;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // wxUSE_THREADS
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// non member functions
|
// non member functions
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -461,7 +485,7 @@ void WXDLLIMPEXP_BASE wxVLogSysError(unsigned long err, const wxString& format,
|
|||||||
|
|
||||||
unsigned wxLog::LogLastRepeatIfNeeded()
|
unsigned wxLog::LogLastRepeatIfNeeded()
|
||||||
{
|
{
|
||||||
wxCRIT_SECT_LOCKER(lock, ms_prevCS);
|
wxCRIT_SECT_LOCKER(lock, GetPreviousLogCS());
|
||||||
|
|
||||||
return LogLastRepeatIfNeededUnlocked();
|
return LogLastRepeatIfNeededUnlocked();
|
||||||
}
|
}
|
||||||
@@ -515,7 +539,7 @@ void wxLog::OnLog(wxLogLevel level, const wxString& szString, time_t t)
|
|||||||
{
|
{
|
||||||
if ( GetRepetitionCounting() )
|
if ( GetRepetitionCounting() )
|
||||||
{
|
{
|
||||||
wxCRIT_SECT_LOCKER(lock, ms_prevCS);
|
wxCRIT_SECT_LOCKER(lock, GetPreviousLogCS());
|
||||||
|
|
||||||
if ( szString == ms_prevString )
|
if ( szString == ms_prevString )
|
||||||
{
|
{
|
||||||
@@ -620,14 +644,14 @@ void wxLog::DoCreateOnDemand()
|
|||||||
|
|
||||||
void wxLog::AddTraceMask(const wxString& str)
|
void wxLog::AddTraceMask(const wxString& str)
|
||||||
{
|
{
|
||||||
wxCRIT_SECT_LOCKER(lock, ms_traceCS);
|
wxCRIT_SECT_LOCKER(lock, GetTraceMaskCS());
|
||||||
|
|
||||||
ms_aTraceMasks.push_back(str);
|
ms_aTraceMasks.push_back(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxLog::RemoveTraceMask(const wxString& str)
|
void wxLog::RemoveTraceMask(const wxString& str)
|
||||||
{
|
{
|
||||||
wxCRIT_SECT_LOCKER(lock, ms_traceCS);
|
wxCRIT_SECT_LOCKER(lock, GetTraceMaskCS());
|
||||||
|
|
||||||
int index = ms_aTraceMasks.Index(str);
|
int index = ms_aTraceMasks.Index(str);
|
||||||
if ( index != wxNOT_FOUND )
|
if ( index != wxNOT_FOUND )
|
||||||
@@ -636,7 +660,7 @@ void wxLog::RemoveTraceMask(const wxString& str)
|
|||||||
|
|
||||||
void wxLog::ClearTraceMasks()
|
void wxLog::ClearTraceMasks()
|
||||||
{
|
{
|
||||||
wxCRIT_SECT_LOCKER(lock, ms_traceCS);
|
wxCRIT_SECT_LOCKER(lock, GetTraceMaskCS());
|
||||||
|
|
||||||
ms_aTraceMasks.Clear();
|
ms_aTraceMasks.Clear();
|
||||||
}
|
}
|
||||||
@@ -733,7 +757,7 @@ void wxLog::Flush()
|
|||||||
|
|
||||||
/*static*/ bool wxLog::IsAllowedTraceMask(const wxString& mask)
|
/*static*/ bool wxLog::IsAllowedTraceMask(const wxString& mask)
|
||||||
{
|
{
|
||||||
wxCRIT_SECT_LOCKER(lock, ms_traceCS);
|
wxCRIT_SECT_LOCKER(lock, GetTraceMaskCS());
|
||||||
|
|
||||||
for ( wxArrayString::iterator it = ms_aTraceMasks.begin(),
|
for ( wxArrayString::iterator it = ms_aTraceMasks.begin(),
|
||||||
en = ms_aTraceMasks.end();
|
en = ms_aTraceMasks.end();
|
||||||
@@ -939,10 +963,6 @@ wxLogInterposerTemp::wxLogInterposerTemp()
|
|||||||
// static variables
|
// static variables
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
#if wxUSE_THREADS
|
|
||||||
wxCriticalSection wxLog::ms_prevCS,
|
|
||||||
wxLog::ms_traceCS;
|
|
||||||
#endif // wxUSE_THREADS
|
|
||||||
bool wxLog::ms_bRepetCounting = false;
|
bool wxLog::ms_bRepetCounting = false;
|
||||||
wxString wxLog::ms_prevString;
|
wxString wxLog::ms_prevString;
|
||||||
unsigned int wxLog::ms_prevCounter = 0;
|
unsigned int wxLog::ms_prevCounter = 0;
|
||||||
|
Reference in New Issue
Block a user