• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * libusb synchronization on Microsoft Windows
3  *
4  * Copyright © 2010 Michael Plante <michael.plante@gmail.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef LIBUSB_THREADS_WINDOWS_H
22 #define LIBUSB_THREADS_WINDOWS_H
23 
24 #define usbi_mutex_static_t	volatile LONG
25 #define USBI_MUTEX_INITIALIZER	0
26 
27 #define usbi_mutex_t		HANDLE
28 
29 typedef struct usbi_cond {
30 	// Every time a thread touches the CV, it winds up in one of these lists.
31 	//   It stays there until the CV is destroyed, even if the thread terminates.
32 	struct list_head waiters;
33 	struct list_head not_waiting;
34 } usbi_cond_t;
35 
36 // We *were* getting timespec from pthread.h:
37 #if (!defined(HAVE_STRUCT_TIMESPEC) && !defined(_TIMESPEC_DEFINED))
38 #define HAVE_STRUCT_TIMESPEC 1
39 #define _TIMESPEC_DEFINED 1
40 struct timespec {
41 	long tv_sec;
42 	long tv_nsec;
43 };
44 #endif /* HAVE_STRUCT_TIMESPEC | _TIMESPEC_DEFINED */
45 
46 // We *were* getting ETIMEDOUT from pthread.h:
47 #ifndef ETIMEDOUT
48 #  define ETIMEDOUT 10060     /* This is the value in winsock.h. */
49 #endif
50 
51 #define usbi_tls_key_t		DWORD
52 
53 int usbi_mutex_static_lock(usbi_mutex_static_t *mutex);
54 int usbi_mutex_static_unlock(usbi_mutex_static_t *mutex);
55 
56 int usbi_mutex_init(usbi_mutex_t *mutex);
57 int usbi_mutex_lock(usbi_mutex_t *mutex);
58 int usbi_mutex_unlock(usbi_mutex_t *mutex);
59 int usbi_mutex_trylock(usbi_mutex_t *mutex);
60 int usbi_mutex_destroy(usbi_mutex_t *mutex);
61 
62 int usbi_cond_init(usbi_cond_t *cond);
63 int usbi_cond_wait(usbi_cond_t *cond, usbi_mutex_t *mutex);
64 int usbi_cond_timedwait(usbi_cond_t *cond,
65 	usbi_mutex_t *mutex, const struct timeval *tv);
66 int usbi_cond_broadcast(usbi_cond_t *cond);
67 int usbi_cond_destroy(usbi_cond_t *cond);
68 
69 int usbi_tls_key_create(usbi_tls_key_t *key);
70 void *usbi_tls_key_get(usbi_tls_key_t key);
71 int usbi_tls_key_set(usbi_tls_key_t key, void *value);
72 int usbi_tls_key_delete(usbi_tls_key_t key);
73 
74 int usbi_get_tid(void);
75 
76 #endif /* LIBUSB_THREADS_WINDOWS_H */
77