summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/configfile.cc10
-rw-r--r--src/mutex.cc15
-rw-r--r--src/thread.cc31
-rw-r--r--src/thread.h33
4 files changed, 47 insertions, 42 deletions
diff --git a/src/configfile.cc b/src/configfile.cc
index 24f9deb..71496a0 100644
--- a/src/configfile.cc
+++ b/src/configfile.cc
@@ -35,7 +35,9 @@
#include <sys/stat.h>
#include <sys/types.h>
-#ifdef WIN32
+#include "platform.h"
+
+#if DG_PLATFORM == DG_PLATFORM_WINDOWS
#include <direct.h>
#include <windows.h>
#include <Shlobj.h>
@@ -45,7 +47,7 @@
#include <hugin.hpp>
-#ifdef WIN32
+#if DG_PLATFORM == DG_PLATFORM_WINDOWS
#define SEP "\\"
#else
#define SEP "/"
@@ -58,7 +60,7 @@
*/
static std::string getConfigPath()
{
-#ifdef WIN32
+#if DG_PLATFORM == DG_PLATFORM_WINDOWS
std::string configpath;
TCHAR szPath[256];
if(SUCCEEDED(SHGetFolderPath(
@@ -87,7 +89,7 @@ static bool createConfigPath()
{
DEBUG(configfile, "No configuration exists, creating directory '%s'\n",
configpath.c_str());
-#ifdef WIN32
+#if DG_PLATFORM == DG_PLATFORM_WINDOWS
if(mkdir(configpath.c_str()) < 0)
{
#else
diff --git a/src/mutex.cc b/src/mutex.cc
index 84143be..b90132d 100644
--- a/src/mutex.cc
+++ b/src/mutex.cc
@@ -28,8 +28,9 @@
#include "mutex.h"
#include <hugin.hpp>
+#include "platform.h"
-#ifdef WIN32
+#if DG_PLATFORM == DG_PLATFORM_WINDOWS
#include <windows.h>
#else
#include <pthread.h>
@@ -37,7 +38,7 @@
#endif
struct mutex_private_t {
-#ifdef WIN32
+#if DG_PLATFORM == DG_PLATFORM_WINDOWS
HANDLE mutex;
#else
pthread_mutex_t mutex;
@@ -47,7 +48,7 @@ struct mutex_private_t {
Mutex::Mutex()
{
prv = new struct mutex_private_t();
-#ifdef WIN32
+#if DG_PLATFORM == DG_PLATFORM_WINDOWS
prv->mutex = CreateMutex(nullptr, // default security attributes
FALSE, // initially not owned
nullptr); // unnamed mutex
@@ -58,7 +59,7 @@ Mutex::Mutex()
Mutex::~Mutex()
{
-#ifdef WIN32
+#if DG_PLATFORM == DG_PLATFORM_WINDOWS
CloseHandle(prv->mutex);
#else
pthread_mutex_destroy(&prv->mutex);
@@ -74,7 +75,7 @@ Mutex::~Mutex()
//! false otherwise.
bool Mutex::try_lock()
{
-#ifdef WIN32
+#if DG_PLATFORM == DG_PLATFORM_WINDOWS
DEBUG(mutex, "%s\n", __PRETTY_FUNCTION__);
DWORD result = WaitForSingleObject(prv->mutex, 0);
@@ -90,7 +91,7 @@ bool Mutex::try_lock()
void Mutex::lock()
{
-#ifdef WIN32
+#if DG_PLATFORM == DG_PLATFORM_WINDOWS
WaitForSingleObject(prv->mutex, // handle to mutex
INFINITE); // no time-out interval
#else
@@ -100,7 +101,7 @@ void Mutex::lock()
void Mutex::unlock()
{
-#ifdef WIN32
+#if DG_PLATFORM == DG_PLATFORM_WINDOWS
ReleaseMutex(prv->mutex);
#else
pthread_mutex_unlock(&prv->mutex);
diff --git a/src/thread.cc b/src/thread.cc
index 030c5dd..abc59a2 100644
--- a/src/thread.cc
+++ b/src/thread.cc
@@ -26,7 +26,6 @@
*/
#include "thread.h"
-#include <stdio.h>
#include <hugin.hpp>
Thread::Thread()
@@ -37,32 +36,32 @@ Thread::~Thread()
void Thread::run()
{
- DEBUG(thread, "Thread::run()\n");
-#ifdef WIN32
- tid = CreateThread(NULL, 0, thread_run, this, 0, NULL);
+ DEBUG(thread, "Thread::run()\n");
+#if DG_PLATFORM == DG_PLATFORM_WINDOWS
+ tid = CreateThread(NULL, 0, thread_run, this, 0, NULL);
#else
- pthread_create(&tid, NULL, thread_run, this);
-#endif/*WIN32*/
+ pthread_create(&tid, NULL, thread_run, this);
+#endif
}
void Thread::wait_stop()
{
-#ifdef WIN32
- WaitForSingleObject(tid, INFINITE);
+#if DG_PLATFORM == DG_PLATFORM_WINDOWS
+ WaitForSingleObject(tid, INFINITE);
#else
- pthread_join(tid, NULL);
-#endif/*WIN32*/
+ pthread_join(tid, NULL);
+#endif
}
-#ifdef WIN32
+#if DG_PLATFORM == DG_PLATFORM_WINDOWS
DWORD WINAPI
#else
void*
-#endif/*WIN32*/
+#endif
Thread::thread_run(void *data)
{
- DEBUG(thread, "Thread run\n");
- Thread *t = (Thread*)data;
- t->thread_main();
- return 0;
+ DEBUG(thread, "Thread run\n");
+ Thread *t = (Thread*)data;
+ t->thread_main();
+ return 0;
}
diff --git a/src/thread.h b/src/thread.h
index 6d3b920..f5bf1a7 100644
--- a/src/thread.h
+++ b/src/thread.h
@@ -26,31 +26,34 @@
*/
#pragma once
-#ifdef WIN32
+#include "platform.h"
+
+#if DG_PLATFORM == DG_PLATFORM_WINDOWS
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#else
#include <pthread.h>
-#endif/*WIN32*/
+#endif
-class Thread {
+class Thread
+{
public:
- Thread();
- virtual ~Thread();
+ Thread();
+ virtual ~Thread();
- void run();
- void wait_stop();
+ void run();
+ void wait_stop();
protected:
- virtual void thread_main() = 0;
-
+ virtual void thread_main() = 0;
+
private:
-#ifdef WIN32
+#if DG_PLATFORM == DG_PLATFORM_WINDOWS
HANDLE tid{nullptr};
- static DWORD WINAPI
+ static DWORD WINAPI
#else
- pthread_t tid{0};
- static void*
-#endif/*WIN32*/
- thread_run(void *data);
+ pthread_t tid{0};
+ static void*
+#endif
+ thread_run(void *data);
};