Revision: 7348
http://mahogany.svn.sourceforge.net/mahogany/?rev=7348&view=rev
Author: vadz
Date: 2007-08-27 14:44:22 -0700 (Mon, 27 Aug 2007)
Log Message:
-----------
make Enter/LeaveCritical() reentrant; don't ignore button evens from the modal
dialogs which can be shown even while the app is in a critical section
Modified Paths:
--------------
trunk/M/include/MApplication.h
trunk/M/src/gui/wxMApp.cpp
Modified: trunk/M/include/MApplication.h
===================================================================
--- trunk/M/include/MApplication.h 2007-08-27 20:50:07 UTC (rev 7347)
+++ trunk/M/include/MApplication.h 2007-08-27 21:44:22 UTC (rev 7348)
@@ -226,8 +226,8 @@
Start critical section inside which background processing should be
disallowed.
- EnterCritical() is not reentrant, it is an error to call it if
- AllowBgProcessing() already returns false.
+ EnterCritical() is reentrant and calls to it may be nested but
+ LeaveCritical() must be called exactly the same number of times.
Consider using MAppCriticalSection instead of manually calling
EnterCritical() and LeaveCritical().
Modified: trunk/M/src/gui/wxMApp.cpp
===================================================================
--- trunk/M/src/gui/wxMApp.cpp 2007-08-27 20:50:07 UTC (rev 7347)
+++ trunk/M/src/gui/wxMApp.cpp 2007-08-27 21:44:22 UTC (rev 7348)
@@ -336,8 +336,8 @@
// a list of modules loaded at startup:
static ModulesList gs_GlobalModulesList;
-// the mutex we lock to block any background processing temporarily
-static MMutex gs_mutexBlockBg;
+// if this is > 0 then background processing is temporarily blocked
+static int gs_mutexBlockBg = 0;
// ============================================================================
// implementation
@@ -618,7 +618,8 @@
if ( AllowBgProcessing() )
return -1;
- if ( event.IsCommandEvent() || event.GetEventType() == wxEVT_CHAR )
+ if ( event.GetEventType() == wxEVT_COMMAND_MENU_SELECTED ||
+ event.GetEventType() == wxEVT_CHAR )
{
// these events are dangerous to handle now as they can result in another
// call to c-client being made so just ignore them
@@ -649,19 +650,23 @@
bool
wxMApp::AllowBgProcessing() const
{
- return !gs_mutexBlockBg.IsLocked();
+ return gs_mutexBlockBg == 0;
}
void
wxMApp::EnterCritical()
{
- gs_mutexBlockBg.Lock();
+ ASSERT( gs_mutexBlockBg >= 0 );
+
+ gs_mutexBlockBg++;
}
void
wxMApp::LeaveCritical()
{
- gs_mutexBlockBg.Unlock();
+ ASSERT( gs_mutexBlockBg > 0 );
+
+ gs_mutexBlockBg--;
}
#ifdef __WXDEBUG__
@@ -670,19 +675,10 @@
wxMApp::OnAssert(const wxChar *file, int line,
const wxChar *cond, const wxChar *msg)
{
- // don't provoke an assert from inside the assert (which would happen if we
- // tried to lock an already locked mutex below)
- if ( gs_mutexBlockBg.IsLocked() )
- {
- wxTrap();
-
- return;
- }
-
// don't allow any calls to c-client while we're in the assert dialog
// because we might be called from a c-client callback and another call to
// it will result in a fatal error
- MLocker lock(gs_mutexBlockBg);
+ MAppCriticalSection cs;
wxApp::OnAssert(file, line, cond, msg);
}
@@ -692,17 +688,10 @@
bool
wxMApp::Yield(bool onlyIfNeeded)
{
- if ( gs_mutexBlockBg.IsLocked() )
- {
- // background processing already disabled, hopefully it's ok to yield
- // now...
- return wxApp::Yield(onlyIfNeeded);
- }
-
// don't allow any calls to c-client from inside wxYield() neither as it is
// implicitly (!) called by wxProgressDialog which is shown from inside some
// c-client handlers and so calling c-client now would result in a crash
- MLocker lock(gs_mutexBlockBg);
+ MAppCriticalSection cs;
return wxApp::Yield(onlyIfNeeded);
}
@@ -728,10 +717,11 @@
if ( s_crashed )
return;
+
s_crashed = true;
// no background processing in this function
- MLocker lock(gs_mutexBlockBg);
+ MAppCriticalSection cs;
MAppBase::OnAbnormalTermination();
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Mahogany-cvsupdates mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates