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