diff options
-rw-r--r-- | src/threading.c | 10 | ||||
-rw-r--r-- | src/threading.h | 22 |
2 files changed, 20 insertions, 12 deletions
diff --git a/src/threading.c b/src/threading.c index 5a3e64b..3e181ba 100644 --- a/src/threading.c +++ b/src/threading.c | |||
@@ -248,7 +248,7 @@ static void prepare_timeout( struct timespec *ts, time_d abs_secs ) { | |||
248 | 248 | ||
249 | #if THREADAPI == THREADAPI_WINDOWS | 249 | #if THREADAPI == THREADAPI_WINDOWS |
250 | 250 | ||
251 | #if WINVER <= 0x0400 // Windows NT4: Use Mutexes with Events | 251 | #if _WIN32_WINNT < 0x0600 // CONDITION_VARIABLE aren't available |
252 | // | 252 | // |
253 | void MUTEX_INIT( MUTEX_T *ref ) { | 253 | void MUTEX_INIT( MUTEX_T *ref ) { |
254 | *ref= CreateMutex( NULL /*security attr*/, FALSE /*not locked*/, NULL ); | 254 | *ref= CreateMutex( NULL /*security attr*/, FALSE /*not locked*/, NULL ); |
@@ -270,7 +270,7 @@ static void prepare_timeout( struct timespec *ts, time_d abs_secs ) { | |||
270 | if (!ReleaseMutex(*ref)) | 270 | if (!ReleaseMutex(*ref)) |
271 | FAIL( "ReleaseMutex", GetLastError() ); | 271 | FAIL( "ReleaseMutex", GetLastError() ); |
272 | } | 272 | } |
273 | #endif // Windows NT4 | 273 | #endif // CONDITION_VARIABLE aren't available |
274 | 274 | ||
275 | static int const gs_prio_remap[] = | 275 | static int const gs_prio_remap[] = |
276 | { | 276 | { |
@@ -384,7 +384,7 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | |||
384 | #endif // !__GNUC__ | 384 | #endif // !__GNUC__ |
385 | } | 385 | } |
386 | 386 | ||
387 | #if WINVER <= 0x0400 // Windows NT4 | 387 | #if _WIN32_WINNT < 0x0600 // CONDITION_VARIABLE aren't available |
388 | 388 | ||
389 | void SIGNAL_INIT( SIGNAL_T* ref) | 389 | void SIGNAL_INIT( SIGNAL_T* ref) |
390 | { | 390 | { |
@@ -477,7 +477,7 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | |||
477 | FAIL( "WaitForSingleObject", GetLastError()); | 477 | FAIL( "WaitForSingleObject", GetLastError()); |
478 | } | 478 | } |
479 | 479 | ||
480 | #else // Windows Vista and above: condition variables exist, use them | 480 | #else // CONDITION_VARIABLE are available, use them |
481 | 481 | ||
482 | // | 482 | // |
483 | void SIGNAL_INIT( SIGNAL_T *ref ) | 483 | void SIGNAL_INIT( SIGNAL_T *ref ) |
@@ -534,7 +534,7 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | |||
534 | WakeAllConditionVariable( ref); | 534 | WakeAllConditionVariable( ref); |
535 | } | 535 | } |
536 | 536 | ||
537 | #endif // Windows Vista and above | 537 | #endif // CONDITION_VARIABLE are available |
538 | 538 | ||
539 | #else // THREADAPI == THREADAPI_PTHREAD | 539 | #else // THREADAPI == THREADAPI_PTHREAD |
540 | // PThread (Linux, OS X, ...) | 540 | // PThread (Linux, OS X, ...) |
diff --git a/src/threading.h b/src/threading.h index 0698355..bfa9ab8 100644 --- a/src/threading.h +++ b/src/threading.h | |||
@@ -59,25 +59,33 @@ enum e_status { PENDING, RUNNING, WAITING, DONE, ERROR_ST, CANCELLED }; | |||
59 | */ | 59 | */ |
60 | 60 | ||
61 | #if THREADAPI == THREADAPI_WINDOWS | 61 | #if THREADAPI == THREADAPI_WINDOWS |
62 | #if defined ( PLATFORM_XBOX) | 62 | #if defined( PLATFORM_XBOX) |
63 | #include <xtl.h> | 63 | #include <xtl.h> |
64 | #else // !PLATFORM_XBOX | 64 | #else // !PLATFORM_XBOX |
65 | #define WIN32_LEAN_AND_MEAN | 65 | #define WIN32_LEAN_AND_MEAN |
66 | // 'SignalObjectAndWait' needs this (targets Windows 2000 and above) | 66 | // CONDITION_VARIABLE needs version 0x0600+ |
67 | #ifndef _WIN32_WINNT // already defined by TDSM-Mingw64, so avoid a warning in that case | 67 | // _WIN32_WINNT value is already defined by MinGW, but not by MSVC |
68 | #define _WIN32_WINNT 0x0400 | 68 | #ifndef _WIN32_WINNT |
69 | #define _WIN32_WINNT 0x0600 | ||
69 | #endif // _WIN32_WINNT | 70 | #endif // _WIN32_WINNT |
70 | #include <windows.h> | 71 | #include <windows.h> |
71 | #endif // !PLATFORM_XBOX | 72 | #endif // !PLATFORM_XBOX |
72 | #include <process.h> | 73 | #include <process.h> |
73 | 74 | ||
75 | /* | ||
76 | #define XSTR(x) STR(x) | ||
77 | #define STR(x) #x | ||
78 | #pragma message( "The value of _WIN32_WINNT: " XSTR(_WIN32_WINNT)) | ||
79 | */ | ||
80 | |||
74 | // MSDN: http://msdn2.microsoft.com/en-us/library/ms684254.aspx | 81 | // MSDN: http://msdn2.microsoft.com/en-us/library/ms684254.aspx |
75 | // | 82 | // |
76 | // CRITICAL_SECTION can be used for simple code protection. Mutexes are | 83 | // CRITICAL_SECTION can be used for simple code protection. Mutexes are |
77 | // needed for use with the SIGNAL system. | 84 | // needed for use with the SIGNAL system. |
78 | // | 85 | // |
79 | 86 | ||
80 | #if WINVER <= 0x0400 // Windows NT4: use a signal | 87 | #if _WIN32_WINNT < 0x0600 // CONDITION_VARIABLE aren't available, use a signal |
88 | |||
81 | typedef struct | 89 | typedef struct |
82 | { | 90 | { |
83 | CRITICAL_SECTION signalCS; | 91 | CRITICAL_SECTION signalCS; |
@@ -94,7 +102,7 @@ enum e_status { PENDING, RUNNING, WAITING, DONE, ERROR_ST, CANCELLED }; | |||
94 | void MUTEX_LOCK( MUTEX_T* ref); | 102 | void MUTEX_LOCK( MUTEX_T* ref); |
95 | void MUTEX_UNLOCK( MUTEX_T* ref); | 103 | void MUTEX_UNLOCK( MUTEX_T* ref); |
96 | 104 | ||
97 | #else // Vista and above: use a condition variable | 105 | #else // CONDITION_VARIABLE are available, use them |
98 | 106 | ||
99 | #define SIGNAL_T CONDITION_VARIABLE | 107 | #define SIGNAL_T CONDITION_VARIABLE |
100 | #define MUTEX_T CRITICAL_SECTION | 108 | #define MUTEX_T CRITICAL_SECTION |
@@ -103,7 +111,7 @@ enum e_status { PENDING, RUNNING, WAITING, DONE, ERROR_ST, CANCELLED }; | |||
103 | #define MUTEX_LOCK( ref) EnterCriticalSection( ref) | 111 | #define MUTEX_LOCK( ref) EnterCriticalSection( ref) |
104 | #define MUTEX_UNLOCK( ref) LeaveCriticalSection( ref) | 112 | #define MUTEX_UNLOCK( ref) LeaveCriticalSection( ref) |
105 | 113 | ||
106 | #endif // // Vista and above | 114 | #endif // CONDITION_VARIABLE are available |
107 | 115 | ||
108 | #define MUTEX_RECURSIVE_INIT(ref) MUTEX_INIT(ref) /* always recursive in Win32 */ | 116 | #define MUTEX_RECURSIVE_INIT(ref) MUTEX_INIT(ref) /* always recursive in Win32 */ |
109 | 117 | ||