]> git.saurik.com Git - wxWidgets.git/blob - src/stubs/thread.cpp
Some wxPython interface change updates. Moved refresh button. Platform
[wxWidgets.git] / src / stubs / 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 /////////////////////////////////////////////////////////////////////////////
28 // Static variables
29 /////////////////////////////////////////////////////////////////////////////
30
31 wxMutex *wxMainMutex; // controls access to all GUI functions
32
33 /////////////////////////////////////////////////////////////////////////////
34 // Windows implementation
35 /////////////////////////////////////////////////////////////////////////////
36
37 class wxMutexInternal {
38 public:
39 // TODO: internal mutex handle
40 };
41
42 wxMutex::wxMutex()
43 {
44 p_internal = new wxMutexInternal;
45 // TODO: create internal mutext handle
46 m_locked = 0;
47 }
48
49 wxMutex::~wxMutex()
50 {
51 if (m_locked > 0)
52 wxDebugMsg("wxMutex warning: freeing a locked mutex (%d locks)\n", m_locked);
53 // TODO: free internal mutext handle
54 }
55
56 wxMutexError wxMutex::Lock()
57 {
58 // TODO
59 m_locked++;
60 return wxMUTEX_NO_ERROR;
61 }
62
63 wxMutexError wxMutex::TryLock()
64 {
65 // TODO
66 m_locked++;
67 return wxMUTEX_NO_ERROR;
68 }
69
70 wxMutexError wxMutex::Unlock()
71 {
72 if (m_locked > 0)
73 m_locked--;
74
75 // TODO
76 return wxMUTEX_NO_ERROR;
77 }
78
79 class wxConditionInternal {
80 public:
81 // TODO: internal handle
82 int waiters;
83 };
84
85 wxCondition::wxCondition()
86 {
87 p_internal = new wxConditionInternal;
88 // TODO: create internal handle
89 p_internal->waiters = 0;
90 }
91
92 wxCondition::~wxCondition()
93 {
94 // TODO: destroy internal handle
95 }
96
97 void wxCondition::Wait(wxMutex& mutex)
98 {
99 mutex.Unlock();
100 p_internal->waiters++;
101 // TODO wait here
102 p_internal->waiters--;
103 mutex.Lock();
104 }
105
106 bool wxCondition::Wait(wxMutex& mutex, unsigned long sec,
107 unsigned long nsec)
108 {
109 mutex.Unlock();
110 p_internal->waiters++;
111
112 // TODO wait here
113 p_internal->waiters--;
114 mutex.Lock();
115
116 return FALSE;
117 }
118
119 void wxCondition::Signal()
120 {
121 // TODO
122 }
123
124 void wxCondition::Broadcast()
125 {
126 // TODO
127 }
128
129 class wxThreadInternal {
130 public:
131 // TODO
132 };
133
134 wxThreadError wxThread::Create()
135 {
136 // TODO
137 return wxTHREAD_NO_ERROR;
138 }
139
140 wxThreadError wxThread::Destroy()
141 {
142 // TODO
143 return wxTHREAD_NO_ERROR;
144 }
145
146 wxThreadError wxThread::Pause()
147 {
148 // TODO
149 return wxTHREAD_NO_ERROR;
150 }
151
152 wxThreadError wxThread::Resume()
153 {
154 // TODO
155 return wxTHREAD_NO_ERROR;
156 }
157
158 void wxThread::Exit(void *status)
159 {
160 // TODO
161 }
162
163 void wxThread::SetPriority(int prio)
164 {
165 // TODO
166 }
167
168 int wxThread::GetPriority() const
169 {
170 // TODO
171 return 0;
172 }
173
174 void wxThread::DeferDestroy(bool on)
175 {
176 // TODO
177 }
178
179 void wxThread::TestDestroy()
180 {
181 // TODO
182 }
183
184 void *wxThread::Join()
185 {
186 // TODO
187 return (void*) NULL;
188 }
189
190 unsigned long wxThread::GetID() const
191 {
192 // TODO
193 return 0;
194 }
195
196 /*
197 wxThread *wxThread::GetThreadFromID(unsigned long id)
198 {
199 // TODO
200 return NULL;
201 }
202 */
203
204 bool wxThread::IsAlive() const
205 {
206 // TODO
207 return FALSE;
208 }
209
210 bool wxThread::IsRunning() const
211 {
212 // TODO
213 return FALSE;
214 }
215
216 bool wxThread::IsMain()
217 {
218 // TODO
219 return FALSE;
220 }
221
222 wxThread::wxThread()
223 {
224 p_internal = new wxThreadInternal();
225
226 // TODO
227 }
228
229 wxThread::~wxThread()
230 {
231 Destroy();
232 Join();
233 delete p_internal;
234 }
235
236 // The default callback just joins the thread and throws away the result.
237 void wxThread::OnExit()
238 {
239 Join();
240 }
241
242 // Automatic initialization
243 class wxThreadModule : public wxModule {
244 DECLARE_DYNAMIC_CLASS(wxThreadModule)
245 public:
246 virtual bool OnInit() {
247 /* TODO p_mainid = GetCurrentThread(); */
248 wxMainMutex = new wxMutex();
249 wxMainMutex->Lock();
250 return TRUE;
251 }
252
253 // Global cleanup
254 virtual void OnExit() {
255 wxMainMutex->Unlock();
256 delete wxMainMutex;
257 }
258 };
259
260 IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
261