21 #ifndef LIBUSB_THREADS_WINDOWS_H 22 #define LIBUSB_THREADS_WINDOWS_H 26 #define USBI_MUTEX_INITIALIZER 0L 27 typedef LONG usbi_mutex_static_t;
28 static inline void usbi_mutex_static_lock(usbi_mutex_static_t *mutex)
30 while (InterlockedExchange(mutex, 1L) == 1L)
33 static inline void usbi_mutex_static_unlock(usbi_mutex_static_t *mutex)
35 InterlockedExchange(mutex, 0L);
38 typedef CRITICAL_SECTION usbi_mutex_t;
39 static inline int usbi_mutex_init(usbi_mutex_t *mutex)
41 InitializeCriticalSection(mutex);
44 static inline void usbi_mutex_lock(usbi_mutex_t *mutex)
46 EnterCriticalSection(mutex);
48 static inline void usbi_mutex_unlock(usbi_mutex_t *mutex)
50 LeaveCriticalSection(mutex);
52 static inline int usbi_mutex_trylock(usbi_mutex_t *mutex)
54 return !TryEnterCriticalSection(mutex);
56 static inline void usbi_mutex_destroy(usbi_mutex_t *mutex)
58 DeleteCriticalSection(mutex);
62 #if !defined(HAVE_STRUCT_TIMESPEC) && !defined(_TIMESPEC_DEFINED) 63 #define HAVE_STRUCT_TIMESPEC 1 64 #define _TIMESPEC_DEFINED 1 73 #define ETIMEDOUT 10060 76 typedef CONDITION_VARIABLE usbi_cond_t;
77 static inline void usbi_cond_init(usbi_cond_t *cond)
79 InitializeConditionVariable(cond);
81 static inline void usbi_cond_wait(usbi_cond_t *cond, usbi_mutex_t *mutex)
83 (
void)SleepConditionVariableCS(cond, mutex, INFINITE);
85 int usbi_cond_timedwait(usbi_cond_t *cond,
86 usbi_mutex_t *mutex,
const struct timeval *tv);
87 static inline void usbi_cond_broadcast(usbi_cond_t *cond)
89 WakeAllConditionVariable(cond);
91 static inline void usbi_cond_destroy(usbi_cond_t *cond)
96 typedef DWORD usbi_tls_key_t;
97 static inline void usbi_tls_key_create(usbi_tls_key_t *key)
101 static inline void *usbi_tls_key_get(usbi_tls_key_t key)
103 return TlsGetValue(key);
105 static inline void usbi_tls_key_set(usbi_tls_key_t key,
void *ptr)
107 (
void)TlsSetValue(key, ptr);
109 static inline void usbi_tls_key_delete(usbi_tls_key_t key)
114 static inline int usbi_get_tid(
void)
116 return (
int)GetCurrentThreadId();
typedef void(LIBUSB_CALL *libusb_transfer_cb_fn)(struct libusb_transfer *transfer)
Definition: threads_windows.h:65