]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/thread.h
64481d7c8854aa42327c6fc4828a57424604717c
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Guilhem Lavaux
8 // Copyright: (c) Guilhem Lavaux
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "thread.h"
19 #include "wx/object.h"
24 MUTEX_DEAD_LOCK
, // Mutex has been already locked by THE CALLING thread
25 MUTEX_BUSY
, // Mutex has been already locked by ONE thread
30 THREAD_NO_ERROR
=0, // No error
31 THREAD_NO_RESOURCE
, // No resource left to create a new thread
32 THREAD_RUNNING
, // The thread is already running
33 THREAD_NOT_RUNNING
// The thread isn't running
36 // defines the interval of priority.
37 #define WXTHREAD_MIN_PRIORITY 0
38 #define WXTHREAD_DEFAULT_PRIORITY 50
39 #define WXTHREAD_MAX_PRIORITY 100
41 // ---------------------------------------------------------------------------
43 class wxMutexInternal
;
44 class WXDLLEXPORT wxMutex
{
46 // constructor & destructor
52 // Try to lock the mutex: if it can't, returns immediately with an error.
53 wxMutexError
TryLock();
55 wxMutexError
Unlock();
57 // Returns true if the mutex is locked.
58 bool IsLocked() const { return (m_locked
> 0); }
60 friend class wxCondition
;
63 wxMutexInternal
*p_internal
;
66 // ---------------------------------------------------------------------------
68 class wxConditionInternal
;
69 class WXDLLEXPORT wxCondition
{
71 // constructor & destructor
75 // Waits indefinitely.
76 void Wait(wxMutex
& mutex
);
77 // Waits until a signal is raised or the timeout is elapsed.
78 bool Wait(wxMutex
& mutex
, unsigned long sec
, unsigned long nsec
);
79 // Raises a signal: only one "Waiter" is released.
81 // Broadcasts to all "Waiters".
84 wxConditionInternal
*p_internal
;
87 // ---------------------------------------------------------------------------
88 // Thread management class
89 class wxThreadInternal
;
90 class WXDLLEXPORT wxThread
{
92 // constructor & destructor.
96 // Create a new thread, this method should check there is only one thread
98 wxThreadError
Create();
100 // Destroys the thread immediately if the defer flag isn't true.
101 wxThreadError
Destroy();
103 // Switches on the defer flag.
104 void DeferDestroy(bool on
);
106 // Waits for the termination of the thread.
109 // Sets the priority to "prio". (Warning: The priority can only be set before
110 // the thread is created)
111 void SetPriority(int prio
);
112 // Get the current priority.
113 int GetPriority() const;
116 unsigned long GetID() const;
118 // Returns true if the thread is alive.
119 bool IsAlive() const;
120 // Returns true if the thread is the main thread (aka the GUI thread).
121 static bool IsMain();
123 // Called when thread exits.
124 virtual void OnExit();
126 // In case, the DIFFER flag is true, enables another thread to kill this one.
128 // Exits from the current thread.
129 void Exit(void *status
= NULL
);
131 // Entry point for the thread.
132 virtual void *Entry() = 0;
135 friend class wxThreadInternal
;
137 wxThreadInternal
*p_internal
;
140 // ---------------------------------------------------------------------------
144 WXDLLEXPORT_DATA(extern wxMutex
) wxMainMutex
;