]> git.saurik.com Git - wxWidgets.git/blame - src/stubs/thread.cpp
DP: Robert's mistake with incorrect var name corrected.
[wxWidgets.git] / src / stubs / thread.cpp
CommitLineData
93cf77c0
JS
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
19enum thread_state {
20 STATE_IDLE = 0,
21 STATE_RUNNING,
22 STATE_CANCELED,
23 STATE_EXITED
24};
25
26/////////////////////////////////////////////////////////////////////////////
27// Static variables
28/////////////////////////////////////////////////////////////////////////////
29
30wxMutex wxMainMutex; // controls access to all GUI functions
31
32/////////////////////////////////////////////////////////////////////////////
33// Windows implementation
34/////////////////////////////////////////////////////////////////////////////
35
36class wxMutexInternal {
37public:
38 // TODO: internal mutex handle
39};
40
41wxMutex::wxMutex()
42{
43 p_internal = new wxMutexInternal;
44 // TODO: create internal mutext handle
45 m_locked = 0;
46}
47
48wxMutex::~wxMutex()
49{
50 if (m_locked > 0)
51 wxDebugMsg("wxMutex warning: freeing a locked mutex (%d locks)\n", m_locked);
52 // TODO: free internal mutext handle
53}
54
55wxMutexError wxMutex::Lock()
56{
57 // TODO
58 m_locked++;
59 return MUTEX_NO_ERROR;
60}
61
62wxMutexError wxMutex::TryLock()
63{
64 // TODO
65 m_locked++;
66 return MUTEX_NO_ERROR;
67}
68
69wxMutexError wxMutex::Unlock()
70{
71 if (m_locked > 0)
72 m_locked--;
73
74 // TODO
75 return MUTEX_NO_ERROR;
76}
77
78class wxConditionInternal {
79public:
80 // TODO: internal handle
81 int waiters;
82};
83
84wxCondition::wxCondition()
85{
86 p_internal = new wxConditionInternal;
87 // TODO: create internal handle
88 p_internal->waiters = 0;
89}
90
91wxCondition::~wxCondition()
92{
93 // TODO: destroy internal handle
94}
95
96void wxCondition::Wait(wxMutex& mutex)
97{
98 mutex.Unlock();
99 p_internal->waiters++;
100 // TODO wait here
101 p_internal->waiters--;
102 mutex.Lock();
103}
104
105bool wxCondition::Wait(wxMutex& mutex, unsigned long sec,
106 unsigned long nsec)
107{
108 mutex.Unlock();
109 p_internal->waiters++;
110
111 // TODO wait here
112 p_internal->waiters--;
113 mutex.Lock();
114
115 return FALSE;
116}
117
118void wxCondition::Signal()
119{
120 // TODO
121}
122
123void wxCondition::Broadcast()
124{
125 // TODO
126}
127
128class wxThreadInternal {
129public:
130 // TODO
131};
132
133wxThreadError wxThread::Create()
134{
135 // TODO
136 return THREAD_NO_ERROR;
137}
138
139wxThreadError wxThread::Destroy()
140{
141 // TODO
142 return THREAD_NO_ERROR;
143}
144
145void wxThread::Exit(void *status)
146{
147 // TODO
148}
149
150void wxThread::SetPriority(int prio)
151{
152 // TODO
153}
154
155int wxThread::GetPriority() const
156{
157 // TODO
158 return 0;
159}
160
161void wxThread::DeferDestroy(bool on)
162{
163 // TODO
164}
165
166void wxThread::TestDestroy()
167{
168 // TODO
169}
170
171void *wxThread::Join()
172{
173 // TODO
174 return (void*) NULL;
175}
176
177unsigned long wxThread::GetID() const
178{
179 // TODO
180 return 0;
181}
182
183bool wxThread::IsMain()
184{
185 // TODO
186}
187
188wxThread::wxThread()
189{
190 p_internal = new wxThreadInternal();
191
192 // TODO
193}
194
195wxThread::~wxThread()
196{
197 Destroy();
198 Join();
199 delete p_internal;
200}
201
202// The default callback just joins the thread and throws away the result.
203void wxThread::OnExit()
204{
205 Join();
206}
207
208// Automatic initialization
209class wxThreadModule : public wxModule {
210 DECLARE_DYNAMIC_CLASS(wxThreadModule)
211public:
212 virtual bool OnInit() {
213 /* TODO p_mainid = GetCurrentThread(); */
214 wxMainMutex.Lock();
215 return TRUE;
216 }
217
218 // Global cleanup
219 virtual void OnExit() {
220 wxMainMutex.Unlock();
221 }
222};
223
224IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
225