]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/threadsgi.cpp
6ba3e7255c9a49daf61c5f698a2eb7e7321fcf5b
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/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"
20 #include "wx/module.h"
28 #include <sys/prctl.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
));
70 wxLogDebug( "wxMutex warning: freeing a locked mutex (%d locks)\n", m_locked
);
75 wxMutexError
wxMutex::Lock()
77 spin_lock(&(p_internal
->p_mutex
));
79 return wxMUTEX_NO_ERROR
;
82 wxMutexError
wxMutex::TryLock()
84 if (acquire_lock(&(p_internal
->p_mutex
)) != 0)
87 return wxMUTEX_NO_ERROR
;
90 wxMutexError
wxMutex::Unlock()
93 return wxMUTEX_UNLOCKED
;
94 release_lock(&(p_internal
->p_mutex
));
96 return wxMUTEX_NO_ERROR
;
99 // GL: Don't know how it works on SGI. Wolfram ?
101 wxCondition::wxCondition() {}
102 wxCondition::~wxCondition() {}
103 int wxCondition::Wait(wxMutex
& WXUNUSED(mutex
)) { return 0;}
104 int wxCondition::Wait(wxMutex
& WXUNUSED(mutex
), unsigned long WXUNUSED(sec
),
105 unsigned long WXUNUSED(nsec
)) { return 0; }
106 int wxCondition::Signal() { return 0; }
107 int wxCondition::Broadcast() { return 0; }
112 wxThreadPrivate() { thread_id
= 0; state
= STATE_IDLE
; }
113 ~wxThreadPrivate() {}
114 static void SprocStart(void *ptr
);
115 static void SignalHandler(int sig
);
117 int state
, thread_id
;
121 void wxThreadPrivate::SprocStart(void *ptr
)
125 wxThread
*thr
= (wxThread
*)ptr
;
127 thr
->p_internal
->thread_id
= getpid();
128 thr
->p_internal
->exit_status
= 0;
129 status
= thr
->Entry();
133 void wxThread::Exit(void* status
)
135 wxThread
* ptr
= this;
136 THREAD_SEND_EXIT_MSG(ptr
);
137 p_internal
->state
= STATE_EXITED
;
138 p_internal
->exit_status
= status
;
142 wxThreadError
wxThread::Create()
144 if (p_internal
->state
!= STATE_IDLE
)
145 return wxTHREAD_RUNNING
;
146 p_internal
->state
= STATE_RUNNING
;
147 if (sproc(p_internal
->SprocStart
, PR_SALL
, this) < 0) {
148 p_internal
->state
= STATE_IDLE
;
149 return wxTHREAD_NO_RESOURCE
;
151 return wxTHREAD_NO_ERROR
;
154 wxThreadError
wxThread::Destroy()
156 if (p_internal
->state
== STATE_RUNNING
)
157 p_internal
->state
= STATE_CANCELED
;
159 return wxTHREAD_NO_ERROR
;
162 wxThreadError
wxThread::Pause()
164 return wxTHREAD_NO_ERROR
;
167 wxThreadError
wxThread::Resume()
169 return wxTHREAD_NO_ERROR
;
172 void *wxThread::Join()
174 if (p_internal
->state
!= STATE_IDLE
) {
175 bool do_unlock
= wxThread::IsMain();
179 wxMainMutex
->Unlock();
180 waitpid(p_internal
->thread_id
, &stat
, 0);
183 if (!WIFEXITED(stat
) && !WIFSIGNALED(stat
))
185 p_internal
->state
= STATE_IDLE
;
186 return p_internal
->exit_status
;
191 unsigned long wxThread::GetID() const
193 return (unsigned long)p_internal
->thread_id
;
196 void wxThread::TestDestroy()
198 if (p_internal
->state
== STATE_CANCELED
) {
199 p_internal
->exit_status
= 0;
204 void wxThread::SetPriority(int prio
)
208 int wxThread::GetPriority() const
213 bool wxThread::IsMain()
215 return (int)getpid() == main_id
;
218 bool wxThread::IsAlive() const
220 return (p_internal
->state
== STATE_RUNNING
);
223 bool wxThread::IsRunning() const
225 return (p_internal
->state
== STATE_RUNNING
);
230 p_internal
= new wxThreadPrivate();
233 wxThread::~wxThread()
240 // The default callback just joins the thread and throws away the result.
241 void wxThread::OnExit()
246 // Global initialization
248 class wxThreadModule
: public wxModule
251 virtual bool OnInit();
252 virtual void OnExit();
255 DECLARE_DYNAMIC_CLASS(wxThreadModule
)
258 IMPLEMENT_DYNAMIC_CLASS(wxThreadModule
, wxModule
)
260 bool wxThreadModule::OnInit()
262 wxMainMutex
= new wxMutex();
264 p_mainid
= (int)getpid();
269 void wxThreadModule::OnExit()
271 wxMainMutex
->Unlock();