]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/threadsgi.cpp
8dcac3700054fd1dce12db8124643fd361053c98
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxThread (SGI) Implementation
4 // Author: Original from Wolfram Gloger/Guilhem Lavaux
8 // Copyright: (c) Wolfram Gloger (1996, 1997); Guilhem Lavaux (1998)
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "thread.h"
20 #include <sys/prctl.h>
21 #include "wx/thread.h"
22 #include "wx/module.h"
33 /////////////////////////////////////////////////////////////////////////////
35 /////////////////////////////////////////////////////////////////////////////
40 #include "threadgui.inc"
42 /////////////////////////////////////////////////////////////////////////////
43 // Unix implementations (SGI threads)
44 /////////////////////////////////////////////////////////////////////////////
46 class wxMutexInternal
{
54 p_internal
= new wxMutexInternal
;
55 init_lock(&(p_internal
->p_mutex
));
61 wxLogDebug( "wxMutex warning: freeing a locked mutex (%d locks)\n", m_locked
);
65 wxMutexError
wxMutex::Lock()
67 spin_lock(&(p_internal
->p_mutex
));
69 return wxMUTEX_NO_ERROR
;
72 wxMutexError
wxMutex::TryLock()
74 if (acquire_lock(&(p_internal
->p_mutex
)) != 0)
77 return wxMUTEX_NO_ERROR
;
80 wxMutexError
wxMutex::Unlock()
83 return wxMUTEX_UNLOCKED
;
84 release_lock(&(p_internal
->p_mutex
));
86 return wxMUTEX_NO_ERROR
;
89 // GL: Don't know how it works on SGI. Wolfram ?
91 wxCondition::wxCondition() {}
92 wxCondition::~wxCondition() {}
93 int wxCondition::Wait(wxMutex
& WXUNUSED(mutex
)) { return 0;}
94 int wxCondition::Wait(wxMutex
& WXUNUSED(mutex
), unsigned long WXUNUSED(sec
),
95 unsigned long WXUNUSED(nsec
)) { return 0; }
96 int wxCondition::Signal() { return 0; }
97 int wxCondition::Broadcast() { return 0; }
102 wxThreadPrivate() { thread_id
= 0; state
= STATE_IDLE
; }
103 ~wxThreadPrivate() {}
104 static void SprocStart(void *ptr
);
105 static void SignalHandler(int sig
);
107 int state
, thread_id
;
111 void wxThreadPrivate::SprocStart(void *ptr
)
115 wxThread
*thr
= (wxThread
*)ptr
;
117 thr
->p_internal
->thread_id
= getpid();
118 thr
->p_internal
->exit_status
= 0;
119 status
= thr
->Entry();
123 void wxThread::Exit(void* status
)
125 wxThread
* ptr
= this;
126 THREAD_SEND_EXIT_MSG(ptr
);
127 p_internal
->state
= STATE_EXITED
;
128 p_internal
->exit_status
= status
;
132 wxThreadError
wxThread::Create()
134 if (p_internal
->state
!= STATE_IDLE
)
135 return wxTHREAD_RUNNING
;
136 p_internal
->state
= STATE_RUNNING
;
137 if (sproc(p_internal
->SprocStart
, PR_SALL
, this) < 0) {
138 p_internal
->state
= STATE_IDLE
;
139 return wxTHREAD_NO_RESOURCE
;
141 return wxTHREAD_NO_ERROR
;
144 wxThreadError
wxThread::Destroy()
146 if (p_internal
->state
== STATE_RUNNING
)
147 p_internal
->state
= STATE_CANCELED
;
149 return wxTHREAD_NO_ERROR
;
152 wxThreadError
wxThread::Pause()
154 return wxTHREAD_NO_ERROR
;
157 wxThreadError
wxThread::Resume()
159 return wxTHREAD_NO_ERROR
;
162 void *wxThread::Join()
164 if (p_internal
->state
!= STATE_IDLE
) {
165 bool do_unlock
= wxThread::IsMain();
169 wxMainMutex
->Unlock();
170 waitpid(p_internal
->thread_id
, &stat
, 0);
173 if (!WIFEXITED(stat
) && !WIFSIGNALED(stat
))
175 p_internal
->state
= STATE_IDLE
;
176 return p_internal
->exit_status
;
181 unsigned long wxThread::GetID() const
183 return (unsigned long)p_internal
->thread_id
;
186 void wxThread::TestDestroy()
188 if (p_internal
->state
== STATE_CANCELED
) {
189 p_internal
->exit_status
= 0;
194 void wxThread::SetPriority(int prio
)
198 int wxThread::GetPriority() const
203 bool wxThread::IsMain()
205 return (int)getpid() == main_id
;
208 bool wxThread::IsAlive() const
210 return (p_internal
->state
== STATE_RUNNING
);
213 bool wxThread::IsRunning() const
215 return (p_internal
->state
== STATE_RUNNING
);
220 p_internal
= new wxThreadPrivate();
223 wxThread::~wxThread()
230 // The default callback just joins the thread and throws away the result.
231 void wxThread::OnExit()
236 // Global initialization
237 class wxThreadModule
: public wxModule
{
238 DECLARE_DYNAMIC_CLASS(wxThreadModule
)
240 virtual bool OnInit() {
241 wxMainMutex
= new wxMutex();
243 p_mainid
= (int)getpid();
247 virtual void OnExit() {
248 wxMainMutex
->Unlock();
254 IMPLEMENT_DYNAMIC_CLASS(wxThreadModule
, wxModule
)