// RCS-ID: $Id$
// Copyright: (c) Wolfram Gloger (1996, 1997); Guilhem Lavaux (1998),
// Vadim Zeitlin (1999) , Stefan Csomor (2000)
-// Licence: wxWidgets licence
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "thread.h"
#endif
#else
#include <DriverServices.h>
#include <Multiprocessing.h>
-#include <math.h>
+#include "wx/math.h"
#endif
#include "wx/mac/uma.h"
#endif
to use two indices one for each 32 bit part as the MP implementation is limited
to longs.
- I have two implementations for mutexes :
+ I have three implementations for mutexes :
version A based on a binary semaphore, problem - not reentrant, version B based
on a critical region, allows for reentrancy, performance implications not
- yet tested
+ yet tested, and third a plain pthreads implementation
The same for condition internal, one implementation by Aj Lavin and the other one
copied from the thrimpl.cpp which I assume has been more broadly tested, I've just
replaced the interlock increment with the appropriate PPC calls
*/
+// ----------------------------------------------------------------------------
+// wxCriticalSection
+// ----------------------------------------------------------------------------
+
+wxCriticalSection::wxCriticalSection()
+{
+ MPCreateCriticalRegion( (MPCriticalRegionID*) &m_critRegion ) ;
+}
+
+wxCriticalSection::~wxCriticalSection()
+{
+ MPDeleteCriticalRegion( (MPCriticalRegionID) m_critRegion ) ;
+}
+
+void wxCriticalSection::Enter()
+{
+ MPEnterCriticalRegion( (MPCriticalRegionID) m_critRegion , kDurationForever ) ;
+}
+
+void wxCriticalSection::Leave()
+{
+ MPExitCriticalRegion((MPCriticalRegionID) m_critRegion ) ;
+}
+
// ----------------------------------------------------------------------------
// wxMutex implementation
// ----------------------------------------------------------------------------
kDurationForever);
if ( err)
{
- wxLogSysError( _( "Cannot wait on thread to exit."));
+ wxLogSysError( _( "Cannot wait for thread termination."));
rc = (void*) -1;
}
verify_noerr( MPAllocateTaskStorageIndex( &gs_tlsForWXThread ) ) ;
// main thread's This() is NULL
- verify_noerr( MPSetTaskStorageValue( gs_tlsForWXThread , NULL ) ) ;
+ verify_noerr( MPSetTaskStorageValue( gs_tlsForWXThread , 0 ) ) ;
gs_idMainThread = wxThread::GetCurrentId() ;
{
if ( gs_critsectGui )
{
+ if ( !wxGuiOwnedByMainThread() )
+ {
+ gs_critsectGui->Enter();
+ gs_bGuiOwnedByMainThread = true;
+ }
gs_critsectGui->Leave();
delete gs_critsectGui;
gs_critsectGui = NULL;
wxASSERT_MSG( wxThread::IsMain(),
wxT("only main thread may call wxMutexGuiLeaveOrEnter()!") );
+ if( !gs_critsectWaitingForGui )
+ return;
+
wxCriticalSectionLocker enter(*gs_critsectWaitingForGui);
if ( gs_nWaitingForGui == 0 )