summaryrefslogtreecommitdiff
path: root/include/threadengines
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2014-06-24 13:09:26 +0200
committerAttila Molnar <attilamolnar@hush.com>2014-06-24 13:09:26 +0200
commitd2760311db1446951b6a3894f7dc1f6a8f3ee931 (patch)
tree94a1e2b202598f589d303aa5201a66d8ae5bb771 /include/threadengines
parentddb1710aa3dc12566c80658d8dc577c07c5dc98b (diff)
Inherit ThreadQueueData from Mutex to avoid duplicating code
Diffstat (limited to 'include/threadengines')
-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();
}
};