]> git.saurik.com Git - wxWidgets.git/blob - src/stubs/thread.cpp
Changed wxMenu::GetTitle to return a wxString.
[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 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 void wxThread::Exit(void *status)
147 {
148 // TODO
149 }
150
151 void wxThread::SetPriority(int prio)
152 {
153 // TODO
154 }
155
156 int wxThread::GetPriority() const
157 {
158 // TODO
159 return 0;
160 }
161
162 void wxThread::DeferDestroy(bool on)
163 {
164 // TODO
165 }
166
167 void wxThread::TestDestroy()
168 {
169 // TODO
170 }
171
172 void *wxThread::Join()
173 {
174 // TODO
175 return (void*) NULL;
176 }
177
178 unsigned long wxThread::GetID() const
179 {
180 // TODO
181 return 0;
182 }
183
184 bool wxThread::IsMain()
185 {
186 // TODO
187 return FALSE;
188 }
189
190 wxThread::wxThread()
191 {
192 p_internal = new wxThreadInternal();
193
194 // TODO
195 }
196
197 wxThread::~wxThread()
198 {
199 Destroy();
200 Join();
201 delete p_internal;
202 }
203
204 // The default callback just joins the thread and throws away the result.
205 void wxThread::OnExit()
206 {
207 Join();
208 }
209
210 // Automatic initialization
211 class wxThreadModule : public wxModule {
212 DECLARE_DYNAMIC_CLASS(wxThreadModule)
213 public:
214 virtual bool OnInit() {
215 /* TODO p_mainid = GetCurrentThread(); */
216 wxMainMutex.Lock();
217 return TRUE;
218 }
219
220 // Global cleanup
221 virtual void OnExit() {
222 wxMainMutex.Unlock();
223 }
224 };
225
226 IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
227