]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/threadsgi.cpp
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>
29 /////////////////////////////////////////////////////////////////////////////
31 /////////////////////////////////////////////////////////////////////////////
36 #include "threadgui.inc"
38 /////////////////////////////////////////////////////////////////////////////
39 // Unix implementations (SGI threads)
40 /////////////////////////////////////////////////////////////////////////////
42 class wxMutexInternal
{
50 p_internal
= new wxMutexInternal
;
51 init_lock(&(p_internal
->p_mutex
));
57 wxDebugMsg("wxMutex warning: freeing a locked mutex (%d locks)\n",
62 wxMutexError
wxMutex::Lock()
64 spin_lock(&(p_internal
->p_mutex
));
66 return MUTEX_NO_ERROR
;
69 wxMutexError
wxMutex::TryLock()
71 if (acquire_lock(&(p_internal
->p_mutex
)) != 0)
74 return MUTEX_NO_ERROR
;
77 wxMutexError
wxMutex::Unlock()
80 return MUTEX_UNLOCKED
;
81 release_lock(&(p_internal
->p_mutex
));
83 return MUTEX_NO_ERROR
;
86 // GL: Don't know how it works on SGI. Wolfram ?
88 wxCondition::wxCondition() {}
89 wxCondition::~wxCondition() {}
90 int wxCondition::Wait(wxMutex
& WXUNUSED(mutex
)) { return 0;}
91 int wxCondition::Wait(wxMutex
& WXUNUSED(mutex
), unsigned long WXUNUSED(sec
),
92 unsigned long WXUNUSED(nsec
)) { return 0; }
93 int wxCondition::Signal() { return 0; }
94 int wxCondition::Broadcast() { return 0; }
99 wxThreadPrivate() { thread_id
= 0; state
= STATE_IDLE
; }
100 ~wxThreadPrivate() {}
101 static void SprocStart(void *ptr
);
102 static void SignalHandler(int sig
);
104 int state
, thread_id
;
108 void wxThreadPrivate::SprocStart(void *ptr
)
112 wxThread
*thr
= (wxThread
*)ptr
;
114 thr
->p_internal
->thread_id
= getpid();
115 thr
->p_internal
->exit_status
= 0;
116 status
= thr
->Entry();
120 void wxThread::Exit(void* status
)
122 wxThread
* ptr
= this;
123 THREAD_SEND_EXIT_MSG(ptr
);
124 p_internal
->state
= STATE_EXITED
;
125 p_internal
->exit_status
= status
;
129 wxThreadError
wxThread::Create()
131 if (p_internal
->state
!= STATE_IDLE
)
132 return THREAD_RUNNING
;
133 p_internal
->state
= STATE_RUNNING
;
134 if (sproc(p_internal
->SprocStart
, PR_SALL
, this) < 0) {
135 p_internal
->state
= STATE_IDLE
;
136 return THREAD_NO_RESOURCE
;
138 return THREAD_NO_ERROR
;
141 void wxThread::Destroy()
143 if (p_internal
->state
== STATE_RUNNING
)
144 p_internal
->state
= STATE_CANCELED
;
147 void *wxThread::Join()
149 if (p_internal
->state
!= STATE_IDLE
) {
150 bool do_unlock
= wxThread::IsMain();
154 wxMainMutex
.Unlock();
155 waitpid(p_internal
->thread_id
, &stat
, 0);
158 if (!WIFEXITED(stat
) && !WIFSIGNALED(stat
))
160 p_internal
->state
= STATE_IDLE
;
161 return p_internal
->exit_status
;
166 unsigned long wxThread::GetID() const
168 return (unsigned long)p_internal
->thread_id
;
171 void wxThread::TestDestroy()
173 if (p_internal
->state
== STATE_CANCELED
) {
174 p_internal
->exit_status
= 0;
179 void wxThread::SetPriority(int prio
)
183 int wxThread::GetPriority() const
188 bool wxThreadIsMain()
190 return (int)getpid() == main_id
;
195 p_internal
= new wxThreadPrivate();
198 wxThread::~wxThread()
205 // The default callback just joins the thread and throws away the result.
206 void wxThread::OnExit()
211 // Global initialization
212 class wxThreadModule
: public wxModule
{
213 DECLARE_DYNAMIC_CLASS(wxThreadModule
)
215 virtual bool OnInit() {
217 p_mainid
= (int)getpid();
221 virtual void OnExit() {
222 wxMainMutex
.Unlock();
227 IMPLEMENT_DYNAMIC_CLASS(wxThreadModule
, wxModule
)