]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/thread.h
08e462a442c6fa362d6acebaee2fec67cf8e6c10
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
29 THREAD_NO_ERROR
=0, // No error
30 THREAD_NO_RESOURCE
, // No resource left to create a new thread
31 THREAD_RUNNING
, // The thread is already running
32 THREAD_NOT_RUNNING
// The thread isn't running
35 // defines the interval of priority.
36 #define WXTHREAD_MIN_PRIORITY 0
37 #define WXTHREAD_DEFAULT_PRIORITY 50
38 #define WXTHREAD_MAX_PRIORITY 100
40 // ---------------------------------------------------------------------------
42 class wxMutexInternal
;
43 class WXDLLEXPORT wxMutex
{
45 // constructor & destructor
51 // Try to lock the mutex: if it can't, returns immediately with an error.
52 wxMutexError
TryLock();
54 wxMutexError
Unlock();
56 // Returns true if the mutex is locked.
57 bool IsLocked() const { return (m_locked
> 0); }
59 friend class wxCondition
;
62 wxMutexInternal
*p_internal
;
65 // ---------------------------------------------------------------------------
67 class wxConditionInternal
;
68 class WXDLLEXPORT wxCondition
{
70 // constructor & destructor
74 // Waits indefinitely.
75 void Wait(wxMutex
& mutex
);
76 // Waits until a signal is raised or the timeout is elapsed.
77 bool Wait(wxMutex
& mutex
, unsigned long sec
, unsigned long nsec
);
78 // Raises a signal: only one "Waiter" is released.
80 // Broadcasts to all "Waiters".
83 wxConditionInternal
*p_internal
;
86 // ---------------------------------------------------------------------------
87 // Thread management class
88 class wxThreadInternal
;
89 class WXDLLEXPORT wxThread
{
91 // constructor & destructor.
95 // Create a new thread, this method should check there is only one thread
97 wxThreadError
Create();
99 // Destroys the thread immediately if the defer flag isn't true.
100 wxThreadError
Destroy();
102 // Switches on the defer flag.
103 void DeferDestroy(bool on
);
105 // Waits for the termination of the thread.
108 // Sets the priority to "prio". (Warning: The priority can only be set before
109 // the thread is created)
110 void SetPriority(int prio
);
111 // Get the current priority.
112 int GetPriority() const;
115 unsigned long GetID() const;
117 // Returns true if the thread is alive.
118 bool IsAlive() const;
119 // Returns true if the thread is the main thread (aka the GUI thread).
120 static bool IsMain();
122 // Called when thread exits.
123 virtual void OnExit();
125 // In case, the DIFFER flag is true, enables another thread to kill this one.
127 // Exits from the current thread.
128 void Exit(void *status
= NULL
);
130 // Entry point for the thread.
131 virtual void *Entry() = 0;
134 friend class wxThreadInternal
;
136 wxThreadInternal
*p_internal
;
139 // ---------------------------------------------------------------------------
143 WXDLLEXPORT_DATA(extern wxMutex
) wxMainMutex
;