// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// id of the main thread - the one which can call GUI functions without first
// calling wxMutexGuiEnter()
// id of the main thread - the one which can call GUI functions without first
// calling wxMutexGuiEnter()
-// if it's FALSE, some secondary thread is holding the GUI lock
-static bool gs_bGuiOwnedByMainThread = TRUE;
+// if it's false, some secondary thread is holding the GUI lock
+static bool gs_bGuiOwnedByMainThread = true;
// critical section which controls access to all GUI functions: any secondary
// thread (i.e. except the main one) must enter this crit section before doing
// critical section which controls access to all GUI functions: any secondary
// thread (i.e. except the main one) must enter this crit section before doing
// ============================================================================
// OS/2 implementation of thread and related classes
// ============================================================================
// OS/2 implementation of thread and related classes
bool IsOk() const { return m_vMutex != NULL; }
wxMutexError Lock() { return LockTimeout(SEM_INDEFINITE_WAIT); }
bool IsOk() const { return m_vMutex != NULL; }
wxMutexError Lock() { return LockTimeout(SEM_INDEFINITE_WAIT); }
// (Calls to DosRequestMutexSem and DosReleaseMutexSem can be nested, but
// the request count for a semaphore cannot exceed 65535. If an attempt is
// made to exceed this number, ERROR_TOO_MANY_SEM_REQUESTS is returned.)
// (Calls to DosRequestMutexSem and DosReleaseMutexSem can be nested, but
// the request count for a semaphore cannot exceed 65535. If an attempt is
// made to exceed this number, ERROR_TOO_MANY_SEM_REQUESTS is returned.)
- APIRET ulrc;
-
- ulrc = ::DosCreateMutexSem(NULL, &m_vMutex, 0L, FALSE);
+ APIRET ulrc = ::DosCreateMutexSem(NULL, &m_vMutex, 0L, FALSE);
+wxMutexError wxMutexInternal::TryLock()
+{
+ const wxMutexError rc = LockTimeout( SEM_IMMEDIATE_RETURN );
+
+ // we have a special return code for timeout in this case
+ return rc == wxMUTEX_TIMEOUT ? wxMUTEX_BUSY : rc;
+}
+
ulrc = ::DosCreateMutexSem(NULL, &m_vMutex, 0L, FALSE);
if (ulrc != 0)
{
ulrc = ::DosCreateMutexSem(NULL, &m_vMutex, 0L, FALSE);
if (ulrc != 0)
{
ulrc = ::DosCreateEventSem(NULL, &m_vEvent, 0L, FALSE);
if ( ulrc != 0)
{
ulrc = ::DosCreateEventSem(NULL, &m_vEvent, 0L, FALSE);
if ( ulrc != 0)
{
return wxSEMA_MISC_ERROR;
}
ulrc = :: DosRequestMutexSem(m_vMutex, ulMilliseconds);
return wxSEMA_MISC_ERROR;
}
ulrc = :: DosRequestMutexSem(m_vMutex, ulMilliseconds);
private:
// Threads in OS/2 have only an ID, so m_hThread is both it's handle and ID
// PM also has no real Tls mechanism to index pointers by so we'll just
private:
// Threads in OS/2 have only an ID, so m_hThread is both it's handle and ID
// PM also has no real Tls mechanism to index pointers by so we'll just
TID m_hThread; // handle and ID of the thread
wxThreadState m_eState; // state, see wxThreadState enum
unsigned int m_nPriority; // thread priority in "wx" units
};
TID m_hThread; // handle and ID of the thread
wxThreadState m_eState; // state, see wxThreadState enum
unsigned int m_nPriority; // thread priority in "wx" units
};
-bool wxThreadInternal::Create(
- wxThread* pThread
-, unsigned int uStackSize
-)
+bool wxThreadInternal::Create( wxThread* pThread,
+ unsigned int uStackSize)
pThread->m_critsect.Enter();
tid = _beginthread(wxThreadInternal::OS2ThreadStart,
pThread->m_critsect.Enter();
tid = _beginthread(wxThreadInternal::OS2ThreadStart,
// although under Windows we can wait for any thread, it's an error to
// wait for a detached one in wxWin API
wxCHECK_MSG( !IsDetached(), (ExitCode)-1,
// although under Windows we can wait for any thread, it's an error to
// wait for a detached one in wxWin API
wxCHECK_MSG( !IsDetached(), (ExitCode)-1,
// we might need to resume the thread, but we might also not need to cancel
// it if it doesn't run yet
// we might need to resume the thread, but we might also not need to cancel
// it if it doesn't run yet
// we can't just wait for the thread to terminate because it might be
// calling some GUI functions and so it will never terminate before we
// process the Windows messages that result from these functions
// we can't just wait for the thread to terminate because it might be
// calling some GUI functions and so it will never terminate before we
// process the Windows messages that result from these functions
- if ( IsMain() )
- {
- // event processing - needed if we are the main thread
- // to give other threads a chance to do remaining GUI
- // processing and terminate cleanly.
- wxTheApp->HandleSockets();
- if (wxTheApp->Pending())
- if ( !wxTheApp->DoMessage() )
- {
- // WM_QUIT received: kill the thread
- Kill();
-
- return wxTHREAD_KILLED;
- }
- else
- wxUsleep(10);
- }
- else
- wxUsleep(10);
+ if ( IsMain() )
+ {
+ // event processing - needed if we are the main thread
+ // to give other threads a chance to do remaining GUI
+ // processing and terminate cleanly.
+ wxTheApp->HandleSockets();
+ if (wxTheApp->Pending())
+ if ( !wxTheApp->DoMessage() )
+ {
+ // WM_QUIT received: kill the thread
+ Kill();
+
+ return wxTHREAD_KILLED;
+ }
+ else
+ wxUsleep(10);
+ }
+ else
+ wxUsleep(10);
{
// this would dead lock everything...
wxASSERT_MSG( !wxThread::IsMain(),
{
// this would dead lock everything...
wxASSERT_MSG( !wxThread::IsMain(),