]> git.saurik.com Git - wxWidgets.git/blobdiff - src/unix/threadpsx.cpp
missing comma for Motif compilation added
[wxWidgets.git] / src / unix / threadpsx.cpp
index 2c8fb6851d2472b5e04045ff7aedbdebc214923f..ca1c7731b64e264a0bf06cb69f46b0e07d6e0488 100644 (file)
     #include <sched.h>
 #endif
 
+#ifdef __WXGTK12__
+#include "gtk/gtk.h"
+#endif
+
 // ----------------------------------------------------------------------------
 // constants
 // ----------------------------------------------------------------------------
@@ -81,8 +85,10 @@ static pthread_t gs_tidMain;
 // the key for the pointer to the associated wxThread object
 static pthread_key_t gs_keySelf;
 
+#ifndef __WXGTK12__
 // this mutex must be acquired before any call to a GUI function
 static wxMutex *gs_mutexGui;
+#endif
 
 // ============================================================================
 // implementation
@@ -325,7 +331,8 @@ wxThreadInternal::wxThreadInternal()
 
 wxThreadInternal::~wxThreadInternal()
 {
-    m_mutexSuspend.Unlock();
+    // GL: moved to SignalExit
+    // m_mutexSuspend.Unlock();
 
     // note that m_mutex will be unlocked by the thread which waits for our
     // termination
@@ -375,6 +382,9 @@ void wxThreadInternal::Wait()
 
 void wxThreadInternal::SignalExit()
 {
+    // GL: Unlock mutexSuspend here.
+    m_mutexSuspend.Unlock();
+
     // as mutex is currently locked, this will block until some other thread
     // (normally the same which created this one) unlocks it by entering Wait()
     m_mutex.Lock();
@@ -453,9 +463,7 @@ wxThread::wxThread()
 
 wxThreadError wxThread::Create()
 {
-    // Maybe we could think about recreate the thread once it has exited.
-    if (p_internal->GetState() != STATE_NEW &&
-        p_internal->GetState() != STATE_EXITED)
+    if (p_internal->GetState() != STATE_NEW)
         return wxTHREAD_RUNNING;
 
     // set up the thread attribute: right now, we only set thread priority
@@ -590,7 +598,9 @@ wxThreadError wxThread::Resume()
 
     if ( p_internal->GetState() == STATE_PAUSED )
     {
+        m_critsect.Leave();
         p_internal->Resume();
+        m_critsect.Enter();
 
         return wxTHREAD_NO_ERROR;
     }
@@ -665,10 +675,10 @@ void wxThread::Exit(void *status)
 
     // next wake up the threads waiting for us (OTOH, this function won't return
     // until someone waited for us!)
-    p_internal->SignalExit();
-
     p_internal->SetState(STATE_EXITED);
 
+    p_internal->SignalExit();
+
     // delete both C++ thread object and terminate the OS thread object
     // GL: This is very ugly and buggy ...
 //    delete this;
@@ -727,6 +737,13 @@ bool wxThread::IsAlive() const
     }
 }
 
+bool wxThread::IsPaused() const
+{
+    wxCriticalSectionLocker lock((wxCriticalSection&)m_critsect);
+
+    return (p_internal->GetState() == STATE_PAUSED);
+}
+
 //--------------------------------------------------------------------
 // wxThreadModule
 //--------------------------------------------------------------------
@@ -754,12 +771,15 @@ bool wxThreadModule::OnInit()
         return FALSE;
     }
 
+#ifndef __WXGTK12__
     gs_mutexGui = new wxMutex();
-
-    //wxThreadGuiInit();
+#endif
 
     gs_tidMain = pthread_self();
+
+#ifndef __WXGTK12__
     gs_mutexGui->Lock();
+#endif
 
     return TRUE;
 }
@@ -778,12 +798,12 @@ void wxThreadModule::OnExit()
         gs_allThreads[n]->Delete();
     }
 
+#ifndef __WXGTK12__
     // destroy GUI mutex
     gs_mutexGui->Unlock();
 
-    //wxThreadGuiExit();
-
     delete gs_mutexGui;
+#endif
 
     // and free TLD slot
     (void)pthread_key_delete(gs_keySelf);
@@ -795,12 +815,20 @@ void wxThreadModule::OnExit()
 
 void wxMutexGuiEnter()
 {
+#ifdef __WXGTK12__
+  gdk_threads_enter();
+#else
   gs_mutexGui->Lock();
+#endif
 }
 
 void wxMutexGuiLeave()
 {
+#ifdef __WXGTK12__
+  gdk_threads_leave();
+#else
   gs_mutexGui->Unlock();
+#endif
 }
 
 #endif