/////////////////////////////////////////////////////////////////////////////
-// Name: thread.cpp
+// Name: src/mac/classic/thread.cpp
// Purpose: wxThread Implementation
// Author: Original from Wolfram Gloger/Guilhem Lavaux/Vadim Zeitlin
// Modified by: Stefan Csomor
// 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__
- #pragma implementation "thread.h"
-#endif
-
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifndef WX_PRECOMP
#include "wx/wx.h"
+ #include "wx/module.h"
#endif
#if wxUSE_THREADS
-#include "wx/module.h"
#include "wx/thread.h"
#ifdef __WXMAC__
// ----------------------------------------------------------------------------
static ThreadID gs_idMainThread = kNoThreadID ;
-static bool gs_waitingForThread = FALSE ;
+static bool gs_waitingForThread = false ;
size_t g_numberOfThreads = 0;
// ============================================================================
wxMacStCritical()
{
if ( UMASystemIsInitialized() )
- ThreadBeginCritical() ;
+ {
+ OSErr err = ThreadBeginCritical() ;
+ wxASSERT( err == noErr ) ;
+ }
}
~wxMacStCritical()
{
if ( UMASystemIsInitialized() )
- ThreadEndCritical() ;
+ {
+ OSErr err = ThreadEndCritical() ;
+ wxASSERT( err == noErr ) ;
+ }
}
};
m_waiters.Add(current);
err = ::SetThreadStateEndCritical(kCurrentThreadID, kStoppedThreadState, m_owner);
err = ::ThreadBeginCritical();
+ wxASSERT( err == noErr ) ;
}
m_owner = current;
}
{
OSErr err;
err = ::ThreadBeginCritical();
+ wxASSERT( err == noErr ) ;
if (m_locked > 0)
m_locked--;
if ( err != noErr )
{
wxLogSysError(_("Can't create thread"));
- return FALSE;
+ return false;
}
if ( m_priority != WXTHREAD_DEFAULT_PRIORITY )
m_state = STATE_NEW;
- return TRUE;
+ return true;
}
bool wxThreadInternal::Suspend()
{
OSErr err ;
- ::ThreadBeginCritical();
+ err = ::ThreadBeginCritical();
+ wxASSERT( err == noErr ) ;
if ( m_state != STATE_RUNNING )
{
- ::ThreadEndCritical() ;
+ err = ::ThreadEndCritical() ;
+ wxASSERT( err == noErr ) ;
wxLogSysError(_("Can not suspend thread %x"), m_tid);
- return FALSE;
+ return false;
}
m_state = STATE_PAUSED;
err = ::SetThreadStateEndCritical(m_tid, kStoppedThreadState, kNoThreadID);
- return TRUE;
+ return true;
}
bool wxThreadInternal::Resume()
wxASSERT( err == noErr ) ;
wxASSERT( current != m_tid ) ;
- ::ThreadBeginCritical();
+ err = ::ThreadBeginCritical();
+ wxASSERT( err == noErr ) ;
+
if ( m_state != STATE_PAUSED && m_state != STATE_NEW )
{
- ::ThreadEndCritical() ;
+ err = ::ThreadEndCritical() ;
+ wxASSERT( err == noErr ) ;
wxLogSysError(_("Can not resume thread %x"), m_tid);
- return FALSE;
+ return false;
}
err = ::SetThreadStateEndCritical(m_tid, kReadyThreadState, kNoThreadID);
- wxASSERT( err == noErr ) ;
m_state = STATE_RUNNING;
- ::ThreadEndCritical() ;
+ err = ::ThreadEndCritical() ;
+ wxASSERT( err == noErr ) ;
::YieldToAnyThread() ;
- return TRUE;
+ return true;
}
// static functions
double mssleep = milliseconds * 1000 ;
double msstart, msnow ;
msstart = (start.hi * 4294967296.0 + start.lo) ;
-
+
do
{
YieldToAnyThread();
return level == 1;
}
- return TRUE ;
+ return true ;
}
// ctor and dtor
// Delete() is always safe to call, so consider all possible states
// has the thread started to run?
- bool shouldResume = FALSE;
+ bool shouldResume = false;
{
wxCriticalSectionLocker lock(m_critsect);
// WinThreadStart() will see it and terminate immediately
m_internal->SetState(STATE_EXITED);
- shouldResume = TRUE;
+ shouldResume = true;
}
}
if ( IsMain() )
{
// set flag for wxIsWaitingForThread()
- gs_waitingForThread = TRUE;
+ gs_waitingForThread = true;
#if wxUSE_GUI
wxBeginBusyCursor();
if ( IsMain() )
{
- gs_waitingForThread = FALSE;
+ gs_waitingForThread = false;
#if wxUSE_GUI
wxEndBusyCursor();
if ( !hasThreadManager )
{
wxLogSysError( wxT("Thread Support is not available on this System") );
- return FALSE ;
+ return false ;
}
// no error return for GetCurrentThreadId()
MacGetCurrentThread( &gs_idMainThread ) ;
- return TRUE;
+ return true;
}
void wxThreadModule::OnExit()