]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/threadsgi.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/threadsgi.cpp
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 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
15 #include "wx/thread.h"
26 #include <sys/prctl.h>
27 #include "wx/module.h"
41 /////////////////////////////////////////////////////////////////////////////
43 /////////////////////////////////////////////////////////////////////////////
48 #include "threadgui.inc"
50 /////////////////////////////////////////////////////////////////////////////
51 // Unix implementations (SGI threads)
52 /////////////////////////////////////////////////////////////////////////////
54 class wxMutexInternal
{
62 p_internal
= new wxMutexInternal
;
63 init_lock(&(p_internal
->p_mutex
));
69 wxLogDebug( "wxMutex warning: freeing a locked mutex (%d locks)\n", m_locked
);
73 wxMutexError
wxMutex::Lock()
75 spin_lock(&(p_internal
->p_mutex
));
77 return wxMUTEX_NO_ERROR
;
80 wxMutexError
wxMutex::TryLock()
82 if (acquire_lock(&(p_internal
->p_mutex
)) != 0)
85 return wxMUTEX_NO_ERROR
;
88 wxMutexError
wxMutex::Unlock()
91 return wxMUTEX_UNLOCKED
;
92 release_lock(&(p_internal
->p_mutex
));
94 return wxMUTEX_NO_ERROR
;
97 // GL: Don't know how it works on SGI. Wolfram ?
99 wxCondition::wxCondition() {}
100 wxCondition::~wxCondition() {}
101 int wxCondition::Wait(wxMutex
& WXUNUSED(mutex
)) { return 0;}
102 int wxCondition::Wait(wxMutex
& WXUNUSED(mutex
), unsigned long WXUNUSED(sec
),
103 unsigned long WXUNUSED(nsec
)) { return 0; }
104 int wxCondition::Signal() { return 0; }
105 int wxCondition::Broadcast() { return 0; }
110 wxThreadPrivate() { thread_id
= 0; state
= STATE_IDLE
; }
111 ~wxThreadPrivate() {}
112 static void SprocStart(void *ptr
);
113 static void SignalHandler(int sig
);
115 int state
, thread_id
;
119 void wxThreadPrivate::SprocStart(void *ptr
)
123 wxThread
*thr
= (wxThread
*)ptr
;
125 thr
->p_internal
->thread_id
= getpid();
126 thr
->p_internal
->exit_status
= 0;
127 status
= thr
->Entry();
131 void wxThread::Exit(void* status
)
133 wxThread
* ptr
= this;
134 THREAD_SEND_EXIT_MSG(ptr
);
135 p_internal
->state
= STATE_EXITED
;
136 p_internal
->exit_status
= status
;
140 wxThreadError
wxThread::Create()
142 if (p_internal
->state
!= STATE_IDLE
)
143 return wxTHREAD_RUNNING
;
144 p_internal
->state
= STATE_RUNNING
;
145 if (sproc(p_internal
->SprocStart
, PR_SALL
, this) < 0) {
146 p_internal
->state
= STATE_IDLE
;
147 return wxTHREAD_NO_RESOURCE
;
149 return wxTHREAD_NO_ERROR
;
152 wxThreadError
wxThread::Destroy()
154 if (p_internal
->state
== STATE_RUNNING
)
155 p_internal
->state
= STATE_CANCELED
;
157 return wxTHREAD_NO_ERROR
;
160 wxThreadError
wxThread::Pause()
162 return wxTHREAD_NO_ERROR
;
165 wxThreadError
wxThread::Resume()
167 return wxTHREAD_NO_ERROR
;
170 void *wxThread::Join()
172 if (p_internal
->state
!= STATE_IDLE
) {
173 bool do_unlock
= wxThread::IsMain();
177 wxMainMutex
->Unlock();
178 waitpid(p_internal
->thread_id
, &stat
, 0);
181 if (!WIFEXITED(stat
) && !WIFSIGNALED(stat
))
183 p_internal
->state
= STATE_IDLE
;
184 return p_internal
->exit_status
;
189 unsigned long wxThread::GetID() const
191 return (unsigned long)p_internal
->thread_id
;
194 void wxThread::TestDestroy()
196 if (p_internal
->state
== STATE_CANCELED
) {
197 p_internal
->exit_status
= 0;
202 void wxThread::SetPriority(int prio
)
206 int wxThread::GetPriority() const
211 bool wxThread::IsMain()
213 return (int)getpid() == main_id
;
216 bool wxThread::IsAlive() const
218 return (p_internal
->state
== STATE_RUNNING
);
221 bool wxThread::IsRunning() const
223 return (p_internal
->state
== STATE_RUNNING
);
228 p_internal
= new wxThreadPrivate();
231 wxThread::~wxThread()
238 // The default callback just joins the thread and throws away the result.
239 void wxThread::OnExit()
244 // Global initialization
246 class wxThreadModule
: public wxModule
249 virtual bool OnInit();
250 virtual void OnExit();
253 DECLARE_DYNAMIC_CLASS(wxThreadModule
)
256 IMPLEMENT_DYNAMIC_CLASS(wxThreadModule
, wxModule
)
258 bool wxThreadModule::OnInit()
260 wxMainMutex
= new wxMutex();
262 p_mainid
= (int)getpid();
267 void wxThreadModule::OnExit()
269 wxMainMutex
->Unlock();