* Corrected #include "thread.h" => #include "wx/thread.h"
[wxWidgets.git] / src / gtk1 / threadno.cpp
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/thread.h"
17
18 wxMutex::wxMutex()
19 {
20 m_locked = 0;
21 }
22
23 wxMutex::~wxMutex()
24 {
25 if (m_locked)
26 wxDebugMsg("wxMutex warning: destroying a locked mutex (%d locks)\n", m_locked);
27 }
28
29 MutexError wxMutex::Lock()
30 {
31 m_locked++;
32 return MUTEX_NO_ERROR;
33 }
34
35 MutexError wxMutex::TryLock()
36 {
37 if (m_locked > 0)
38 return MUTEX_BUSY;
39 m_locked++;
40 return MUTEX_NO_ERROR;
41 }
42
43 MutexError wxMutex::Unlock()
44 {
45 if (m_locked == 0)
46 return MUTEX_UNLOCKED;
47 m_locked--;
48 return MUTEX_NO_ERROR;
49 }
50
51 wxCondition::wxCondition()
52 {
53 }
54
55 wxCondition::~wxCondition()
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
69 void wxCondition::Signal()
70 {
71 }
72
73 void wxCondition::Broadcast()
74 {
75 }
76
77 struct wxThreadPrivate {
78 int thread_id;
79 void* exit_status;
80 };
81
82 ThreadError wxThread::Create()
83 {
84 p_internal->exit_status = Entry();
85 OnExit();
86 return THREAD_NO_ERROR;
87 }
88
89 ThreadError wxThread::Destroy()
90 {
91 return THREAD_RUNNING;
92 }
93
94 void wxThread::DeferDestroy()
95 {
96 }
97
98 void wxThread::TestDestroy()
99 {
100 }
101
102 void *wxThread::Join()
103 {
104 return p_internal->exit_status;
105 }
106
107 unsigned long wxThread::GetID() const
108 {
109 return 0;
110 }
111
112 bool wxThread::IsMain()
113 {
114 return TRUE;
115 }
116
117 bool wxThread::IsAlive() const
118 {
119 return FALSE;
120 }
121
122 void wxThread::SetPriority(int WXUNUSED(prio)) { }
123 int wxThread::GetPriority() const { }
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
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() {
155 wxMainMutex.Lock();
156 return TRUE;
157 }
158
159 void wxThreadModule::wxThreadExit()
160 {
161 wxMainMutex.Unlock();
162 }
163
164 IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)