1998-05-21 15:02:02 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: thread.h
|
|
|
|
// Purpose: Thread API
|
|
|
|
// Author: Guilhem Lavaux
|
1999-01-17 22:39:58 +00:00
|
|
|
// Modified by: Vadim Zeitlin (modifications partly inspired by omnithreads
|
|
|
|
// package from Olivetti & Oracle Research Laboratory)
|
1998-05-21 15:02:02 +00:00
|
|
|
// Created: 04/13/98
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Guilhem Lavaux
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1998-08-18 17:22:15 +00:00
|
|
|
#ifndef __THREADH__
|
|
|
|
#define __THREADH__
|
1998-05-21 15:02:02 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
1999-01-17 22:39:58 +00:00
|
|
|
#pragma interface "thread.h"
|
1998-05-21 15:02:02 +00:00
|
|
|
#endif
|
|
|
|
|
1999-01-05 03:04:48 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
1999-01-17 22:39:58 +00:00
|
|
|
|
|
|
|
// get the value of wxUSE_THREADS configuration flag
|
1998-05-21 15:02:02 +00:00
|
|
|
#include "wx/setup.h"
|
1999-01-05 03:04:48 +00:00
|
|
|
|
|
|
|
#if wxUSE_THREADS
|
1999-01-17 22:39:58 +00:00
|
|
|
|
|
|
|
// Windows headers define it
|
|
|
|
#ifdef Yield
|
|
|
|
#undef Yield
|
|
|
|
#endif
|
|
|
|
|
1999-01-02 22:24:41 +00:00
|
|
|
#include "wx/module.h"
|
1998-05-21 15:02:02 +00:00
|
|
|
|
1998-12-27 00:54:53 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1999-01-17 22:39:58 +00:00
|
|
|
typedef enum
|
1999-01-02 22:24:41 +00:00
|
|
|
{
|
1998-12-27 00:54:53 +00:00
|
|
|
wxMUTEX_NO_ERROR = 0,
|
1999-01-17 22:39:58 +00:00
|
|
|
wxMUTEX_DEAD_LOCK, // Mutex has been already locked by THE CALLING thread
|
1998-12-27 00:54:53 +00:00
|
|
|
wxMUTEX_BUSY, // Mutex has been already locked by ONE thread
|
|
|
|
wxMUTEX_UNLOCKED,
|
|
|
|
wxMUTEX_MISC_ERROR
|
1998-05-21 15:02:02 +00:00
|
|
|
} wxMutexError;
|
|
|
|
|
1999-01-17 22:39:58 +00:00
|
|
|
typedef enum
|
1999-01-02 22:24:41 +00:00
|
|
|
{
|
1998-12-27 00:54:53 +00:00
|
|
|
wxTHREAD_NO_ERROR = 0, // No error
|
|
|
|
wxTHREAD_NO_RESOURCE, // No resource left to create a new thread
|
|
|
|
wxTHREAD_RUNNING, // The thread is already running
|
|
|
|
wxTHREAD_NOT_RUNNING, // The thread isn't running
|
|
|
|
wxTHREAD_MISC_ERROR // Some other error
|
1998-05-21 15:02:02 +00:00
|
|
|
} wxThreadError;
|
|
|
|
|
1999-01-17 22:39:58 +00:00
|
|
|
// defines the interval of priority
|
|
|
|
#define WXTHREAD_MIN_PRIORITY 0u
|
|
|
|
#define WXTHREAD_DEFAULT_PRIORITY 50u
|
|
|
|
#define WXTHREAD_MAX_PRIORITY 100u
|
1998-05-21 15:02:02 +00:00
|
|
|
|
1999-01-02 22:24:41 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1999-01-05 03:04:48 +00:00
|
|
|
// A mutex object is a synchronization object whose state is set to signaled
|
|
|
|
// when it is not owned by any thread, and nonsignaled when it is owned. Its
|
|
|
|
// name comes from its usefulness in coordinating mutually-exclusive access to
|
|
|
|
// a shared resource. Only one thread at a time can own a mutex object.
|
1998-12-27 00:54:53 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1999-01-02 22:24:41 +00:00
|
|
|
|
1999-01-05 03:04:48 +00:00
|
|
|
// you should consider wxMutexLocker whenever possible instead of directly
|
|
|
|
// working with wxMutex class - it is safer
|
1998-08-18 17:22:15 +00:00
|
|
|
class WXDLLEXPORT wxMutexInternal;
|
1999-01-17 22:39:58 +00:00
|
|
|
class WXDLLEXPORT wxMutex
|
1999-01-02 22:24:41 +00:00
|
|
|
{
|
1998-05-21 15:02:02 +00:00
|
|
|
public:
|
1999-01-17 22:39:58 +00:00
|
|
|
// constructor & destructor
|
1999-01-10 00:04:07 +00:00
|
|
|
wxMutex();
|
|
|
|
~wxMutex();
|
1998-05-21 15:02:02 +00:00
|
|
|
|
1999-01-10 00:04:07 +00:00
|
|
|
// Lock the mutex.
|
|
|
|
wxMutexError Lock();
|
|
|
|
// Try to lock the mutex: if it can't, returns immediately with an error.
|
|
|
|
wxMutexError TryLock();
|
|
|
|
// Unlock the mutex.
|
|
|
|
wxMutexError Unlock();
|
1998-05-21 15:02:02 +00:00
|
|
|
|
1999-01-10 00:04:07 +00:00
|
|
|
// Returns true if the mutex is locked.
|
|
|
|
bool IsLocked() const { return (m_locked > 0); }
|
1998-12-27 00:54:53 +00:00
|
|
|
|
1998-05-21 15:02:02 +00:00
|
|
|
protected:
|
1999-01-10 00:04:07 +00:00
|
|
|
friend class wxCondition;
|
1998-05-21 15:02:02 +00:00
|
|
|
|
1999-01-10 00:04:07 +00:00
|
|
|
// no assignment operator nor copy ctor
|
|
|
|
wxMutex(const wxMutex&);
|
|
|
|
wxMutex& operator=(const wxMutex&);
|
|
|
|
|
|
|
|
int m_locked;
|
|
|
|
wxMutexInternal *p_internal;
|
1998-05-21 15:02:02 +00:00
|
|
|
};
|
|
|
|
|
1999-01-05 03:04:48 +00:00
|
|
|
// a helper class which locks the mutex in the ctor and unlocks it in the dtor:
|
|
|
|
// this ensures that mutex is always unlocked, even if the function returns or
|
|
|
|
// throws an exception before it reaches the end
|
|
|
|
class WXDLLEXPORT wxMutexLocker
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// lock the mutex in the ctor
|
1999-01-22 16:21:24 +00:00
|
|
|
wxMutexLocker(wxMutex& mutex) : m_mutex(mutex)
|
|
|
|
{ m_isOk = m_mutex.Lock() == wxMUTEX_NO_ERROR; }
|
1999-01-05 03:04:48 +00:00
|
|
|
|
|
|
|
// returns TRUE if mutex was successfully locked in ctor
|
1999-01-22 16:21:24 +00:00
|
|
|
bool IsOk() const
|
|
|
|
{ return m_isOk; }
|
1999-01-05 03:04:48 +00:00
|
|
|
|
|
|
|
// unlock the mutex in dtor
|
1999-01-22 16:21:24 +00:00
|
|
|
~wxMutexLocker()
|
|
|
|
{ if ( IsOk() ) m_mutex.Unlock(); }
|
1999-01-05 03:04:48 +00:00
|
|
|
|
|
|
|
private:
|
1999-01-10 00:04:07 +00:00
|
|
|
// no assignment operator nor copy ctor
|
|
|
|
wxMutexLocker(const wxMutexLocker&);
|
|
|
|
wxMutexLocker& operator=(const wxMutexLocker&);
|
|
|
|
|
1999-01-05 03:04:48 +00:00
|
|
|
bool m_isOk;
|
1999-01-22 16:21:24 +00:00
|
|
|
wxMutex& m_mutex;
|
1999-01-05 03:04:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Critical section: this is the same as mutex but is only visible to the
|
|
|
|
// threads of the same process. For the platforms which don't have native
|
|
|
|
// support for critical sections, they're implemented entirely in terms of
|
|
|
|
// mutexes
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1999-01-17 22:39:58 +00:00
|
|
|
// in order to avoid any overhead under !MSW make all wxCriticalSection class
|
|
|
|
// functions inline - but this can't be done under MSW
|
1999-01-11 15:51:45 +00:00
|
|
|
#ifdef __WXMSW__
|
|
|
|
class WXDLLEXPORT wxCriticalSectionInternal;
|
|
|
|
#define WXCRITICAL_INLINE
|
|
|
|
#else // !MSW
|
|
|
|
#define WXCRITICAL_INLINE inline
|
|
|
|
#endif // MSW/!MSW
|
1999-01-17 22:39:58 +00:00
|
|
|
|
|
|
|
// you should consider wxCriticalSectionLocker whenever possible instead of
|
|
|
|
// directly working with wxCriticalSection class - it is safer
|
1999-01-05 03:04:48 +00:00
|
|
|
class WXDLLEXPORT wxCriticalSection
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// ctor & dtor
|
1999-01-11 15:51:45 +00:00
|
|
|
WXCRITICAL_INLINE wxCriticalSection();
|
|
|
|
WXCRITICAL_INLINE ~wxCriticalSection();
|
1999-01-05 03:04:48 +00:00
|
|
|
|
|
|
|
// enter the section (the same as locking a mutex)
|
1999-01-11 15:51:45 +00:00
|
|
|
void WXCRITICAL_INLINE Enter();
|
1999-01-05 03:04:48 +00:00
|
|
|
// leave the critical section (same as unlocking a mutex)
|
1999-01-11 15:51:45 +00:00
|
|
|
void WXCRITICAL_INLINE Leave();
|
1999-01-05 03:04:48 +00:00
|
|
|
|
|
|
|
private:
|
1999-01-10 00:04:07 +00:00
|
|
|
// no assignment operator nor copy ctor
|
|
|
|
wxCriticalSection(const wxCriticalSection&);
|
|
|
|
wxCriticalSection& operator=(const wxCriticalSection&);
|
|
|
|
|
1999-01-11 15:51:45 +00:00
|
|
|
#ifdef __WXMSW__
|
1999-01-05 03:04:48 +00:00
|
|
|
wxCriticalSectionInternal *m_critsect;
|
1999-01-11 15:51:45 +00:00
|
|
|
#else // !MSW
|
|
|
|
wxMutex m_mutex;
|
|
|
|
#endif // MSW/!MSW
|
1999-01-05 03:04:48 +00:00
|
|
|
};
|
|
|
|
|
1999-01-17 22:39:58 +00:00
|
|
|
// keep your preprocessor name space clean
|
|
|
|
#undef WXCRITICAL_INLINE
|
|
|
|
|
1999-01-05 03:04:48 +00:00
|
|
|
// wxCriticalSectionLocker is the same to critical sections as wxMutexLocker is
|
|
|
|
// to th mutexes
|
|
|
|
class WXDLLEXPORT wxCriticalSectionLocker
|
|
|
|
{
|
|
|
|
public:
|
1999-01-09 00:28:27 +00:00
|
|
|
wxCriticalSectionLocker(wxCriticalSection& critsect) : m_critsect(critsect)
|
|
|
|
{ m_critsect.Enter(); }
|
1999-01-05 03:04:48 +00:00
|
|
|
~wxCriticalSectionLocker()
|
1999-01-09 00:28:27 +00:00
|
|
|
{ m_critsect.Leave(); }
|
1999-01-05 03:04:48 +00:00
|
|
|
|
|
|
|
private:
|
1999-01-10 00:04:07 +00:00
|
|
|
// no assignment operator nor copy ctor
|
|
|
|
wxCriticalSectionLocker(const wxCriticalSectionLocker&);
|
|
|
|
wxCriticalSectionLocker& operator=(const wxCriticalSectionLocker&);
|
|
|
|
|
1999-01-09 00:28:27 +00:00
|
|
|
wxCriticalSection& m_critsect;
|
1999-01-05 03:04:48 +00:00
|
|
|
};
|
|
|
|
|
1998-12-27 00:54:53 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-05-21 15:02:02 +00:00
|
|
|
// Condition handler.
|
1998-12-27 00:54:53 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1999-01-02 22:24:41 +00:00
|
|
|
|
1998-05-21 15:02:02 +00:00
|
|
|
class wxConditionInternal;
|
1999-01-17 22:39:58 +00:00
|
|
|
class WXDLLEXPORT wxCondition
|
1999-01-02 22:24:41 +00:00
|
|
|
{
|
1998-05-21 15:02:02 +00:00
|
|
|
public:
|
|
|
|
// constructor & destructor
|
1998-06-14 12:15:13 +00:00
|
|
|
wxCondition();
|
|
|
|
~wxCondition();
|
1998-05-21 15:02:02 +00:00
|
|
|
|
1998-06-14 12:15:13 +00:00
|
|
|
// Waits indefinitely.
|
1998-05-21 15:02:02 +00:00
|
|
|
void Wait(wxMutex& mutex);
|
|
|
|
// Waits until a signal is raised or the timeout is elapsed.
|
|
|
|
bool Wait(wxMutex& mutex, unsigned long sec, unsigned long nsec);
|
|
|
|
// Raises a signal: only one "Waiter" is released.
|
1998-06-14 12:15:13 +00:00
|
|
|
void Signal();
|
1998-05-21 15:02:02 +00:00
|
|
|
// Broadcasts to all "Waiters".
|
1998-06-14 12:15:13 +00:00
|
|
|
void Broadcast();
|
1998-12-27 00:54:53 +00:00
|
|
|
|
1998-05-21 15:02:02 +00:00
|
|
|
private:
|
|
|
|
wxConditionInternal *p_internal;
|
|
|
|
};
|
|
|
|
|
1998-12-27 00:54:53 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-05-21 15:02:02 +00:00
|
|
|
// Thread management class
|
1998-12-27 00:54:53 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1999-01-02 22:24:41 +00:00
|
|
|
|
1999-01-17 22:39:58 +00:00
|
|
|
// FIXME Thread termination model is still unclear. Delete() should probably
|
|
|
|
// have a timeout after which the thread must be Kill()ed.
|
|
|
|
|
|
|
|
// NB: in the function descriptions the words "this thread" mean the thread
|
|
|
|
// created by the wxThread object while "main thread" is the thread created
|
|
|
|
// during the process initialization (a.k.a. the GUI thread)
|
1998-05-21 15:02:02 +00:00
|
|
|
class wxThreadInternal;
|
1999-01-17 22:39:58 +00:00
|
|
|
class WXDLLEXPORT wxThread
|
1999-01-02 22:24:41 +00:00
|
|
|
{
|
1998-05-21 15:02:02 +00:00
|
|
|
public:
|
1999-01-17 22:39:58 +00:00
|
|
|
// the return type for the thread function
|
|
|
|
typedef void *ExitCode;
|
|
|
|
|
|
|
|
// static functions
|
|
|
|
// Returns the wxThread object for the calling thread. NULL is returned
|
|
|
|
// if the caller is the main thread (but it's recommended to use
|
|
|
|
// IsMain() and only call This() for threads other than the main one
|
|
|
|
// because NULL is also returned on error). If the thread wasn't
|
|
|
|
// created with wxThread class, the returned value is undefined.
|
|
|
|
static wxThread *This();
|
|
|
|
|
|
|
|
// Returns true if current thread is the main thread.
|
|
|
|
static bool IsMain();
|
|
|
|
|
|
|
|
// Release the rest of our time slice leting the other threads run
|
|
|
|
static void Yield();
|
|
|
|
|
|
|
|
// Sleep during the specified period of time in milliseconds
|
|
|
|
//
|
|
|
|
// NB: at least under MSW worker threads can not call ::wxSleep()!
|
|
|
|
static void Sleep(unsigned long milliseconds);
|
|
|
|
|
|
|
|
// default constructor
|
|
|
|
wxThread();
|
|
|
|
|
|
|
|
// function that change the thread state
|
|
|
|
// create a new thread - call Run() to start it
|
|
|
|
wxThreadError Create();
|
|
|
|
|
|
|
|
// starts execution of the thread - from the moment Run() is called the
|
|
|
|
// execution of wxThread::Entry() may start at any moment, caller
|
|
|
|
// shouldn't suppose that it starts after (or before) Run() returns.
|
|
|
|
wxThreadError Run();
|
|
|
|
|
|
|
|
// stops the thread if it's running and deletes the wxThread object
|
|
|
|
// freeing its memory. This function should also be called if the
|
|
|
|
// Create() or Run() fails to free memory (otherwise it will be done by
|
|
|
|
// the thread itself when it terminates). The return value is the
|
|
|
|
// thread exit code if the thread was gracefully terminated, 0 if it
|
|
|
|
// wasn't running and -1 if an error occured.
|
|
|
|
ExitCode Delete();
|
|
|
|
|
|
|
|
// kills the thread without giving it any chance to clean up - should
|
|
|
|
// not be used in normal circumstances, use Delete() instead. It is a
|
|
|
|
// dangerous function that should only be used in the most extreme
|
|
|
|
// cases! The wxThread object is deleted by Kill() if thread was
|
|
|
|
// killed (i.e. no errors occured).
|
|
|
|
wxThreadError Kill();
|
|
|
|
|
|
|
|
// pause a running thread
|
|
|
|
wxThreadError Pause();
|
|
|
|
|
|
|
|
// resume a paused thread
|
|
|
|
wxThreadError Resume();
|
|
|
|
|
|
|
|
// priority
|
|
|
|
// Sets the priority to "prio": see WXTHREAD_XXX_PRIORITY constants
|
|
|
|
//
|
|
|
|
// NB: the priority can only be set before the thread is created
|
|
|
|
void SetPriority(unsigned int prio);
|
|
|
|
|
|
|
|
// Get the current priority.
|
|
|
|
unsigned int GetPriority() const;
|
|
|
|
|
|
|
|
// Get the thread ID - a platform dependent number which uniquely
|
|
|
|
// identifies a thread inside a process
|
|
|
|
unsigned long GetID() const;
|
|
|
|
|
|
|
|
// thread status inquiries
|
|
|
|
// Returns true if the thread is alive: i.e. running or suspended
|
|
|
|
bool IsAlive() const;
|
|
|
|
// Returns true if the thread is running (not paused, not killed).
|
|
|
|
bool IsRunning() const;
|
|
|
|
// Returns true if the thread is suspended
|
|
|
|
bool IsPaused() const { return IsAlive() && !IsRunning(); }
|
|
|
|
|
|
|
|
// called when the thread exits - in the context of this thread
|
|
|
|
//
|
|
|
|
// NB: this function will not be called if the thread is Kill()ed
|
|
|
|
virtual void OnExit() { }
|
1998-05-21 15:02:02 +00:00
|
|
|
|
1999-01-17 22:39:58 +00:00
|
|
|
protected:
|
|
|
|
// Returns TRUE if the thread was asked to terminate: this function should
|
|
|
|
// be called by the thread from time to time, otherwise the main thread
|
|
|
|
// will be left forever in Delete()!
|
1999-01-22 18:35:42 +00:00
|
|
|
bool TestDestroy();
|
1998-05-21 15:02:02 +00:00
|
|
|
|
1999-01-17 22:39:58 +00:00
|
|
|
// exits from the current thread - can be called only from this thread
|
|
|
|
void Exit(void *exitcode = 0);
|
1998-08-18 17:22:15 +00:00
|
|
|
|
1999-01-17 22:39:58 +00:00
|
|
|
// destructor is private - user code can't delete thread objects, they will
|
|
|
|
// auto-delete themselves (and thus must be always allocated on the heap).
|
|
|
|
// Use Delete() or Kill() instead.
|
|
|
|
//
|
|
|
|
// NB: derived classes dtors shouldn't be public neither!
|
|
|
|
virtual ~wxThread();
|
1999-01-05 03:04:48 +00:00
|
|
|
|
1999-01-17 22:39:58 +00:00
|
|
|
// entry point for the thread - called by Run() and executes in the context
|
|
|
|
// of this thread.
|
|
|
|
virtual void *Entry() = 0;
|
1998-12-27 00:54:53 +00:00
|
|
|
|
1998-05-21 15:02:02 +00:00
|
|
|
private:
|
1999-01-17 22:39:58 +00:00
|
|
|
// no copy ctor/assignment operator
|
|
|
|
wxThread(const wxThread&);
|
|
|
|
wxThread& operator=(const wxThread&);
|
1998-05-21 15:02:02 +00:00
|
|
|
|
1999-01-17 22:39:58 +00:00
|
|
|
friend class wxThreadInternal;
|
|
|
|
|
|
|
|
// the (platform-dependent) thread class implementation
|
|
|
|
wxThreadInternal *p_internal;
|
1998-05-21 15:02:02 +00:00
|
|
|
|
1999-01-17 22:39:58 +00:00
|
|
|
// protects access to any methods of wxThreadInternal object
|
|
|
|
wxCriticalSection m_critsect;
|
1998-05-21 15:02:02 +00:00
|
|
|
};
|
|
|
|
|
1998-12-27 00:54:53 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1999-01-02 22:24:41 +00:00
|
|
|
// Automatic initialization
|
1998-12-27 00:54:53 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-05-21 15:02:02 +00:00
|
|
|
|
1999-01-05 03:04:48 +00:00
|
|
|
// GUI mutex handling.
|
|
|
|
void WXDLLEXPORT wxMutexGuiEnter();
|
|
|
|
void WXDLLEXPORT wxMutexGuiLeave();
|
1999-01-02 22:24:41 +00:00
|
|
|
|
1999-01-05 03:04:48 +00:00
|
|
|
#else // !wxUSE_THREADS
|
1999-01-02 22:24:41 +00:00
|
|
|
|
1999-01-05 03:04:48 +00:00
|
|
|
// no thread support
|
|
|
|
inline void WXDLLEXPORT wxMutexGuiEnter() { }
|
|
|
|
inline void WXDLLEXPORT wxMutexGuiLeave() { }
|
1999-01-02 22:24:41 +00:00
|
|
|
|
1999-01-05 03:04:48 +00:00
|
|
|
#endif // wxUSE_THREADS
|
1998-05-21 15:02:02 +00:00
|
|
|
|
1999-01-09 00:28:27 +00:00
|
|
|
// automatically unlock GUI mutex in dtor
|
|
|
|
class WXDLLEXPORT wxMutexGuiLocker
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxMutexGuiLocker() { wxMutexGuiEnter(); }
|
|
|
|
~wxMutexGuiLocker() { wxMutexGuiLeave(); }
|
|
|
|
};
|
|
|
|
|
1999-01-11 15:51:45 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// implementation only until the end of file
|
|
|
|
// -----------------------------------------------------------------------------
|
1999-01-24 14:57:09 +00:00
|
|
|
#if wxUSE_THREADS
|
1999-01-11 15:51:45 +00:00
|
|
|
#ifdef __WXMSW__
|
|
|
|
// unlock GUI if there are threads waiting for and lock it back when
|
|
|
|
// there are no more of them - should be called periodically by the main
|
|
|
|
// thread
|
1999-01-12 23:39:07 +00:00
|
|
|
extern void WXDLLEXPORT wxMutexGuiLeaveOrEnter();
|
1999-01-11 15:51:45 +00:00
|
|
|
|
|
|
|
// returns TRUE if the main thread has GUI lock
|
1999-01-12 23:39:07 +00:00
|
|
|
extern bool WXDLLEXPORT wxGuiOwnedByMainThread();
|
1999-01-11 15:51:45 +00:00
|
|
|
|
|
|
|
// wakes up the main thread if it's sleeping inside ::GetMessage()
|
1999-01-12 23:39:07 +00:00
|
|
|
extern void WXDLLEXPORT wxWakeUpMainThread();
|
1999-01-17 22:39:58 +00:00
|
|
|
|
|
|
|
// return TRUE if the main thread is waiting for some other to terminate:
|
|
|
|
// wxApp then should block all "dangerous" messages
|
|
|
|
extern bool WXDLLEXPORT wxIsWaitingForThread();
|
1999-01-11 15:51:45 +00:00
|
|
|
#else // !MSW
|
|
|
|
// implement wxCriticalSection using mutexes
|
|
|
|
inline wxCriticalSection::wxCriticalSection() { }
|
|
|
|
inline wxCriticalSection::~wxCriticalSection() { }
|
|
|
|
|
|
|
|
inline void wxCriticalSection::Enter() { (void)m_mutex.Lock(); }
|
|
|
|
inline void wxCriticalSection::Leave() { (void)m_mutex.Unlock(); }
|
|
|
|
#endif // MSW/!MSW
|
|
|
|
#endif // wxUSE_THREADS
|
|
|
|
|
1998-12-27 00:54:53 +00:00
|
|
|
#endif // __THREADH__
|