]>
Commit | Line | Data |
---|---|---|
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 MUTEX_NO_ERROR; | |
61 | } | |
62 | ||
63 | wxMutexError wxMutex::TryLock() | |
64 | { | |
65 | // TODO | |
66 | m_locked++; | |
67 | return MUTEX_NO_ERROR; | |
68 | } | |
69 | ||
70 | wxMutexError wxMutex::Unlock() | |
71 | { | |
72 | if (m_locked > 0) | |
73 | m_locked--; | |
74 | ||
75 | // TODO | |
76 | return MUTEX_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 THREAD_NO_ERROR; | |
138 | } | |
139 | ||
140 | wxThreadError wxThread::Destroy() | |
141 | { | |
142 | // TODO | |
143 | return THREAD_NO_ERROR; | |
144 | } | |
145 | ||
146 | wxThreadError wxThread::Pause() | |
147 | { | |
148 | // TODO | |
149 | return THREAD_NO_ERROR; | |
150 | } | |
151 | ||
152 | wxThreadError wxThread::Resume() | |
153 | { | |
154 | // TODO | |
155 | return THREAD_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 | wxThread *wxThread::GetThreadFromID(unsigned long id) | |
197 | { | |
198 | // TODO | |
199 | return NULL; | |
200 | } | |
201 | ||
202 | bool wxThread::IsAlive() const | |
203 | { | |
204 | // TODO | |
205 | return FALSE; | |
206 | } | |
207 | ||
208 | bool wxThread::IsRunning() const | |
209 | { | |
210 | // TODO | |
211 | return FALSE; | |
212 | } | |
213 | ||
214 | bool wxThread::IsMain() | |
215 | { | |
216 | // TODO | |
217 | return FALSE; | |
218 | } | |
219 | ||
220 | wxThread::wxThread() | |
221 | { | |
222 | p_internal = new wxThreadInternal(); | |
223 | ||
224 | // TODO | |
225 | } | |
226 | ||
227 | wxThread::~wxThread() | |
228 | { | |
229 | Destroy(); | |
230 | Join(); | |
231 | delete p_internal; | |
232 | } | |
233 | ||
234 | // The default callback just joins the thread and throws away the result. | |
235 | void wxThread::OnExit() | |
236 | { | |
237 | Join(); | |
238 | } | |
239 | ||
240 | // Automatic initialization | |
241 | class wxThreadModule : public wxModule { | |
242 | DECLARE_DYNAMIC_CLASS(wxThreadModule) | |
243 | public: | |
244 | virtual bool OnInit() { | |
245 | /* TODO p_mainid = GetCurrentThread(); */ | |
246 | wxMainMutex.Lock(); | |
247 | return TRUE; | |
248 | } | |
249 | ||
250 | // Global cleanup | |
251 | virtual void OnExit() { | |
252 | wxMainMutex.Unlock(); | |
253 | } | |
254 | }; | |
255 | ||
256 | IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule) | |
257 |