when the system is not yet start fully (macos not inited) mutexes and critical sections take shortcuts, these are ok since at this time there is always only on thread

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13385 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2002-01-05 16:37:49 +00:00
parent 0e5a4d2032
commit 9c152f8094
2 changed files with 118 additions and 92 deletions

View File

@@ -35,7 +35,7 @@
#include "wx/thread.h" #include "wx/thread.h"
#ifdef __WXMAC__ #ifdef __WXMAC__
#include "wx/mac/private.h" #include "wx/mac/uma.h"
#endif #endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -69,10 +69,12 @@ class wxMacStCritical
public : public :
wxMacStCritical() wxMacStCritical()
{ {
if ( UMASystemIsInitialized() )
ThreadBeginCritical() ; ThreadBeginCritical() ;
} }
~wxMacStCritical() ~wxMacStCritical()
{ {
if ( UMASystemIsInitialized() )
ThreadEndCritical() ; ThreadEndCritical() ;
} }
}; };
@@ -118,7 +120,8 @@ wxMutex::~wxMutex()
wxMutexError wxMutex::Lock() wxMutexError wxMutex::Lock()
{ {
wxMacStCritical critical ; wxMacStCritical critical ;
if ( UMASystemIsInitialized() )
{
OSErr err ; OSErr err ;
ThreadID current = kNoThreadID; ThreadID current = kNoThreadID;
err = ::MacGetCurrentThread(&current); err = ::MacGetCurrentThread(&current);
@@ -131,6 +134,7 @@ wxMutexError wxMutex::Lock()
err = ::ThreadBeginCritical(); err = ::ThreadBeginCritical();
} }
m_internal->m_owner = current; m_internal->m_owner = current;
}
m_locked++; m_locked++;
return wxMUTEX_NO_ERROR; return wxMUTEX_NO_ERROR;
@@ -139,7 +143,8 @@ wxMutexError wxMutex::Lock()
wxMutexError wxMutex::TryLock() wxMutexError wxMutex::TryLock()
{ {
wxMacStCritical critical ; wxMacStCritical critical ;
if ( UMASystemIsInitialized() )
{
OSErr err ; OSErr err ;
ThreadID current = kNoThreadID; ThreadID current = kNoThreadID;
::MacGetCurrentThread(&current); ::MacGetCurrentThread(&current);
@@ -148,12 +153,15 @@ wxMutexError wxMutex::TryLock()
return wxMUTEX_BUSY; return wxMUTEX_BUSY;
m_internal->m_owner = current; m_internal->m_owner = current;
}
m_locked++; m_locked++;
return wxMUTEX_NO_ERROR; return wxMUTEX_NO_ERROR;
} }
wxMutexError wxMutex::Unlock() wxMutexError wxMutex::Unlock()
{
if ( UMASystemIsInitialized() )
{ {
OSErr err; OSErr err;
err = ::ThreadBeginCritical(); err = ::ThreadBeginCritical();
@@ -180,7 +188,12 @@ wxMutexError wxMutex::Unlock()
// now we have a valid firstWaiting thread, which has been scheduled to run next, just end the // now we have a valid firstWaiting thread, which has been scheduled to run next, just end the
// critical section and invoke the scheduler // critical section and invoke the scheduler
err = ::SetThreadStateEndCritical(kCurrentThreadID, kReadyThreadState, firstWaiting); err = ::SetThreadStateEndCritical(kCurrentThreadID, kReadyThreadState, firstWaiting);
}
else
{
if (m_locked > 0)
m_locked--;
}
return wxMUTEX_NO_ERROR; return wxMUTEX_NO_ERROR;
} }

View File

@@ -35,7 +35,7 @@
#include "wx/thread.h" #include "wx/thread.h"
#ifdef __WXMAC__ #ifdef __WXMAC__
#include "wx/mac/private.h" #include "wx/mac/uma.h"
#endif #endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -69,10 +69,12 @@ class wxMacStCritical
public : public :
wxMacStCritical() wxMacStCritical()
{ {
if ( UMASystemIsInitialized() )
ThreadBeginCritical() ; ThreadBeginCritical() ;
} }
~wxMacStCritical() ~wxMacStCritical()
{ {
if ( UMASystemIsInitialized() )
ThreadEndCritical() ; ThreadEndCritical() ;
} }
}; };
@@ -118,7 +120,8 @@ wxMutex::~wxMutex()
wxMutexError wxMutex::Lock() wxMutexError wxMutex::Lock()
{ {
wxMacStCritical critical ; wxMacStCritical critical ;
if ( UMASystemIsInitialized() )
{
OSErr err ; OSErr err ;
ThreadID current = kNoThreadID; ThreadID current = kNoThreadID;
err = ::MacGetCurrentThread(&current); err = ::MacGetCurrentThread(&current);
@@ -131,6 +134,7 @@ wxMutexError wxMutex::Lock()
err = ::ThreadBeginCritical(); err = ::ThreadBeginCritical();
} }
m_internal->m_owner = current; m_internal->m_owner = current;
}
m_locked++; m_locked++;
return wxMUTEX_NO_ERROR; return wxMUTEX_NO_ERROR;
@@ -139,7 +143,8 @@ wxMutexError wxMutex::Lock()
wxMutexError wxMutex::TryLock() wxMutexError wxMutex::TryLock()
{ {
wxMacStCritical critical ; wxMacStCritical critical ;
if ( UMASystemIsInitialized() )
{
OSErr err ; OSErr err ;
ThreadID current = kNoThreadID; ThreadID current = kNoThreadID;
::MacGetCurrentThread(&current); ::MacGetCurrentThread(&current);
@@ -148,12 +153,15 @@ wxMutexError wxMutex::TryLock()
return wxMUTEX_BUSY; return wxMUTEX_BUSY;
m_internal->m_owner = current; m_internal->m_owner = current;
}
m_locked++; m_locked++;
return wxMUTEX_NO_ERROR; return wxMUTEX_NO_ERROR;
} }
wxMutexError wxMutex::Unlock() wxMutexError wxMutex::Unlock()
{
if ( UMASystemIsInitialized() )
{ {
OSErr err; OSErr err;
err = ::ThreadBeginCritical(); err = ::ThreadBeginCritical();
@@ -180,7 +188,12 @@ wxMutexError wxMutex::Unlock()
// now we have a valid firstWaiting thread, which has been scheduled to run next, just end the // now we have a valid firstWaiting thread, which has been scheduled to run next, just end the
// critical section and invoke the scheduler // critical section and invoke the scheduler
err = ::SetThreadStateEndCritical(kCurrentThreadID, kReadyThreadState, firstWaiting); err = ::SetThreadStateEndCritical(kCurrentThreadID, kReadyThreadState, firstWaiting);
}
else
{
if (m_locked > 0)
m_locked--;
}
return wxMUTEX_NO_ERROR; return wxMUTEX_NO_ERROR;
} }