prefer pthread-semaphores (posix API) with mingw
authorRobin Gareus <robin@gareus.org>
Wed, 2 Dec 2015 12:38:59 +0000 (13:38 +0100)
committerRobin Gareus <robin@gareus.org>
Wed, 2 Dec 2015 12:59:48 +0000 (13:59 +0100)
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 :)

libs/pbd/pbd/semutils.h
libs/pbd/semutils.cc
wscript

index 5c0191e25bfea4cb291d838117200d43d98b4ab3..50ac41919c26b9c8411706f5c360544c0645a797 100644 (file)
 #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 ();
index 5d3ef3d958ce2fb3230dead833f00e35284e7de5..bafa447f8fac9185af8e275445ef90de0b9637eb 100644 (file)
@@ -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 ()
diff --git a/wscript b/wscript
index cefe9998d9e50ea57f6661563dad92ab46f14ac4..041b12ecba0a2fcb857882e063fda5a53a8c5584 100644 (file)
--- a/wscript
+++ b/wscript
@@ -963,6 +963,11 @@ int main () { int x = SFC_RF64_AUTO_DOWNGRADE; return 0; }
         conf.env.append_value('CXXFLAGS', '-DUSE_CAIRO_IMAGE_SURFACE')
         conf.define ('WINDOWS', 1)
 
+        if os.path.isfile (user_gtk_root + 'include/semaphore.h'):
+            conf.define ('USE_PTW32_SEMAPHORE', 1)
+            conf.env.append_value('CFLAGS', '-DUSE_PTW32_SEMAPHORE')
+            conf.env.append_value('CXXFLAGS', '-DUSE_PTW32_SEMAPHORE')
+
     if Options.options.dist_target == 'msvc':
         conf.env.append_value('CFLAGS', '-DPLATFORM_WINDOWS')
         conf.env.append_value('CFLAGS', '-DCOMPILER_MSVC')
@@ -1144,7 +1149,8 @@ const char* const ardour_config_info = "\\n\\
     write_config_text('Phone home',            conf.is_defined('PHONE_HOME'))
     write_config_text('Program name',          opts.program_name)
     write_config_text('Samplerate',            conf.is_defined('HAVE_SAMPLERATE'))
-    write_config_text('PT format',            conf.is_defined('PTFORMAT'))
+    write_config_text('PT format',             conf.is_defined('PTFORMAT'))
+    write_config_text('PTW32 Semaphore',       conf.is_defined('USE_PTW32_SEMAPHORE'))
 #    write_config_text('Soundtouch',            conf.is_defined('HAVE_SOUNDTOUCH'))
     write_config_text('Translation',           opts.nls)
 #    write_config_text('Tranzport',             opts.tranzport)