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