]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/threadsgi.cpp
10945b3900324398e99ca6e460f08017a486c4d5
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 /////////////////////////////////////////////////////////////////////////////
33 #include "wx/thread.h"
38 #include "threadgui.inc"
40 /////////////////////////////////////////////////////////////////////////////
41 // Unix implementations (SGI threads)
42 /////////////////////////////////////////////////////////////////////////////
44 class wxMutexInternal
{
52 p_internal
= new wxMutexInternal
;
53 init_lock(&(p_internal
->p_mutex
));
59 wxDebugMsg("wxMutex warning: freeing a locked mutex (%d locks)\n",
64 wxMutexError
wxMutex::Lock()
66 spin_lock(&(p_internal
->p_mutex
));
68 return MUTEX_NO_ERROR
;
71 wxMutexError
wxMutex::TryLock()
73 if (acquire_lock(&(p_internal
->p_mutex
)) != 0)
76 return MUTEX_NO_ERROR
;
79 wxMutexError
wxMutex::Unlock()
82 return MUTEX_UNLOCKED
;
83 release_lock(&(p_internal
->p_mutex
));
85 return MUTEX_NO_ERROR
;
88 // GL: Don't know how it works on SGI. Wolfram ?
90 wxCondition::wxCondition() {}
91 wxCondition::~wxCondition() {}
92 int wxCondition::Wait(wxMutex
& WXUNUSED(mutex
)) { return 0;}
93 int wxCondition::Wait(wxMutex
& WXUNUSED(mutex
), unsigned long WXUNUSED(sec
),
94 unsigned long WXUNUSED(nsec
)) { return 0; }
95 int wxCondition::Signal() { return 0; }
96 int wxCondition::Broadcast() { return 0; }
101 wxThreadPrivate() { thread_id
= 0; state
= STATE_IDLE
; }
102 ~wxThreadPrivate() {}
103 static void SprocStart(void *ptr
);
104 static void SignalHandler(int sig
);
106 int state
, thread_id
;
110 void wxThreadPrivate::SprocStart(void *ptr
)
114 wxThread
*thr
= (wxThread
*)ptr
;
116 thr
->p_internal
->thread_id
= getpid();
117 thr
->p_internal
->exit_status
= 0;
118 status
= thr
->Entry();
122 void wxThread::Exit(void* status
)
124 wxThread
* ptr
= this;
125 THREAD_SEND_EXIT_MSG(ptr
);
126 p_internal
->state
= STATE_EXITED
;
127 p_internal
->exit_status
= status
;
131 wxThreadError
wxThread::Create()
133 if (p_internal
->state
!= STATE_IDLE
)
134 return THREAD_RUNNING
;
135 p_internal
->state
= STATE_RUNNING
;
136 if (sproc(p_internal
->SprocStart
, PR_SALL
, this) < 0) {
137 p_internal
->state
= STATE_IDLE
;
138 return THREAD_NO_RESOURCE
;
140 return THREAD_NO_ERROR
;
143 void wxThread::Destroy()
145 if (p_internal
->state
== STATE_RUNNING
)
146 p_internal
->state
= STATE_CANCELED
;
149 void *wxThread::Join()
151 if (p_internal
->state
!= STATE_IDLE
) {
152 bool do_unlock
= wxThread::IsMain();
156 wxMainMutex
.Unlock();
157 waitpid(p_internal
->thread_id
, &stat
, 0);
160 if (!WIFEXITED(stat
) && !WIFSIGNALED(stat
))
162 p_internal
->state
= STATE_IDLE
;
163 return p_internal
->exit_status
;
168 unsigned long wxThread::GetID() const
170 return (unsigned long)p_internal
->thread_id
;
173 void wxThread::TestDestroy()
175 if (p_internal
->state
== STATE_CANCELED
) {
176 p_internal
->exit_status
= 0;
181 void wxThread::SetPriority(int prio
)
185 int wxThread::GetPriority() const
190 bool wxThreadIsMain()
192 return (int)getpid() == main_id
;
197 p_internal
= new wxThreadPrivate();
200 wxThread::~wxThread()
207 // The default callback just joins the thread and throws away the result.
208 void wxThread::OnExit()
213 // Global initialization
214 class wxThreadModule
: public wxModule
{
215 DECLARE_DYNAMIC_CLASS(wxThreadModule
)
217 virtual bool OnInit() {
219 p_mainid
= (int)getpid();
223 virtual void OnExit() {
224 wxMainMutex
.Unlock();
229 IMPLEMENT_DYNAMIC_CLASS(wxThreadModule
, wxModule
)