summaryrefslogtreecommitdiff
path: root/libs/pbd
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2015-12-02 13:38:59 +0100
committerRobin Gareus <robin@gareus.org>2015-12-02 13:59:48 +0100
commit14d6470ad36a1682966ff93e774849901055a916 (patch)
treed37838c341a09f1814db6783b920ceab4cbdf6aa /libs/pbd
parente9be313c11cb0eafd7fcd2800748ae80be95787f (diff)
prefer pthread-semaphores (posix API) with mingw
Hopefully this resolves glitches on hyperthreading machines. Apart from using unnamed Semaphores, pthread-w32 includes additional locks (guess: mem-barriers), a fallback implementation and windows-specific tricks that I'd rather not want to know about :)
Diffstat (limited to 'libs/pbd')
-rw-r--r--libs/pbd/pbd/semutils.h11
-rw-r--r--libs/pbd/semutils.cc6
2 files changed, 11 insertions, 6 deletions
diff --git a/libs/pbd/pbd/semutils.h b/libs/pbd/pbd/semutils.h
index 5c0191e25b..50ac41919c 100644
--- a/libs/pbd/pbd/semutils.h
+++ b/libs/pbd/pbd/semutils.h
@@ -19,9 +19,14 @@
#ifndef __pbd_semutils_h__
#define __pbd_semutils_h__
-#ifdef PLATFORM_WINDOWS
+#if (defined PLATFORM_WINDOWS && !defined USE_PTW32_SEMAPHORE)
+#define WINDOWS_SEMAPHORE 1
+#endif
+
+#ifdef WINDOWS_SEMAPHORE
#include <windows.h>
#else
+#include <pthread.h>
#include <semaphore.h>
#endif
@@ -31,7 +36,7 @@ namespace PBD {
class LIBPBD_API ProcessSemaphore {
private:
-#ifdef PLATFORM_WINDOWS
+#ifdef WINDOWS_SEMAPHORE
HANDLE _sem;
#elif __APPLE__
@@ -46,7 +51,7 @@ class LIBPBD_API ProcessSemaphore {
ProcessSemaphore (const char* name, int val);
~ProcessSemaphore ();
-#ifdef PLATFORM_WINDOWS
+#ifdef WINDOWS_SEMAPHORE
int signal ();
int wait ();
diff --git a/libs/pbd/semutils.cc b/libs/pbd/semutils.cc
index 5d3ef3d958..bafa447f8f 100644
--- a/libs/pbd/semutils.cc
+++ b/libs/pbd/semutils.cc
@@ -23,7 +23,7 @@ using namespace PBD;
ProcessSemaphore::ProcessSemaphore (const char* name, int val)
{
-#ifdef PLATFORM_WINDOWS
+#ifdef WINDOWS_SEMAPHORE
if ((_sem = CreateSemaphore(NULL, val, 32767, name)) == NULL) {
throw failed_constructor ();
}
@@ -50,14 +50,14 @@ ProcessSemaphore::ProcessSemaphore (const char* name, int val)
ProcessSemaphore::~ProcessSemaphore ()
{
-#ifdef PLATFORM_WINDOWS
+#ifdef WINDOWS_SEMAPHORE
CloseHandle(_sem);
#elif __APPLE__
sem_close (ptr_to_sem());
#endif
}
-#ifdef PLATFORM_WINDOWS
+#ifdef WINDOWS_SEMAPHORE
int
ProcessSemaphore::signal ()