]>
Commit | Line | Data |
---|---|---|
7c351dad GL |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: thread.cpp | |
3 | // Purpose: No thread support | |
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 | #ifdef __GNUG__ | |
12 | #pragma implementation "thread.h" | |
13 | #endif | |
14 | ||
15 | #include "wx/wx.h" | |
c0392997 | 16 | #include "wx/module.h" |
8d31c138 | 17 | #include "wx/thread.h" |
7c351dad | 18 | |
ee4f8c2a | 19 | wxMutex::wxMutex() |
7c351dad | 20 | { |
b89156b5 | 21 | m_locked = 0; |
7c351dad GL |
22 | } |
23 | ||
ee4f8c2a | 24 | wxMutex::~wxMutex() |
7c351dad | 25 | { |
b89156b5 GL |
26 | if (m_locked) |
27 | wxDebugMsg("wxMutex warning: destroying a locked mutex (%d locks)\n", m_locked); | |
7c351dad GL |
28 | } |
29 | ||
c0392997 | 30 | wxMutexError wxMutex::Lock() |
7c351dad | 31 | { |
b89156b5 GL |
32 | m_locked++; |
33 | return MUTEX_NO_ERROR; | |
7c351dad GL |
34 | } |
35 | ||
c0392997 | 36 | wxMutexError wxMutex::TryLock() |
7c351dad | 37 | { |
b89156b5 GL |
38 | if (m_locked > 0) |
39 | return MUTEX_BUSY; | |
40 | m_locked++; | |
41 | return MUTEX_NO_ERROR; | |
7c351dad GL |
42 | } |
43 | ||
c0392997 | 44 | wxMutexError wxMutex::Unlock() |
7c351dad | 45 | { |
b89156b5 GL |
46 | if (m_locked == 0) |
47 | return MUTEX_UNLOCKED; | |
48 | m_locked--; | |
49 | return MUTEX_NO_ERROR; | |
7c351dad GL |
50 | } |
51 | ||
ee4f8c2a | 52 | wxCondition::wxCondition() |
7c351dad GL |
53 | { |
54 | } | |
55 | ||
ee4f8c2a | 56 | wxCondition::~wxCondition() |
7c351dad GL |
57 | { |
58 | } | |
59 | ||
60 | void wxCondition::Wait(wxMutex& WXUNUSED(mutex)) | |
61 | { | |
62 | } | |
63 | ||
64 | bool wxCondition::Wait(wxMutex& WXUNUSED(mutex), unsigned long WXUNUSED(sec), | |
65 | unsigned long WXUNUSED(nsec)) | |
66 | { | |
67 | return FALSE; | |
68 | } | |
69 | ||
ee4f8c2a | 70 | void wxCondition::Signal() |
7c351dad GL |
71 | { |
72 | } | |
73 | ||
ee4f8c2a | 74 | void wxCondition::Broadcast() |
7c351dad GL |
75 | { |
76 | } | |
77 | ||
c0392997 | 78 | struct wxThreadInternal { |
7c351dad GL |
79 | int thread_id; |
80 | void* exit_status; | |
81 | }; | |
82 | ||
c0392997 | 83 | wxThreadError wxThread::Create() |
7c351dad GL |
84 | { |
85 | p_internal->exit_status = Entry(); | |
86 | OnExit(); | |
b89156b5 | 87 | return THREAD_NO_ERROR; |
7c351dad GL |
88 | } |
89 | ||
c0392997 | 90 | wxThreadError wxThread::Destroy() |
7c351dad | 91 | { |
c2dd8380 GL |
92 | return THREAD_NOT_RUNNING; |
93 | } | |
94 | ||
95 | wxThreadError wxThread::Pause() | |
96 | { | |
97 | return THREAD_NOT_RUNNING; | |
98 | } | |
99 | ||
100 | wxThreadError wxThread::Resume() | |
101 | { | |
102 | return THREAD_NOT_RUNNING; | |
7c351dad GL |
103 | } |
104 | ||
c0392997 | 105 | void wxThread::DeferDestroy( bool WXUNUSED(on) ) |
7c351dad GL |
106 | { |
107 | } | |
108 | ||
ee4f8c2a | 109 | void wxThread::TestDestroy() |
7c351dad GL |
110 | { |
111 | } | |
112 | ||
113 | void *wxThread::Join() | |
114 | { | |
115 | return p_internal->exit_status; | |
116 | } | |
117 | ||
ee4f8c2a | 118 | unsigned long wxThread::GetID() const |
7c351dad GL |
119 | { |
120 | return 0; | |
121 | } | |
122 | ||
ee4f8c2a | 123 | bool wxThread::IsMain() |
7c351dad GL |
124 | { |
125 | return TRUE; | |
126 | } | |
127 | ||
c2dd8380 GL |
128 | bool wxThread::IsRunning() const |
129 | { | |
130 | return FALSE; | |
131 | } | |
132 | ||
ee4f8c2a | 133 | bool wxThread::IsAlive() const |
7c351dad GL |
134 | { |
135 | return FALSE; | |
136 | } | |
137 | ||
138 | void wxThread::SetPriority(int WXUNUSED(prio)) { } | |
c0392997 | 139 | int wxThread::GetPriority() const { return 0; } |
7c351dad | 140 | |
6773ae19 | 141 | wxMutex *wxMainMutex; // controls access to all GUI functions |
7c351dad GL |
142 | |
143 | wxThread::wxThread() | |
144 | { | |
c0392997 | 145 | p_internal = new wxThreadInternal(); |
7c351dad GL |
146 | } |
147 | ||
148 | wxThread::~wxThread() | |
149 | { | |
c0392997 | 150 | Destroy(); |
7c351dad GL |
151 | Join(); |
152 | delete p_internal; | |
153 | } | |
154 | ||
155 | // The default callback just joins the thread and throws away the result. | |
156 | void wxThread::OnExit() | |
157 | { | |
158 | Join(); | |
159 | } | |
160 | ||
b89156b5 GL |
161 | |
162 | // Automatic initialization | |
163 | class wxThreadModule : public wxModule { | |
164 | DECLARE_DYNAMIC_CLASS(wxThreadModule) | |
165 | public: | |
166 | bool OnInit(); | |
167 | void OnExit(); | |
168 | }; | |
169 | ||
170 | bool wxThreadModule::OnInit() { | |
6773ae19 GL |
171 | wxMainMutex = new wxMutex(); |
172 | wxMainMutex->Lock(); | |
b89156b5 | 173 | return TRUE; |
7c351dad GL |
174 | } |
175 | ||
c0392997 | 176 | void wxThreadModule::OnExit() |
7c351dad | 177 | { |
6773ae19 GL |
178 | wxMainMutex->Unlock(); |
179 | delete wxMainMutex; | |
7c351dad GL |
180 | } |
181 | ||
b89156b5 | 182 | IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule) |