summaryrefslogtreecommitdiff
path: root/src/thread/thread_pthread.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/thread/thread_pthread.cpp')
-rw-r--r--src/thread/thread_pthread.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/thread/thread_pthread.cpp b/src/thread/thread_pthread.cpp
index 483b71c0f..ca1fb8f5a 100644
--- a/src/thread/thread_pthread.cpp
+++ b/src/thread/thread_pthread.cpp
@@ -12,6 +12,7 @@
#include "../stdafx.h"
#include "thread.h"
#include <pthread.h>
+#include <errno.h>
/**
* POSIX pthread version for ThreadObject.
@@ -95,16 +96,21 @@ private:
class ThreadMutex_pthread : public ThreadMutex {
private:
pthread_mutex_t mutex;
+ pthread_cond_t condition;
public:
ThreadMutex_pthread()
{
pthread_mutex_init(&this->mutex, NULL);
+ pthread_cond_init(&this->condition, NULL);
}
/* virtual */ ~ThreadMutex_pthread()
{
- pthread_mutex_destroy(&this->mutex);
+ int err = pthread_cond_destroy(&this->condition);
+ assert(err != EBUSY);
+ err = pthread_mutex_destroy(&this->mutex);
+ assert(err != EBUSY);
}
/* virtual */ void BeginCritical()
@@ -116,6 +122,16 @@ public:
{
pthread_mutex_unlock(&this->mutex);
}
+
+ /* virtual */ void WaitForSignal()
+ {
+ pthread_cond_wait(&this->condition, &this->mutex);
+ }
+
+ /* virtual */ void SendSignal()
+ {
+ pthread_cond_signal(&this->condition);
+ }
};
/* static */ ThreadMutex *ThreadMutex::New()