]> git.saurik.com Git - wxWidgets.git/blob - src/mac/thread.cpp
latest CW additions
[wxWidgets.git] / src / mac / thread.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: thread.cpp
3 // Purpose: wxThread Implementation. For Unix ports, see e.g. src/gtk
4 // Author: Original from Wolfram Gloger/Guilhem Lavaux
5 // Modified by:
6 // Created: 04/22/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Wolfram Gloger (1996, 1997); Guilhem Lavaux (1998)
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "thread.h"
14 #endif
15
16 #include "wx/module.h"
17 #include "wx/thread.h"
18 #include "wx/utils.h"
19
20 enum thread_state {
21 STATE_IDLE = 0,
22 STATE_RUNNING,
23 STATE_CANCELED,
24 STATE_EXITED
25 };
26
27 #if wxUSE_THREADS
28
29 /////////////////////////////////////////////////////////////////////////////
30 // Static variables
31 /////////////////////////////////////////////////////////////////////////////
32
33 wxMutex *wxMainMutex; // controls access to all GUI functions
34
35 /////////////////////////////////////////////////////////////////////////////
36 // Windows implementation
37 /////////////////////////////////////////////////////////////////////////////
38
39 class wxMutexInternal {
40 public:
41 // TODO: internal mutex handle
42 };
43
44 wxMutex::wxMutex()
45 {
46 p_internal = new wxMutexInternal;
47 // TODO: create internal mutext handle
48 m_locked = 0;
49 }
50
51 wxMutex::~wxMutex()
52 {
53 if (m_locked > 0)
54 wxDebugMsg("wxMutex warning: freeing a locked mutex (%d locks)\n", m_locked);
55 // TODO: free internal mutext handle
56 }
57
58 wxMutexError wxMutex::Lock()
59 {
60 // TODO
61 m_locked++;
62 return wxMUTEX_NO_ERROR;
63 }
64
65 wxMutexError wxMutex::TryLock()
66 {
67 // TODO
68 m_locked++;
69 return wxMUTEX_NO_ERROR;
70 }
71
72 wxMutexError wxMutex::Unlock()
73 {
74 if (m_locked > 0)
75 m_locked--;
76
77 // TODO
78 return wxMUTEX_NO_ERROR;
79 }
80
81 class wxConditionInternal {
82 public:
83 // TODO: internal handle
84 int waiters;
85 };
86
87 wxCondition::wxCondition()
88 {
89 p_internal = new wxConditionInternal;
90 // TODO: create internal handle
91 p_internal->waiters = 0;
92 }
93
94 wxCondition::~wxCondition()
95 {
96 // TODO: destroy internal handle
97 }
98
99 void wxCondition::Wait(wxMutex& mutex)
100 {
101 mutex.Unlock();
102 p_internal->waiters++;
103 // TODO wait here
104 p_internal->waiters--;
105 mutex.Lock();
106 }
107
108 bool wxCondition::Wait(wxMutex& mutex, unsigned long sec,
109 unsigned long nsec)
110 {
111 mutex.Unlock();
112 p_internal->waiters++;
113
114 // TODO wait here
115 p_internal->waiters--;
116 mutex.Lock();
117
118 return FALSE;
119 }
120
121 void wxCondition::Signal()
122 {
123 // TODO
124 }
125
126 void wxCondition::Broadcast()
127 {
128 // TODO
129 }
130
131 class wxThreadInternal {
132 public:
133 // TODO
134 };
135
136 wxThreadError wxThread::Create()
137 {
138 // TODO
139 return wxTHREAD_NO_ERROR;
140 }
141
142 wxThreadError wxThread::Destroy()
143 {
144 // TODO
145 return wxTHREAD_NO_ERROR;
146 }
147
148 wxThreadError wxThread::Pause()
149 {
150 // TODO
151 return wxTHREAD_NO_ERROR;
152 }
153
154 wxThreadError wxThread::Resume()
155 {
156 // TODO
157 return wxTHREAD_NO_ERROR;
158 }
159
160 void wxThread::Exit(void *status)
161 {
162 // TODO
163 }
164
165 void wxThread::SetPriority(int prio)
166 {
167 // TODO
168 }
169
170 int wxThread::GetPriority() const
171 {
172 // TODO
173 return 0;
174 }
175
176 void wxThread::DeferDestroy(bool on)
177 {
178 // TODO
179 }
180
181 void wxThread::TestDestroy()
182 {
183 // TODO
184 }
185
186 void *wxThread::Join()
187 {
188 // TODO
189 return (void*) NULL;
190 }
191
192 unsigned long wxThread::GetID() const
193 {
194 // TODO
195 return 0;
196 }
197
198 /* is this needed somewhere ?
199 wxThread *wxThread::GetThreadFromID(unsigned long id)
200 {
201 // TODO
202 return NULL;
203 }
204 */
205
206 bool wxThread::IsAlive() const
207 {
208 // TODO
209 return FALSE;
210 }
211
212 bool wxThread::IsRunning() const
213 {
214 // TODO
215 return FALSE;
216 }
217
218 bool wxThread::IsMain()
219 {
220 // TODO
221 return FALSE;
222 }
223
224 wxThread::wxThread()
225 {
226 p_internal = new wxThreadInternal();
227
228 // TODO
229 }
230
231 wxThread::~wxThread()
232 {
233 Destroy();
234 Join();
235 delete p_internal;
236 }
237
238 // The default callback just joins the thread and throws away the result.
239 void wxThread::OnExit()
240 {
241 Join();
242 }
243
244 // Automatic initialization
245 class wxThreadModule : public wxModule {
246 DECLARE_DYNAMIC_CLASS(wxThreadModule)
247 public:
248 virtual bool OnInit() {
249 /* TODO p_mainid = GetCurrentThread(); */
250 wxMainMutex = new wxMutex();
251 wxMainMutex->Lock();
252 return TRUE;
253 }
254
255 // Global cleanup
256 virtual void OnExit() {
257 wxMainMutex->Unlock();
258 delete wxMainMutex;
259 }
260 };
261
262 IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
263
264 #endif