summaryrefslogtreecommitdiff
path: root/libusb/os/threads_windows.c
diff options
context:
space:
mode:
authorPete Batard <pbatard@gmail.com>2010-08-15 21:44:13 +0100
committerPete Batard <pbatard@gmail.com>2010-08-15 21:44:13 +0100
commit3cbb8af8742f1384f25df84b3d4047983cbce709 (patch)
tree432ceef3ad35829fb62c8bc95e1baf863057c2ce /libusb/os/threads_windows.c
parent689d78a0631b3ce2e341a947df0151f58e5ff21e (diff)
downloadlibusb-3cbb8af8742f1384f25df84b3d4047983cbce709.tar.gz
added Workaround for MinGW-w64 multilib bug
* current MinGW-w64 32 bit headers (winbase.h) are missing the WINAPI qualifier on Interlocked### calls * this results in missing decorations on symbols and failed linking as a result * this workaround hooks into kernel32.dll for these function calls to alleviate the issue
Diffstat (limited to 'libusb/os/threads_windows.c')
-rw-r--r--libusb/os/threads_windows.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/libusb/os/threads_windows.c b/libusb/os/threads_windows.c
index 8a29920..9d64fb0 100644
--- a/libusb/os/threads_windows.c
+++ b/libusb/os/threads_windows.c
@@ -25,6 +25,13 @@
#include "libusbi.h"
+// Workaround for MinGW-w64 multilib bug
+static LONG (WINAPI *pInterlockedExchange)(LONG volatile *, LONG) = NULL;
+#define INIT_INTERLOCKEDEXCHANGE if (pInterlockedExchange == NULL) { \
+ pInterlockedExchange = (LONG (WINAPI *)(LONG volatile *, LONG)) \
+ GetProcAddress(GetModuleHandle("KERNEL32"), "InterlockedExchange"); \
+ if (pInterlockedExchange == NULL) return ((errno=ENOENT)); \
+ }
int usbi_mutex_init(usbi_mutex_t *mutex,
const usbi_mutexattr_t *attr) {
@@ -68,7 +75,8 @@ int usbi_mutex_unlock(usbi_mutex_t *mutex) {
int usbi_mutex_static_lock(usbi_mutex_static_t *mutex) {
if(!mutex) return ((errno=EINVAL));
- while (InterlockedExchange((LONG *)mutex, 1) == 1) {
+ INIT_INTERLOCKEDEXCHANGE;
+ while (pInterlockedExchange((LONG *)mutex, 1) == 1) {
SleepEx(0, TRUE);
}
return 0;