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