From ba23715453320aec9962c534d61e292aa5b56ab8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 24 Oct 2007 18:06:10 +0000 Subject: [PATCH] add a critical section protecting ms_prev variables (replaces patch 1819224) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@49405 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/log.cpp | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) 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); } } }