]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/motif/thread.cpp
Dialog unit mods; wxProp tidying
[wxWidgets.git] / src / motif / thread.cpp
... / ...
CommitLineData
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
20enum thread_state {
21 STATE_IDLE = 0,
22 STATE_RUNNING,
23 STATE_CANCELED,
24 STATE_EXITED
25};
26
27/////////////////////////////////////////////////////////////////////////////
28// Static variables
29/////////////////////////////////////////////////////////////////////////////
30
31wxMutex wxMainMutex; // controls access to all GUI functions
32
33/////////////////////////////////////////////////////////////////////////////
34// Windows implementation
35/////////////////////////////////////////////////////////////////////////////
36
37class wxMutexInternal {
38public:
39 // TODO: internal mutex handle
40};
41
42wxMutex::wxMutex()
43{
44 p_internal = new wxMutexInternal;
45 // TODO: create internal mutext handle
46 m_locked = 0;
47}
48
49wxMutex::~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
56wxMutexError wxMutex::Lock()
57{
58 // TODO
59 m_locked++;
60 return MUTEX_NO_ERROR;
61}
62
63wxMutexError wxMutex::TryLock()
64{
65 // TODO
66 m_locked++;
67 return MUTEX_NO_ERROR;
68}
69
70wxMutexError wxMutex::Unlock()
71{
72 if (m_locked > 0)
73 m_locked--;
74
75 // TODO
76 return MUTEX_NO_ERROR;
77}
78
79class wxConditionInternal {
80public:
81 // TODO: internal handle
82 int waiters;
83};
84
85wxCondition::wxCondition()
86{
87 p_internal = new wxConditionInternal;
88 // TODO: create internal handle
89 p_internal->waiters = 0;
90}
91
92wxCondition::~wxCondition()
93{
94 // TODO: destroy internal handle
95}
96
97void 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
106bool 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
119void wxCondition::Signal()
120{
121 // TODO
122}
123
124void wxCondition::Broadcast()
125{
126 // TODO
127}
128
129class wxThreadInternal {
130public:
131 // TODO
132};
133
134wxThreadError wxThread::Create()
135{
136 // TODO
137 return THREAD_NO_ERROR;
138}
139
140wxThreadError wxThread::Destroy()
141{
142 // TODO
143 return THREAD_NO_ERROR;
144}
145
146wxThreadError wxThread::Pause()
147{
148 // TODO
149 return THREAD_NO_ERROR;
150}
151
152wxThreadError wxThread::Resume()
153{
154 // TODO
155 return THREAD_NO_ERROR;
156}
157
158void wxThread::Exit(void *status)
159{
160 // TODO
161}
162
163void wxThread::SetPriority(int prio)
164{
165 // TODO
166}
167
168int wxThread::GetPriority() const
169{
170 // TODO
171 return 0;
172}
173
174void wxThread::DeferDestroy(bool on)
175{
176 // TODO
177}
178
179void wxThread::TestDestroy()
180{
181 // TODO
182}
183
184void *wxThread::Join()
185{
186 // TODO
187 return (void*) NULL;
188}
189
190unsigned long wxThread::GetID() const
191{
192 // TODO
193 return 0;
194}
195
196wxThread *wxThread::GetThreadFromID(unsigned long id)
197{
198 // TODO
199 return NULL;
200}
201
202bool wxThread::IsAlive() const
203{
204 // TODO
205 return FALSE;
206}
207
208bool wxThread::IsRunning() const
209{
210 // TODO
211 return FALSE;
212}
213
214bool wxThread::IsMain()
215{
216 // TODO
217 return FALSE;
218}
219
220wxThread::wxThread()
221{
222 p_internal = new wxThreadInternal();
223
224 // TODO
225}
226
227wxThread::~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.
235void wxThread::OnExit()
236{
237 Join();
238}
239
240// Automatic initialization
241class wxThreadModule : public wxModule {
242 DECLARE_DYNAMIC_CLASS(wxThreadModule)
243public:
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
256IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
257