External, Non-PPA KXStudio Repository
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.5KB

  1. diff --git a/api/apiplan.c b/api/apiplan.c
  2. index b8642a9..c7df958 100644
  3. --- a/api/apiplan.c
  4. +++ b/api/apiplan.c
  5. @@ -20,7 +20,50 @@
  6. #include "api/api.h"
  7. -static planner_hook_t before_planner_hook = 0, after_planner_hook = 0;
  8. +#if defined(__WIN32__) || defined(_WIN32) || defined(_WINDOWS)
  9. +/* hack: windef.h defines INT for its own purposes and this causes
  10. + a conflict with our own INT in ifftw.h. Divert the windows
  11. + definition into another name unlikely to cause a conflict */
  12. +#define INT magnus_ab_INTegro_seclorum_nascitur_ordo
  13. +#include <windows.h>
  14. +#include <process.h>
  15. +#include <intrin.h>
  16. +#undef INT
  17. +
  18. +/* windows does not have statically-initialized mutexes---fake a
  19. + spinlock */
  20. +static volatile LONG planner_mutex = 0;
  21. +
  22. +static void lock_planner_mutex(void)
  23. +{
  24. + while (InterlockedExchange(&planner_mutex, 1) == 1) {
  25. + YieldProcessor();
  26. + Sleep(0);
  27. + }
  28. +}
  29. +
  30. +static void unlock_planner_mutex(void)
  31. +{
  32. + LONG old = InterlockedExchange(&planner_mutex, 0);
  33. + A(old == 1);
  34. +}
  35. +#else
  36. +#include <pthread.h>
  37. +
  38. +static pthread_mutex_t planner_mutex = PTHREAD_MUTEX_INITIALIZER;
  39. +
  40. +static void lock_planner_mutex(void)
  41. +{
  42. + pthread_mutex_lock(&planner_mutex);
  43. +}
  44. +
  45. +static void unlock_planner_mutex(void)
  46. +{
  47. + pthread_mutex_unlock(&planner_mutex);
  48. +}
  49. +#endif
  50. +
  51. +static planner_hook_t before_planner_hook = lock_planner_mutex, after_planner_hook = unlock_planner_mutex;
  52. void X(set_planner_hooks)(planner_hook_t before, planner_hook_t after)
  53. {