]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/threadpsx.cpp
Since wxREADONLY has disappeared, I had to change to wxTE_READONLY
[wxWidgets.git] / src / gtk / threadpsx.cpp
index 645fba49ab22a2ad31746dddd28be4cf12473890..363f0636eafc5bbab35e30b72e7e042fb81e61e5 100644 (file)
 
 #include <stdio.h>
 #include <unistd.h>
-#include <sched.h>
 #include <pthread.h>
+#include <errno.h>
+#include "wx/thread.h"
+#include "wx/module.h"
+#include "wx/utils.h"
 
 enum thread_state {
   STATE_IDLE = 0,
@@ -28,8 +31,6 @@ enum thread_state {
 // Static variables
 /////////////////////////////////////////////////////////////////////////////
 
-#include "thread.h"
-
 static pthread_t p_mainid;
 wxMutex wxMainMutex; // controls access to all GUI functions
 
@@ -47,34 +48,35 @@ public:
   pthread_mutex_t p_mutex;
 };
 
-wxMutex::wxMutex(void)
+wxMutex::wxMutex()
 {
   p_internal = new wxMutexInternal;
   pthread_mutex_init(&(p_internal->p_mutex), NULL);
-  m_locked = false;
+  m_locked = 0;
 }
 
-wxMutex::~wxMutex(void)
+wxMutex::~wxMutex()
 {
-  if (m_locked)
-    pthread_mutex_unlock(&(p_internal->p_mutex));
+  if (m_locked > 0)
+    wxDebugMsg("wxMutex warning: freeing a locked mutex (%d locks)\n",
+               m_locked);
+
   pthread_mutex_destroy(&(p_internal->p_mutex));
   delete p_internal;
 }
 
-wxMutexError wxMutex::Lock(void)
+wxMutexError wxMutex::Lock()
 {
   int err;
 
   err = pthread_mutex_lock(&(p_internal->p_mutex));
-  switch (err) {
-  case EDEADLK: return MUTEX_DEAD_LOCK;
-  }
+  if (err == EDEADLK)
+    return MUTEX_DEAD_LOCK;
   m_locked++;
   return MUTEX_NO_ERROR;
 }
 
-wxMutexError wxMutex::TryLock(void)
+wxMutexError wxMutex::TryLock()
 {
   int err;
 
@@ -88,9 +90,12 @@ wxMutexError wxMutex::TryLock(void)
   return MUTEX_NO_ERROR;
 }
 
-wxMutexError wxMutex::Unlock(void)
+wxMutexError wxMutex::Unlock()
 {
-  if (m_locked > 0) m_locked--;
+  if (m_locked > 0)
+    m_locked--;
+  else
+    return MUTEX_UNLOCKED;
   pthread_mutex_unlock(&(p_internal->p_mutex));
   return MUTEX_NO_ERROR;
 }
@@ -104,13 +109,13 @@ public:
   pthread_cond_t p_condition;
 };
 
-wxCondition::wxCondition(void)
+wxCondition::wxCondition()
 {
   p_internal = new wxConditionInternal;
   pthread_cond_init(&(p_internal->p_condition), NULL);
 }
 
-wxCondition::~wxCondition(void)
+wxCondition::~wxCondition()
 {
   pthread_cond_destroy(&(p_internal->p_condition));
   delete p_internal;
@@ -130,12 +135,12 @@ bool wxCondition::Wait(wxMutex& mutex, unsigned long sec, unsigned long nsec)
   return (pthread_cond_timedwait(&(p_internal->p_condition), &(mutex.p_internal->p_mutex), &tspec) != ETIMEDOUT);
 }
 
-void wxCondition::Signal(void)
+void wxCondition::Signal()
 {
   pthread_cond_signal(&(p_internal->p_condition));
 }
 
-void wxCondition::Broadcast(void)
+void wxCondition::Broadcast()
 {
   pthread_cond_broadcast(&(p_internal->p_condition));
 }
@@ -210,7 +215,7 @@ void wxThread::SetPriority(int prio)
   p_internal->prio = prio;
 }
 
-int wxThread::GetPriority(void)
+int wxThread::GetPriority() const
 {
   return p_internal->prio;
 }
@@ -223,7 +228,7 @@ void wxThread::DeferDestroy(bool on)
     pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
 }
 
-wxThreadError wxThread::Destroy(void)
+wxThreadError wxThread::Destroy()
 {
   int res = 0;
 
@@ -255,7 +260,7 @@ void *wxThread::Join()
   return status;
 }
 
-unsigned long wxThread::GetID()
+unsigned long wxThread::GetID() const
 {
   return (unsigned long)p_internal->thread_id;
 }
@@ -274,7 +279,7 @@ void wxThread::TestDestroy()
   pthread_testcancel();
 }
 
-bool wxThread::IsMain(void)
+bool wxThread::IsMain()
 {
   return (bool)pthread_equal(pthread_self(), p_mainid);
 }
@@ -300,7 +305,7 @@ void wxThread::OnExit()
 class wxThreadModule : public wxModule {
   DECLARE_DYNAMIC_CLASS(wxThreadModule)
 public:
-  virtual bool OnInit(void) {
+  virtual bool OnInit() {
     wxThreadGuiInit();
     p_mainid = pthread_self();
     wxMainMutex.Lock();
@@ -308,7 +313,7 @@ public:
     return TRUE;
   }
 
-  virtual void OnExit(void) {
+  virtual void OnExit() {
     wxMainMutex.Unlock();
     wxThreadGuiExit();
   }