* Allow building on Win32 with MinGW
This commit is contained in:
37
src/Thread.h
37
src/Thread.h
@@ -15,7 +15,11 @@
|
||||
#ifndef _RUBBERBAND_THREAD_H_
|
||||
#define _RUBBERBAND_THREAD_H_
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else /* !_WIN32 */
|
||||
#include <pthread.h>
|
||||
#endif /* !_WIN32 */
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -25,7 +29,11 @@ namespace RubberBand
|
||||
class Thread
|
||||
{
|
||||
public:
|
||||
#ifdef _WIN32
|
||||
typedef HANDLE Id;
|
||||
#else
|
||||
typedef pthread_t Id;
|
||||
#endif
|
||||
|
||||
Thread();
|
||||
virtual ~Thread();
|
||||
@@ -41,9 +49,15 @@ protected:
|
||||
virtual void run() = 0;
|
||||
|
||||
private:
|
||||
#ifdef _WIN32
|
||||
HANDLE m_id;
|
||||
bool m_extant;
|
||||
static DWORD WINAPI staticRun(LPVOID lpParam);
|
||||
#else
|
||||
pthread_t m_id;
|
||||
bool m_extant;
|
||||
static void *staticRun(void *);
|
||||
#endif
|
||||
};
|
||||
|
||||
class Mutex
|
||||
@@ -57,8 +71,13 @@ public:
|
||||
bool trylock();
|
||||
|
||||
private:
|
||||
#ifdef _WIN32
|
||||
HANDLE m_mutex;
|
||||
bool m_locked;
|
||||
#else
|
||||
pthread_mutex_t m_mutex;
|
||||
bool m_locked;
|
||||
#endif
|
||||
};
|
||||
|
||||
class MutexLocker
|
||||
@@ -77,16 +96,34 @@ public:
|
||||
Condition(std::string name);
|
||||
~Condition();
|
||||
|
||||
// To wait on a condition, either simply call wait(), or call
|
||||
// lock() and then wait() (perhaps testing some state in between).
|
||||
// To signal a condition, call signal().
|
||||
|
||||
// Although any thread may signal on a given condition, only one
|
||||
// thread should ever wait on any given condition object --
|
||||
// otherwise there will be a race conditions in the logic that
|
||||
// avoids the thread code having to track whether the condition's
|
||||
// mutex is locked or not. If that is your requirement, this
|
||||
// Condition wrapper is not for you.
|
||||
void lock();
|
||||
void unlock();
|
||||
void wait(int us = 0);
|
||||
|
||||
void signal();
|
||||
|
||||
private:
|
||||
#ifdef _WIN32
|
||||
HANDLE m_mutex;
|
||||
bool m_locked;
|
||||
HANDLE m_condition;
|
||||
std::string m_name;
|
||||
#else
|
||||
pthread_mutex_t m_mutex;
|
||||
bool m_locked;
|
||||
pthread_cond_t m_condition;
|
||||
std::string m_name;
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user