Browse Source

thread-safe fftw on windows too

Signed-off-by: falkTX <falktx@falktx.com>
tags/v1.0
falkTX 4 years ago
parent
commit
20efd84474
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
2 changed files with 35 additions and 6 deletions
  1. +1
    -1
      .travis.yml
  2. +34
    -5
      patches/fftw/01_static-planner-thread-safe.patch

+ 1
- 1
.travis.yml View File

@@ -13,7 +13,7 @@ cache:

env:
global:
- BOOTSTRAP_VERSION=11
- BOOTSTRAP_VERSION=12

jobs:
include:


+ 34
- 5
patches/fftw/01_static-planner-thread-safe.patch View File

@@ -1,12 +1,40 @@
--- fftw3-static-3.3.5~git20160520.orig/api/apiplan.c
+++ fftw3-static-3.3.5~git20160520/api/apiplan.c
@@ -19,8 +19,21 @@
*/
diff --git a/api/apiplan.c b/api/apiplan.c
index b8642a9..d63f2e4 100644
--- a/api/apiplan.c
+++ b/api/apiplan.c
@@ -20,7 +20,48 @@
#include "api/api.h"
+#include <pthread.h>
-static planner_hook_t before_planner_hook = 0, after_planner_hook = 0;
+#if defined(__WIN32__) || defined(_WIN32) || defined(_WINDOWS)
+/* hack: windef.h defines INT for its own purposes and this causes
+ a conflict with our own INT in ifftw.h. Divert the windows
+ definition into another name unlikely to cause a conflict */
+#define INT magnus_ab_INTegro_seclorum_nascitur_ordo
+#include <windows.h>
+#undef INT
+
+/* windows does not have statically-initialized mutexes---fake a
+ spinlock */
+static volatile LONG planner_mutex = 0;
+
+static void lock_planner_mutex(void)
+{
+ while (InterlockedExchange(&planner_mutex, 1) == 1) {
+ YieldProcessor();
+ Sleep(0);
+ }
+}
+
+static void unlock_planner_mutex(void)
+{
+ LONG old = InterlockedExchange(&planner_mutex, 0);
+ A(old == 1);
+}
+#else
+#include <pthread.h>
+
+static pthread_mutex_t planner_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+static void lock_planner_mutex(void)
@@ -18,6 +46,7 @@
+{
+ pthread_mutex_unlock(&planner_mutex);
+}
+#endif
+
+static planner_hook_t before_planner_hook = lock_planner_mutex, after_planner_hook = unlock_planner_mutex;


Loading…
Cancel
Save