source: libusb1/vendor/current/libusb/os/threads_windows.h@ 1876

Last change on this file since 1876 was 1876, checked in by Silvan Scherrer, 8 years ago

libusb: import version 1.0.16

File size: 2.8 KB
Line 
1/*
2 * libusb synchronization on Microsoft Windows
3 *
4 * Copyright (C) 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#include <windows.h>
25
26#define usbi_mutex_static_t volatile LONG
27#define USBI_MUTEX_INITIALIZER 0
28
29#define usbi_mutex_t HANDLE
30
31struct usbi_cond_perthread {
32 struct list_head list;
33 DWORD tid;
34 HANDLE event;
35};
36struct usbi_cond_t_ {
37 // Every time a thread touches the CV, it winds up in one of these lists.
38 // It stays there until the CV is destroyed, even if the thread
39 // terminates.
40 struct list_head waiters;
41 struct list_head not_waiting;
42};
43typedef struct usbi_cond_t_ usbi_cond_t;
44
45// We *were* getting timespec from pthread.h:
46#if (!defined(HAVE_STRUCT_TIMESPEC) && !defined(_TIMESPEC_DEFINED))
47#define HAVE_STRUCT_TIMESPEC 1
48#define _TIMESPEC_DEFINED 1
49struct timespec {
50 long tv_sec;
51 long tv_nsec;
52};
53#endif /* HAVE_STRUCT_TIMESPEC | _TIMESPEC_DEFINED */
54
55// We *were* getting ETIMEDOUT from pthread.h:
56#ifndef ETIMEDOUT
57# define ETIMEDOUT 10060 /* This is the value in winsock.h. */
58#endif
59
60#define usbi_mutexattr_t void
61#define usbi_condattr_t void
62
63// all Windows mutexes are recursive
64#define usbi_mutex_init_recursive(mutex, attr) usbi_mutex_init((mutex), (attr))
65
66int usbi_mutex_static_lock(usbi_mutex_static_t *mutex);
67int usbi_mutex_static_unlock(usbi_mutex_static_t *mutex);
68
69
70int usbi_mutex_init(usbi_mutex_t *mutex,
71 const usbi_mutexattr_t *attr);
72int usbi_mutex_lock(usbi_mutex_t *mutex);
73int usbi_mutex_unlock(usbi_mutex_t *mutex);
74int usbi_mutex_trylock(usbi_mutex_t *mutex);
75int usbi_mutex_destroy(usbi_mutex_t *mutex);
76
77int usbi_cond_init(usbi_cond_t *cond,
78 const usbi_condattr_t *attr);
79int usbi_cond_destroy(usbi_cond_t *cond);
80int usbi_cond_wait(usbi_cond_t *cond, usbi_mutex_t *mutex);
81int usbi_cond_timedwait(usbi_cond_t *cond,
82 usbi_mutex_t *mutex,
83 const struct timespec *abstime);
84int usbi_cond_broadcast(usbi_cond_t *cond);
85int usbi_cond_signal(usbi_cond_t *cond);
86
87#endif /* LIBUSB_THREADS_WINDOWS_H */
88
Note: See TracBrowser for help on using the repository browser.