]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/threadsgi.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/threadsgi.cpp
3 // Purpose: wxThread (SGI) Implementation
4 // Author: Original from Wolfram Gloger/Guilhem Lavaux
7 // Copyright: (c) Wolfram Gloger (1996, 1997); Guilhem Lavaux (1998)
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
14 #include "wx/thread.h"
19 #include "wx/module.h"
27 #include <sys/prctl.h>
40 /////////////////////////////////////////////////////////////////////////////
42 /////////////////////////////////////////////////////////////////////////////
47 #include "threadgui.inc"
49 /////////////////////////////////////////////////////////////////////////////
50 // Unix implementations (SGI threads)
51 /////////////////////////////////////////////////////////////////////////////
53 class wxMutexInternal
{
61 p_internal
= new wxMutexInternal
;
62 init_lock(&(p_internal
->p_mutex
));
69 wxLogDebug( "wxMutex warning: freeing a locked mutex (%d locks)\n", m_locked
);
74 wxMutexError
wxMutex::Lock()
76 spin_lock(&(p_internal
->p_mutex
));
78 return wxMUTEX_NO_ERROR
;
81 wxMutexError
wxMutex::TryLock()
83 if (acquire_lock(&(p_internal
->p_mutex
)) != 0)
86 return wxMUTEX_NO_ERROR
;
89 wxMutexError
wxMutex::Unlock()
92 return wxMUTEX_UNLOCKED
;
93 release_lock(&(p_internal
->p_mutex
));
95 return wxMUTEX_NO_ERROR
;
98 // GL: Don't know how it works on SGI. Wolfram ?
100 wxCondition::wxCondition() {}
101 wxCondition::~wxCondition() {}
102 int wxCondition::Wait(wxMutex
& WXUNUSED(mutex
)) { return 0;}
103 int wxCondition::Wait(wxMutex
& WXUNUSED(mutex
), unsigned long WXUNUSED(sec
),
104 unsigned long WXUNUSED(nsec
)) { return 0; }
105 int wxCondition::Signal() { return 0; }
106 int wxCondition::Broadcast() { return 0; }
111 wxThreadPrivate() { thread_id
= 0; state
= STATE_IDLE
; }
112 ~wxThreadPrivate() {}
113 static void SprocStart(void *ptr
);
114 static void SignalHandler(int sig
);
116 int state
, thread_id
;
120 void wxThreadPrivate::SprocStart(void *ptr
)
124 wxThread
*thr
= (wxThread
*)ptr
;
126 thr
->p_internal
->thread_id
= getpid();
127 thr
->p_internal
->exit_status
= 0;
128 status
= thr
->CallEntry();
132 void wxThread::Exit(void* status
)
134 wxThread
* ptr
= this;
135 THREAD_SEND_EXIT_MSG(ptr
);
136 p_internal
->state
= STATE_EXITED
;
137 p_internal
->exit_status
= status
;
141 wxThreadError
wxThread::Create()
143 if (p_internal
->state
!= STATE_IDLE
)
144 return wxTHREAD_RUNNING
;
145 p_internal
->state
= STATE_RUNNING
;
146 if (sproc(p_internal
->SprocStart
, PR_SALL
, this) < 0) {
147 p_internal
->state
= STATE_IDLE
;
148 return wxTHREAD_NO_RESOURCE
;
150 return wxTHREAD_NO_ERROR
;
153 wxThreadError
wxThread::Destroy()
155 if (p_internal
->state
== STATE_RUNNING
)
156 p_internal
->state
= STATE_CANCELED
;
158 return wxTHREAD_NO_ERROR
;
161 wxThreadError
wxThread::Pause()
163 return wxTHREAD_NO_ERROR
;
166 wxThreadError
wxThread::Resume()
168 return wxTHREAD_NO_ERROR
;
171 void *wxThread::Join()
173 if (p_internal
->state
!= STATE_IDLE
) {
174 bool do_unlock
= wxThread::IsMain();
178 wxMainMutex
->Unlock();
179 waitpid(p_internal
->thread_id
, &stat
, 0);
182 if (!WIFEXITED(stat
) && !WIFSIGNALED(stat
))
184 p_internal
->state
= STATE_IDLE
;
185 return p_internal
->exit_status
;
190 unsigned long wxThread::GetID() const
192 return (unsigned long)p_internal
->thread_id
;
195 void wxThread::TestDestroy()
197 if (p_internal
->state
== STATE_CANCELED
) {
198 p_internal
->exit_status
= 0;
203 void wxThread::SetPriority(int prio
)
207 int wxThread::GetPriority() const
212 bool wxThread::IsMain()
214 return (int)getpid() == main_id
;
217 bool wxThread::IsAlive() const
219 return (p_internal
->state
== STATE_RUNNING
);
222 bool wxThread::IsRunning() const
224 return (p_internal
->state
== STATE_RUNNING
);
229 p_internal
= new wxThreadPrivate();
232 wxThread::~wxThread()
239 // The default callback just joins the thread and throws away the result.
240 void wxThread::OnExit()
245 // Global initialization
247 class wxThreadModule
: public wxModule
250 virtual bool OnInit();
251 virtual void OnExit();
254 DECLARE_DYNAMIC_CLASS(wxThreadModule
)
257 IMPLEMENT_DYNAMIC_CLASS(wxThreadModule
, wxModule
)
259 bool wxThreadModule::OnInit()
261 wxMainMutex
= new wxMutex();
263 p_mainid
= (int)getpid();
268 void wxThreadModule::OnExit()
270 wxMainMutex
->Unlock();