diff --git a/src/common/log.cpp b/src/common/log.cpp index 1e4db45ec6..de1740f468 100644 --- a/src/common/log.cpp +++ b/src/common/log.cpp @@ -280,9 +280,14 @@ void WXDLLEXPORT wxLogSysError(long lErrCode, const wxChar *szFormat, ...) // wxLog class implementation // ---------------------------------------------------------------------------- +// define a critical section gs_prevCS protecting access to wxLog::ms_prevXXX +wxCRIT_SECT_DECLARE(gs_prevCS); + /* static */ unsigned wxLog::DoLogNumberOfRepeats() { + wxCRIT_SECT_LOCKER(lock, gs_prevCS); + long retval = ms_prevCounter; wxLog *pLogger = GetActiveTarget(); if ( pLogger && ms_prevCounter > 0 ) @@ -305,12 +310,7 @@ unsigned wxLog::DoLogNumberOfRepeats() wxLog::~wxLog() { - if ( ms_prevCounter > 0 ) - { - // looks like the repeat count has not been logged yet, - // so let's do it now - wxLog::DoLogNumberOfRepeats(); - } + wxLog::DoLogNumberOfRepeats(); } /* static */ @@ -321,21 +321,28 @@ void wxLog::OnLog(wxLogLevel level, const wxChar *szString, time_t t) wxLog *pLogger = GetActiveTarget(); if ( pLogger ) { - if ( GetRepetitionCounting() && ms_prevString == szString ) + if ( GetRepetitionCounting() ) { - ms_prevCounter++; - } - else - { - if ( GetRepetitionCounting() ) + wxCRIT_SECT_LOCKER(lock, gs_prevCS); + + if ( szString == ms_prevString ) { - DoLogNumberOfRepeats(); + ms_prevCounter++; + + // nothing else to do, in particular, don't log the + // repeated message + return; } + + DoLogNumberOfRepeats(); + + // reset repetition counter for a new message ms_prevString = szString; ms_prevLevel = level; ms_prevTimeStamp = t; - pLogger->DoLog(level, szString, t); } + + pLogger->DoLog(level, szString, t); } } }