]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/threadsgi.cpp
07d7cdabdeb2ecc4fd9af222a72b42db780caeda
   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 
{ 
  49   p_internal 
= new wxMutexInternal
; 
  50   init_lock(&(p_internal
->p_mutex
)); 
  57 wxMutex::MutexError 
wxMutex::Lock(void) 
  59   spin_lock(&(p_internal
->p_mutex
)); 
  63 wxMutex::MutexError 
wxMutex::TryLock(void) 
  65   if (acquire_lock(&(p_internal
->p_mutex
)) != 0) 
  70 wxMutex::MutexError 
wxMutex::Unlock(void) 
  72   release_lock(&(p_internal
->p_mutex
)); 
  76 // GLH: Don't now how it works on SGI. Wolfram ? 
  78 wxCondition::wxCondition(void) {} 
  79 wxCondition::~wxCondition(void) {} 
  80 int wxCondition::Wait(wxMutex
& WXUNUSED(mutex
)) { return 0;} 
  81 int wxCondition::Wait(wxMutex
& WXUNUSED(mutex
), unsigned long WXUNUSED(sec
), 
  82                       unsigned long WXUNUSED(nsec
)) { return 0; } 
  83 int wxCondition::Signal(void) { return 0; } 
  84 int wxCondition::Broadcast(void) { return 0; } 
  89   wxThreadPrivate() { thread_id 
= 0; state 
= STATE_IDLE
; } 
  91   static void SprocStart(void *ptr
); 
  92   static void SignalHandler(int sig
); 
  98 void wxThreadPrivate::SprocStart(void *ptr
) 
 102   wxThread 
*thr 
= (wxThread 
*)ptr
; 
 104   thr
->p_internal
->thread_id 
= getpid(); 
 105   thr
->p_internal
->exit_status 
= 0; 
 106   status 
= thr
->Entry(); 
 110 void wxThread::Exit(void* status
) 
 112   wxThread
* ptr 
= this; 
 113   THREAD_SEND_EXIT_MSG(ptr
); 
 114   p_internal
->state 
= STATE_EXITED
; 
 115   p_internal
->exit_status 
= status
; 
 119 wxThread::ThreadError 
wxThread::Create() 
 121   if (p_internal
->state 
!= STATE_IDLE
) 
 123   p_internal
->state 
= STATE_RUNNING
; 
 124   if (sproc(p_internal
->SprocStart
, PR_SALL
, this) < 0) { 
 125     p_internal
->state 
= STATE_IDLE
; 
 131 void wxThread::Destroy() 
 133   if (p_internal
->state 
== STATE_RUNNING
) 
 134     p_internal
->state 
= STATE_CANCELED
; 
 137 void *wxThread::Join() 
 139   if (p_internal
->state 
!= STATE_IDLE
) { 
 140     bool do_unlock 
= wxThread::IsMain(); 
 144       wxMainMutex
.Unlock(); 
 145     waitpid(p_internal
->thread_id
, &stat
, 0); 
 148     if (!WIFEXITED(stat
) && !WIFSIGNALED(stat
)) 
 150     p_internal
->state 
= STATE_IDLE
; 
 151     return p_internal
->exit_status
; 
 156 unsigned long wxThread::GetID() 
 158   return (unsigned long)p_internal
->thread_id
; 
 161 void wxThread::TestDestroy() 
 163   if (p_internal
->state 
== STATE_CANCELED
) { 
 164     p_internal
->exit_status 
= 0; 
 169 void wxThread::SetPriority(int prio
) 
 173 int wxThread::GetPriority(void) 
 177 bool wxThreadIsMain() 
 179   return (int)getpid() == main_id
; 
 184   p_internal 
= new wxThreadPrivate(); 
 187 wxThread::~wxThread() 
 194 // The default callback just joins the thread and throws away the result. 
 195 void wxThread::OnExit() 
 200 // Global initialization 
 201 class wxThreadModule 
: public wxModule 
{ 
 202   DECLARE_DYNAMIC_CLASS(wxThreadModule
) 
 204   virtual bool OnInit(void) { 
 206     p_mainid 
= (int)getpid(); 
 210   virtual void OnExit(void) { 
 211     wxMainMutex
.Unlock(); 
 216 IMPLEMENT_DYNAMIC_CLASS(wxThreadModule
, wxModule
)