git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13597
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
class wxMacStCritical
{
public :
class wxMacStCritical
{
public :
{
if ( UMASystemIsInitialized() )
ThreadBeginCritical() ;
{
if ( UMASystemIsInitialized() )
ThreadBeginCritical() ;
m_owner = kNoThreadID ;
}
m_owner = kNoThreadID ;
}
err = ::MacGetCurrentThread(¤t);
// if we are not the owner, add this thread to the list of waiting threads, stop this thread
// and invoke the scheduler to continue executing the owner's thread
err = ::MacGetCurrentThread(¤t);
// if we are not the owner, add this thread to the list of waiting threads, stop this thread
// and invoke the scheduler to continue executing the owner's thread
- while ( m_internal->m_owner != kNoThreadID && m_internal->m_owner != current)
+ while ( m_internal->m_owner != kNoThreadID && m_internal->m_owner != current)
{
m_internal->m_waiters.Add(current);
err = ::SetThreadStateEndCritical(kCurrentThreadID, kStoppedThreadState, m_internal->m_owner);
{
m_internal->m_waiters.Add(current);
err = ::SetThreadStateEndCritical(kCurrentThreadID, kStoppedThreadState, m_internal->m_owner);
{
wxMacStCritical critical ;
if ( UMASystemIsInitialized() )
{
wxMacStCritical critical ;
if ( UMASystemIsInitialized() )
OSErr err ;
ThreadID current = kNoThreadID;
::MacGetCurrentThread(¤t);
// if we are not the owner, give an error back
OSErr err ;
ThreadID current = kNoThreadID;
::MacGetCurrentThread(¤t);
// if we are not the owner, give an error back
- if ( m_internal->m_owner != kNoThreadID && m_internal->m_owner != current )
+ if ( m_internal->m_owner != kNoThreadID && m_internal->m_owner != current )
m_internal->m_owner = current;
}
m_locked++;
m_internal->m_owner = current;
}
m_locked++;
wxMutexError wxMutex::Unlock()
{
if ( UMASystemIsInitialized() )
wxMutexError wxMutex::Unlock()
{
if ( UMASystemIsInitialized() )
OSErr err;
err = ::ThreadBeginCritical();
OSErr err;
err = ::ThreadBeginCritical();
if (m_locked > 0)
m_locked--;
if (m_locked > 0)
m_locked--;
// now pass on to the first waiting thread
ThreadID firstWaiting = kNoThreadID;
bool found = false;
// now pass on to the first waiting thread
ThreadID firstWaiting = kNoThreadID;
bool found = false;
- while (!m_internal->m_waiters.IsEmpty() && !found)
+ while (!m_internal->m_waiters.IsEmpty() && !found)
{
firstWaiting = m_internal->m_waiters[0];
err = ::SetThreadState(firstWaiting, kReadyThreadState, kNoThreadID);
// in case this was not successful (dead thread), we just loop on and reset the id
{
firstWaiting = m_internal->m_waiters[0];
err = ::SetThreadState(firstWaiting, kReadyThreadState, kNoThreadID);
// in case this was not successful (dead thread), we just loop on and reset the id
- found = (err != threadNotFoundErr);
+ found = (err != threadNotFoundErr);
if ( !found )
firstWaiting = kNoThreadID ;
m_internal->m_waiters.RemoveAt(0) ;
if ( !found )
firstWaiting = kNoThreadID ;
m_internal->m_waiters.RemoveAt(0) ;
// thread priority
void SetPriority(unsigned int priority);
unsigned int GetPriority() const { return m_priority; }
// thread priority
void SetPriority(unsigned int priority);
unsigned int GetPriority() const { return m_priority; }
void SetResult( void *res ) { m_result = res ; }
void *GetResult() { return m_result ; }
void SetResult( void *res ) { m_result = res ; }
void *GetResult() { return m_result ; }
bool wxThreadInternal::Suspend()
{
OSErr err ;
bool wxThreadInternal::Suspend()
{
OSErr err ;
::ThreadBeginCritical();
if ( m_state != STATE_RUNNING )
::ThreadBeginCritical();
if ( m_state != STATE_RUNNING )
wxASSERT( err == noErr ) ;
wxASSERT( current != m_tid ) ;
wxASSERT( err == noErr ) ;
wxASSERT( current != m_tid ) ;
::ThreadBeginCritical();
if ( m_state != STATE_PAUSED && m_state != STATE_NEW )
{
::ThreadEndCritical() ;
wxLogSysError(_("Can not resume thread %x"), m_tid);
return FALSE;
::ThreadBeginCritical();
if ( m_state != STATE_PAUSED && m_state != STATE_NEW )
{
::ThreadEndCritical() ;
wxLogSysError(_("Can not resume thread %x"), m_tid);
return FALSE;
}
err = ::SetThreadStateEndCritical(m_tid, kReadyThreadState, kNoThreadID);
wxASSERT( err == noErr ) ;
}
err = ::SetThreadStateEndCritical(m_tid, kReadyThreadState, kNoThreadID);
wxASSERT( err == noErr ) ;
m_state = STATE_RUNNING;
::ThreadEndCritical() ;
::YieldToAnyThread() ;
m_state = STATE_RUNNING;
::ThreadEndCritical() ;
::YieldToAnyThread() ;
wxThread *wxThread::This()
{
wxMacStCritical critical ;
wxThread *wxThread::This()
{
wxMacStCritical critical ;
ThreadID current ;
OSErr err ;
ThreadID current ;
OSErr err ;
err = MacGetCurrentThread( ¤t ) ;
err = MacGetCurrentThread( ¤t ) ;
for ( int i = 0 ; i < s_threads.Count() ; ++i )
{
if ( ( (wxThread*) s_threads[i] )->GetId() == current )
for ( int i = 0 ; i < s_threads.Count() ; ++i )
{
if ( ( (wxThread*) s_threads[i] )->GetId() == current )
{
ThreadID current ;
OSErr err ;
{
ThreadID current ;
OSErr err ;
err = MacGetCurrentThread( ¤t ) ;
return current == gs_idMainThread;
}
err = MacGetCurrentThread( ¤t ) ;
return current == gs_idMainThread;
}
void wxThread::Sleep(unsigned long milliseconds)
{
clock_t start = clock() ;
void wxThread::Sleep(unsigned long milliseconds)
{
clock_t start = clock() ;
{
YieldToAnyThread() ;
} while( clock() - start < milliseconds / CLOCKS_PER_SEC ) ;
{
YieldToAnyThread() ;
} while( clock() - start < milliseconds / CLOCKS_PER_SEC ) ;
+unsigned long wxThread::GetCurrentId()
+{
+ ThreadID current ;
+ MacGetCurrentThread( ¤t ) ;
+ return (unsigned long)current;
+}
+
bool wxThread::SetConcurrency(size_t level)
{
wxASSERT_MSG( IsMain(), _T("should only be called from the main thread") );
bool wxThread::SetConcurrency(size_t level)
{
wxASSERT_MSG( IsMain(), _T("should only be called from the main thread") );
// processor system it doesn't make much sense anyhow
return level == 1;
}
// processor system it doesn't make much sense anyhow
return level == 1;
}
m_internal->SetResult( status ) ;
m_internal->SetResult( status ) ;
#if defined(__VISUALC__) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x500))
_endthreadex((unsigned)status);
#else // !VC++
#if defined(__VISUALC__) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x500))
_endthreadex((unsigned)status);
#else // !VC++
-// wake up the main thread
+// wake up the main thread
void WXDLLEXPORT wxWakeUpMainThread()
{
wxMacWakeUp() ;
void WXDLLEXPORT wxWakeUpMainThread()
{
wxMacWakeUp() ;
class wxMacStCritical
{
public :
class wxMacStCritical
{
public :
{
if ( UMASystemIsInitialized() )
ThreadBeginCritical() ;
{
if ( UMASystemIsInitialized() )
ThreadBeginCritical() ;
m_owner = kNoThreadID ;
}
m_owner = kNoThreadID ;
}
err = ::MacGetCurrentThread(¤t);
// if we are not the owner, add this thread to the list of waiting threads, stop this thread
// and invoke the scheduler to continue executing the owner's thread
err = ::MacGetCurrentThread(¤t);
// if we are not the owner, add this thread to the list of waiting threads, stop this thread
// and invoke the scheduler to continue executing the owner's thread
- while ( m_internal->m_owner != kNoThreadID && m_internal->m_owner != current)
+ while ( m_internal->m_owner != kNoThreadID && m_internal->m_owner != current)
{
m_internal->m_waiters.Add(current);
err = ::SetThreadStateEndCritical(kCurrentThreadID, kStoppedThreadState, m_internal->m_owner);
{
m_internal->m_waiters.Add(current);
err = ::SetThreadStateEndCritical(kCurrentThreadID, kStoppedThreadState, m_internal->m_owner);
{
wxMacStCritical critical ;
if ( UMASystemIsInitialized() )
{
wxMacStCritical critical ;
if ( UMASystemIsInitialized() )
OSErr err ;
ThreadID current = kNoThreadID;
::MacGetCurrentThread(¤t);
// if we are not the owner, give an error back
OSErr err ;
ThreadID current = kNoThreadID;
::MacGetCurrentThread(¤t);
// if we are not the owner, give an error back
- if ( m_internal->m_owner != kNoThreadID && m_internal->m_owner != current )
+ if ( m_internal->m_owner != kNoThreadID && m_internal->m_owner != current )
m_internal->m_owner = current;
}
m_locked++;
m_internal->m_owner = current;
}
m_locked++;
wxMutexError wxMutex::Unlock()
{
if ( UMASystemIsInitialized() )
wxMutexError wxMutex::Unlock()
{
if ( UMASystemIsInitialized() )
OSErr err;
err = ::ThreadBeginCritical();
OSErr err;
err = ::ThreadBeginCritical();
if (m_locked > 0)
m_locked--;
if (m_locked > 0)
m_locked--;
// now pass on to the first waiting thread
ThreadID firstWaiting = kNoThreadID;
bool found = false;
// now pass on to the first waiting thread
ThreadID firstWaiting = kNoThreadID;
bool found = false;
- while (!m_internal->m_waiters.IsEmpty() && !found)
+ while (!m_internal->m_waiters.IsEmpty() && !found)
{
firstWaiting = m_internal->m_waiters[0];
err = ::SetThreadState(firstWaiting, kReadyThreadState, kNoThreadID);
// in case this was not successful (dead thread), we just loop on and reset the id
{
firstWaiting = m_internal->m_waiters[0];
err = ::SetThreadState(firstWaiting, kReadyThreadState, kNoThreadID);
// in case this was not successful (dead thread), we just loop on and reset the id
- found = (err != threadNotFoundErr);
+ found = (err != threadNotFoundErr);
if ( !found )
firstWaiting = kNoThreadID ;
m_internal->m_waiters.RemoveAt(0) ;
if ( !found )
firstWaiting = kNoThreadID ;
m_internal->m_waiters.RemoveAt(0) ;
// thread priority
void SetPriority(unsigned int priority);
unsigned int GetPriority() const { return m_priority; }
// thread priority
void SetPriority(unsigned int priority);
unsigned int GetPriority() const { return m_priority; }
void SetResult( void *res ) { m_result = res ; }
void *GetResult() { return m_result ; }
void SetResult( void *res ) { m_result = res ; }
void *GetResult() { return m_result ; }
bool wxThreadInternal::Suspend()
{
OSErr err ;
bool wxThreadInternal::Suspend()
{
OSErr err ;
::ThreadBeginCritical();
if ( m_state != STATE_RUNNING )
::ThreadBeginCritical();
if ( m_state != STATE_RUNNING )
wxASSERT( err == noErr ) ;
wxASSERT( current != m_tid ) ;
wxASSERT( err == noErr ) ;
wxASSERT( current != m_tid ) ;
::ThreadBeginCritical();
if ( m_state != STATE_PAUSED && m_state != STATE_NEW )
{
::ThreadEndCritical() ;
wxLogSysError(_("Can not resume thread %x"), m_tid);
return FALSE;
::ThreadBeginCritical();
if ( m_state != STATE_PAUSED && m_state != STATE_NEW )
{
::ThreadEndCritical() ;
wxLogSysError(_("Can not resume thread %x"), m_tid);
return FALSE;
}
err = ::SetThreadStateEndCritical(m_tid, kReadyThreadState, kNoThreadID);
wxASSERT( err == noErr ) ;
}
err = ::SetThreadStateEndCritical(m_tid, kReadyThreadState, kNoThreadID);
wxASSERT( err == noErr ) ;
m_state = STATE_RUNNING;
::ThreadEndCritical() ;
::YieldToAnyThread() ;
m_state = STATE_RUNNING;
::ThreadEndCritical() ;
::YieldToAnyThread() ;
wxThread *wxThread::This()
{
wxMacStCritical critical ;
wxThread *wxThread::This()
{
wxMacStCritical critical ;
ThreadID current ;
OSErr err ;
ThreadID current ;
OSErr err ;
err = MacGetCurrentThread( ¤t ) ;
err = MacGetCurrentThread( ¤t ) ;
for ( int i = 0 ; i < s_threads.Count() ; ++i )
{
if ( ( (wxThread*) s_threads[i] )->GetId() == current )
for ( int i = 0 ; i < s_threads.Count() ; ++i )
{
if ( ( (wxThread*) s_threads[i] )->GetId() == current )
{
ThreadID current ;
OSErr err ;
{
ThreadID current ;
OSErr err ;
err = MacGetCurrentThread( ¤t ) ;
return current == gs_idMainThread;
}
err = MacGetCurrentThread( ¤t ) ;
return current == gs_idMainThread;
}
void wxThread::Sleep(unsigned long milliseconds)
{
clock_t start = clock() ;
void wxThread::Sleep(unsigned long milliseconds)
{
clock_t start = clock() ;
{
YieldToAnyThread() ;
} while( clock() - start < milliseconds / CLOCKS_PER_SEC ) ;
{
YieldToAnyThread() ;
} while( clock() - start < milliseconds / CLOCKS_PER_SEC ) ;
+unsigned long wxThread::GetCurrentId()
+{
+ ThreadID current ;
+ MacGetCurrentThread( ¤t ) ;
+ return (unsigned long)current;
+}
+
bool wxThread::SetConcurrency(size_t level)
{
wxASSERT_MSG( IsMain(), _T("should only be called from the main thread") );
bool wxThread::SetConcurrency(size_t level)
{
wxASSERT_MSG( IsMain(), _T("should only be called from the main thread") );
// processor system it doesn't make much sense anyhow
return level == 1;
}
// processor system it doesn't make much sense anyhow
return level == 1;
}
m_internal->SetResult( status ) ;
m_internal->SetResult( status ) ;
#if defined(__VISUALC__) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x500))
_endthreadex((unsigned)status);
#else // !VC++
#if defined(__VISUALC__) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x500))
_endthreadex((unsigned)status);
#else // !VC++
-// wake up the main thread
+// wake up the main thread
void WXDLLEXPORT wxWakeUpMainThread()
{
wxMacWakeUp() ;
void WXDLLEXPORT wxWakeUpMainThread()
{
wxMacWakeUp() ;