summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/threadengines/threadengine_pthread.h19
-rw-r--r--include/threadengines/threadengine_win32.h19
2 files changed, 6 insertions, 32 deletions
diff --git a/include/threadengines/threadengine_pthread.h b/include/threadengines/threadengine_pthread.h
index 454e3ea4a..ca3354260 100644
--- a/include/threadengines/threadengine_pthread.h
+++ b/include/threadengines/threadengine_pthread.h
@@ -74,7 +74,7 @@ class CoreExport ThreadEngine
*/
class CoreExport Mutex
{
- private:
+ protected:
pthread_mutex_t putex;
public:
/** Constructor.
@@ -103,33 +103,20 @@ class CoreExport Mutex
}
};
-class ThreadQueueData
+class ThreadQueueData : public Mutex
{
- pthread_mutex_t mutex;
pthread_cond_t cond;
public:
ThreadQueueData()
{
- pthread_mutex_init(&mutex, NULL);
pthread_cond_init(&cond, NULL);
}
~ThreadQueueData()
{
- pthread_mutex_destroy(&mutex);
pthread_cond_destroy(&cond);
}
- void Lock()
- {
- pthread_mutex_lock(&mutex);
- }
-
- void Unlock()
- {
- pthread_mutex_unlock(&mutex);
- }
-
void Wakeup()
{
pthread_cond_signal(&cond);
@@ -137,7 +124,7 @@ class ThreadQueueData
void Wait()
{
- pthread_cond_wait(&cond, &mutex);
+ pthread_cond_wait(&cond, &putex);
}
};
diff --git a/include/threadengines/threadengine_win32.h b/include/threadengines/threadengine_win32.h
index bf8658853..aac7b8b97 100644
--- a/include/threadengines/threadengine_win32.h
+++ b/include/threadengines/threadengine_win32.h
@@ -99,9 +99,8 @@ class CoreExport Mutex
}
};
-class ThreadQueueData
+class ThreadQueueData : public Mutex
{
- CRITICAL_SECTION mutex;
HANDLE event;
public:
ThreadQueueData()
@@ -109,23 +108,11 @@ class ThreadQueueData
event = CreateEvent(NULL, false, false, NULL);
if (event == NULL)
throw CoreException("CreateEvent() failed in ThreadQueueData::ThreadQueueData()!");
- InitializeCriticalSection(&mutex);
}
~ThreadQueueData()
{
CloseHandle(event);
- DeleteCriticalSection(&mutex);
- }
-
- void Lock()
- {
- EnterCriticalSection(&mutex);
- }
-
- void Unlock()
- {
- LeaveCriticalSection(&mutex);
}
void Wakeup()
@@ -135,9 +122,9 @@ class ThreadQueueData
void Wait()
{
- LeaveCriticalSection(&mutex);
+ Unlock();
WaitForSingleObject(event, INFINITE);
- EnterCriticalSection(&mutex);
+ Lock();
}
};