]>
Commit | Line | Data |
---|---|---|
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" | |
16 | #include "wx/module.h" | |
17 | #include "wx/thread.h" | |
18 | ||
19 | wxMutex::wxMutex() | |
20 | { | |
21 | m_locked = 0; | |
22 | } | |
23 | ||
24 | wxMutex::~wxMutex() | |
25 | { | |
26 | if (m_locked) | |
27 | wxDebugMsg("wxMutex warning: destroying a locked mutex (%d locks)\n", m_locked); | |
28 | } | |
29 | ||
30 | wxMutexError wxMutex::Lock() | |
31 | { | |
32 | m_locked++; | |
33 | return MUTEX_NO_ERROR; | |
34 | } | |
35 | ||
36 | wxMutexError wxMutex::TryLock() | |
37 | { | |
38 | if (m_locked > 0) | |
39 | return MUTEX_BUSY; | |
40 | m_locked++; | |
41 | return MUTEX_NO_ERROR; | |
42 | } | |
43 | ||
44 | wxMutexError wxMutex::Unlock() | |
45 | { | |
46 | if (m_locked == 0) | |
47 | return MUTEX_UNLOCKED; | |
48 | m_locked--; | |
49 | return MUTEX_NO_ERROR; | |
50 | } | |
51 | ||
52 | wxCondition::wxCondition() | |
53 | { | |
54 | } | |
55 | ||
56 | wxCondition::~wxCondition() | |
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 | ||
70 | void wxCondition::Signal() | |
71 | { | |
72 | } | |
73 | ||
74 | void wxCondition::Broadcast() | |
75 | { | |
76 | } | |
77 | ||
78 | struct wxThreadInternal { | |
79 | int thread_id; | |
80 | void* exit_status; | |
81 | }; | |
82 | ||
83 | wxThreadError wxThread::Create() | |
84 | { | |
85 | p_internal->exit_status = Entry(); | |
86 | OnExit(); | |
87 | return THREAD_NO_ERROR; | |
88 | } | |
89 | ||
90 | wxThreadError wxThread::Destroy() | |
91 | { | |
92 | return THREAD_RUNNING; | |
93 | } | |
94 | ||
95 | void wxThread::DeferDestroy( bool WXUNUSED(on) ) | |
96 | { | |
97 | } | |
98 | ||
99 | void wxThread::TestDestroy() | |
100 | { | |
101 | } | |
102 | ||
103 | void *wxThread::Join() | |
104 | { | |
105 | return p_internal->exit_status; | |
106 | } | |
107 | ||
108 | unsigned long wxThread::GetID() const | |
109 | { | |
110 | return 0; | |
111 | } | |
112 | ||
113 | bool wxThread::IsMain() | |
114 | { | |
115 | return TRUE; | |
116 | } | |
117 | ||
118 | bool wxThread::IsAlive() const | |
119 | { | |
120 | return FALSE; | |
121 | } | |
122 | ||
123 | void wxThread::SetPriority(int WXUNUSED(prio)) { } | |
124 | int wxThread::GetPriority() const { return 0; } | |
125 | ||
126 | wxMutex wxMainMutex; // controls access to all GUI functions | |
127 | ||
128 | wxThread::wxThread() | |
129 | { | |
130 | p_internal = new wxThreadInternal(); | |
131 | } | |
132 | ||
133 | wxThread::~wxThread() | |
134 | { | |
135 | Destroy(); | |
136 | Join(); | |
137 | delete p_internal; | |
138 | } | |
139 | ||
140 | // The default callback just joins the thread and throws away the result. | |
141 | void wxThread::OnExit() | |
142 | { | |
143 | Join(); | |
144 | } | |
145 | ||
146 | ||
147 | // Automatic initialization | |
148 | class wxThreadModule : public wxModule { | |
149 | DECLARE_DYNAMIC_CLASS(wxThreadModule) | |
150 | public: | |
151 | bool OnInit(); | |
152 | void OnExit(); | |
153 | }; | |
154 | ||
155 | bool wxThreadModule::OnInit() { | |
156 | wxMainMutex.Lock(); | |
157 | return TRUE; | |
158 | } | |
159 | ||
160 | void wxThreadModule::OnExit() | |
161 | { | |
162 | wxMainMutex.Unlock(); | |
163 | } | |
164 | ||
165 | IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule) |