usb 2.17.0 → 3.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/LICENSE +18 -4
  2. package/README.md +25 -516
  3. package/dist/index.d.ts +67 -13
  4. package/dist/index.js +333 -64
  5. package/index.d.ts +89 -0
  6. package/index.js +583 -0
  7. package/package.json +53 -33
  8. package/CHANGELOG.md +0 -294
  9. package/binding.gyp +0 -128
  10. package/dist/index.js.map +0 -1
  11. package/dist/usb/bindings.d.ts +0 -266
  12. package/dist/usb/bindings.js +0 -10
  13. package/dist/usb/bindings.js.map +0 -1
  14. package/dist/usb/capability.d.ts +0 -13
  15. package/dist/usb/capability.js +0 -17
  16. package/dist/usb/capability.js.map +0 -1
  17. package/dist/usb/descriptors.d.ts +0 -128
  18. package/dist/usb/descriptors.js +0 -3
  19. package/dist/usb/descriptors.js.map +0 -1
  20. package/dist/usb/device.d.ts +0 -100
  21. package/dist/usb/device.js +0 -297
  22. package/dist/usb/device.js.map +0 -1
  23. package/dist/usb/endpoint.d.ts +0 -94
  24. package/dist/usb/endpoint.js +0 -219
  25. package/dist/usb/endpoint.js.map +0 -1
  26. package/dist/usb/index.d.ts +0 -31
  27. package/dist/usb/index.js +0 -116
  28. package/dist/usb/index.js.map +0 -1
  29. package/dist/usb/interface.d.ts +0 -80
  30. package/dist/usb/interface.js +0 -133
  31. package/dist/usb/interface.js.map +0 -1
  32. package/dist/webusb/index.d.ts +0 -64
  33. package/dist/webusb/index.js +0 -295
  34. package/dist/webusb/index.js.map +0 -1
  35. package/dist/webusb/webusb-device.d.ts +0 -54
  36. package/dist/webusb/webusb-device.js +0 -434
  37. package/dist/webusb/webusb-device.js.map +0 -1
  38. package/libusb/.clang-tidy +0 -34
  39. package/libusb/.codespellrc +0 -3
  40. package/libusb/.private/README.txt +0 -5
  41. package/libusb/.private/appveyor_build.sh +0 -26
  42. package/libusb/.private/bm.sh +0 -54
  43. package/libusb/.private/ci-build.sh +0 -92
  44. package/libusb/.private/ci-container-build.sh +0 -67
  45. package/libusb/.private/post-rewrite.sh +0 -32
  46. package/libusb/.private/pre-commit.sh +0 -52
  47. package/libusb/.private/wbs.txt +0 -43
  48. package/libusb/.travis.yml +0 -58
  49. package/libusb/AUTHORS +0 -231
  50. package/libusb/COPYING +0 -504
  51. package/libusb/ChangeLog +0 -365
  52. package/libusb/HACKING +0 -25
  53. package/libusb/INSTALL_WIN.txt +0 -52
  54. package/libusb/KEYS +0 -123
  55. package/libusb/Makefile.am +0 -50
  56. package/libusb/NEWS +0 -2
  57. package/libusb/PORTING +0 -94
  58. package/libusb/README +0 -29
  59. package/libusb/README.git +0 -41
  60. package/libusb/TODO +0 -2
  61. package/libusb/Xcode/common.xcconfig +0 -92
  62. package/libusb/Xcode/config.h +0 -31
  63. package/libusb/Xcode/debug.xcconfig +0 -32
  64. package/libusb/Xcode/libusb.xcconfig +0 -21
  65. package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +0 -1391
  66. package/libusb/Xcode/libusb_debug.xcconfig +0 -21
  67. package/libusb/Xcode/libusb_release.xcconfig +0 -21
  68. package/libusb/Xcode/release.xcconfig +0 -30
  69. package/libusb/android/README +0 -152
  70. package/libusb/android/config.h +0 -55
  71. package/libusb/android/examples/unrooted_android.c +0 -301
  72. package/libusb/android/examples/unrooted_android.h +0 -36
  73. package/libusb/android/jni/Android.mk +0 -23
  74. package/libusb/android/jni/Application.mk +0 -40
  75. package/libusb/android/jni/examples.mk +0 -168
  76. package/libusb/android/jni/libusb.mk +0 -60
  77. package/libusb/android/jni/tests.mk +0 -45
  78. package/libusb/appveyor.yml +0 -108
  79. package/libusb/autogen.sh +0 -10
  80. package/libusb/bootstrap.sh +0 -10
  81. package/libusb/configure.ac +0 -450
  82. package/libusb/doc/Makefile.in +0 -22
  83. package/libusb/doc/doxygen.cfg.in +0 -2571
  84. package/libusb/doc/libusb.png +0 -0
  85. package/libusb/examples/Makefile.am +0 -12
  86. package/libusb/examples/dpfp.c +0 -711
  87. package/libusb/examples/ezusb.c +0 -846
  88. package/libusb/examples/ezusb.h +0 -109
  89. package/libusb/examples/fxload.c +0 -310
  90. package/libusb/examples/hotplugtest.c +0 -147
  91. package/libusb/examples/listdevs.c +0 -73
  92. package/libusb/examples/sam3u_benchmark.c +0 -228
  93. package/libusb/examples/testlibusb.c +0 -312
  94. package/libusb/examples/xusb.c +0 -1254
  95. package/libusb/libusb/Makefile.am +0 -98
  96. package/libusb/libusb/Makefile.am.extra +0 -26
  97. package/libusb/libusb/core.c +0 -2925
  98. package/libusb/libusb/descriptor.c +0 -1558
  99. package/libusb/libusb/hotplug.c +0 -489
  100. package/libusb/libusb/io.c +0 -2865
  101. package/libusb/libusb/libusb-1.0.def +0 -199
  102. package/libusb/libusb/libusb-1.0.rc +0 -53
  103. package/libusb/libusb/libusb.h +0 -2421
  104. package/libusb/libusb/libusbi.h +0 -1535
  105. package/libusb/libusb/os/darwin_usb.c +0 -2977
  106. package/libusb/libusb/os/darwin_usb.h +0 -156
  107. package/libusb/libusb/os/emscripten_webusb.cpp +0 -875
  108. package/libusb/libusb/os/events_posix.c +0 -340
  109. package/libusb/libusb/os/events_posix.h +0 -62
  110. package/libusb/libusb/os/events_windows.c +0 -214
  111. package/libusb/libusb/os/events_windows.h +0 -46
  112. package/libusb/libusb/os/haiku_pollfs.cpp +0 -372
  113. package/libusb/libusb/os/haiku_usb.h +0 -113
  114. package/libusb/libusb/os/haiku_usb_backend.cpp +0 -532
  115. package/libusb/libusb/os/haiku_usb_raw.cpp +0 -231
  116. package/libusb/libusb/os/haiku_usb_raw.h +0 -188
  117. package/libusb/libusb/os/linux_netlink.c +0 -401
  118. package/libusb/libusb/os/linux_udev.c +0 -321
  119. package/libusb/libusb/os/linux_usbfs.c +0 -2829
  120. package/libusb/libusb/os/linux_usbfs.h +0 -221
  121. package/libusb/libusb/os/netbsd_usb.c +0 -617
  122. package/libusb/libusb/os/null_usb.c +0 -111
  123. package/libusb/libusb/os/openbsd_usb.c +0 -700
  124. package/libusb/libusb/os/sunos_usb.c +0 -1619
  125. package/libusb/libusb/os/sunos_usb.h +0 -79
  126. package/libusb/libusb/os/threads_posix.c +0 -126
  127. package/libusb/libusb/os/threads_posix.h +0 -98
  128. package/libusb/libusb/os/threads_windows.c +0 -40
  129. package/libusb/libusb/os/threads_windows.h +0 -113
  130. package/libusb/libusb/os/windows_common.c +0 -923
  131. package/libusb/libusb/os/windows_common.h +0 -424
  132. package/libusb/libusb/os/windows_usbdk.c +0 -724
  133. package/libusb/libusb/os/windows_usbdk.h +0 -106
  134. package/libusb/libusb/os/windows_winusb.c +0 -4766
  135. package/libusb/libusb/os/windows_winusb.h +0 -787
  136. package/libusb/libusb/strerror.c +0 -223
  137. package/libusb/libusb/sync.c +0 -342
  138. package/libusb/libusb/version.h +0 -18
  139. package/libusb/libusb/version_nano.h +0 -1
  140. package/libusb/libusb-1.0.pc.in +0 -11
  141. package/libusb/msvc/Base.props +0 -60
  142. package/libusb/msvc/Configuration.Application.props +0 -7
  143. package/libusb/msvc/Configuration.Base.props +0 -47
  144. package/libusb/msvc/Configuration.DynamicLibrary.props +0 -21
  145. package/libusb/msvc/Configuration.StaticLibrary.props +0 -7
  146. package/libusb/msvc/ProjectConfigurations.Base.props +0 -69
  147. package/libusb/msvc/build_all.ps1 +0 -17
  148. package/libusb/msvc/config.h +0 -58
  149. package/libusb/msvc/dpfp.vcxproj +0 -33
  150. package/libusb/msvc/dpfp_threaded.vcxproj +0 -38
  151. package/libusb/msvc/fxload.vcxproj +0 -46
  152. package/libusb/msvc/getopt/getopt.c +0 -1060
  153. package/libusb/msvc/getopt/getopt.h +0 -180
  154. package/libusb/msvc/getopt/getopt1.c +0 -188
  155. package/libusb/msvc/getopt.vcxproj +0 -33
  156. package/libusb/msvc/hotplugtest.vcxproj +0 -32
  157. package/libusb/msvc/init_context.vcxproj +0 -35
  158. package/libusb/msvc/libusb.sln +0 -542
  159. package/libusb/msvc/libusb_dll.vcxproj +0 -61
  160. package/libusb/msvc/libusb_static.vcxproj +0 -49
  161. package/libusb/msvc/listdevs.vcxproj +0 -32
  162. package/libusb/msvc/sam3u_benchmark.vcxproj +0 -33
  163. package/libusb/msvc/set_option.vcxproj +0 -35
  164. package/libusb/msvc/stress.vcxproj +0 -35
  165. package/libusb/msvc/stress_mt.vcxproj +0 -33
  166. package/libusb/msvc/testlibusb.vcxproj +0 -32
  167. package/libusb/msvc/xusb.vcxproj +0 -38
  168. package/libusb/tests/Makefile.am +0 -40
  169. package/libusb/tests/init_context.c +0 -153
  170. package/libusb/tests/libusb_testlib.h +0 -76
  171. package/libusb/tests/macos.c +0 -130
  172. package/libusb/tests/set_option.c +0 -253
  173. package/libusb/tests/stress.c +0 -172
  174. package/libusb/tests/stress_mt.c +0 -267
  175. package/libusb/tests/testlib.c +0 -184
  176. package/libusb/tests/umockdev.c +0 -1175
  177. package/libusb/tests/webusb-test-shim/index.js +0 -12
  178. package/libusb/tests/webusb-test-shim/package-lock.json +0 -50
  179. package/libusb/tests/webusb-test-shim/package.json +0 -10
  180. package/libusb.gypi +0 -154
  181. package/libusb_config/config.h +0 -1
  182. package/prebuilds/android-arm/node.napi.armv7.node +0 -0
  183. package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
  184. package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
  185. package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
  186. package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
  187. package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
  188. package/prebuilds/linux-ia32/node.napi.node +0 -0
  189. package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
  190. package/prebuilds/linux-x64/node.napi.musl.node +0 -0
  191. package/prebuilds/win32-arm64/node.napi.node +0 -0
  192. package/prebuilds/win32-ia32/node.napi.node +0 -0
  193. package/prebuilds/win32-x64/node.napi.node +0 -0
  194. package/src/device.cc +0 -439
  195. package/src/helpers.h +0 -64
  196. package/src/hotplug/hotplug.h +0 -22
  197. package/src/hotplug/libusb.cc +0 -90
  198. package/src/hotplug/windows.cc +0 -168
  199. package/src/node_usb.cc +0 -314
  200. package/src/node_usb.h +0 -131
  201. package/src/thread_name.cc +0 -79
  202. package/src/thread_name.h +0 -11
  203. package/src/transfer.cc +0 -143
  204. package/src/uv_async_queue.h +0 -41
  205. package/test/usb.coffee +0 -250
  206. package/test/webusb.coffee +0 -227
  207. package/test/worker.cjs +0 -13
@@ -1,79 +0,0 @@
1
- /*
2
- *
3
- * Copyright (c) 2016, Oracle and/or its affiliates.
4
- *
5
- * This library is free software; you can redistribute it and/or
6
- * modify it under the terms of the GNU Lesser General Public
7
- * License as published by the Free Software Foundation; either
8
- * version 2.1 of the License, or (at your option) any later version.
9
- *
10
- * This library is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- * Lesser General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU Lesser General Public
16
- * License along with this library; if not, write to the Free Software
17
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
- */
19
-
20
- #ifndef LIBUSB_SUNOS_H
21
- #define LIBUSB_SUNOS_H
22
-
23
- #include <libdevinfo.h>
24
- #include <pthread.h>
25
- #include "libusbi.h"
26
-
27
- #define READ 0
28
- #define WRITE 1
29
-
30
- typedef struct sunos_device_priv {
31
- uint8_t cfgvalue; /* active config value */
32
- uint8_t *raw_cfgdescr; /* active config descriptor */
33
- char *ugenpath; /* name of the ugen(4) node */
34
- char *phypath; /* physical path */
35
- } sunos_dev_priv_t;
36
-
37
- typedef struct endpoint {
38
- int datafd; /* data file */
39
- int statfd; /* state file */
40
- } sunos_ep_priv_t;
41
-
42
- typedef struct sunos_device_handle_priv {
43
- uint8_t altsetting[USB_MAXINTERFACES]; /* a interface's alt */
44
- uint8_t config_index;
45
- sunos_ep_priv_t eps[USB_MAXENDPOINTS];
46
- sunos_dev_priv_t *dpriv; /* device private */
47
- } sunos_dev_handle_priv_t;
48
-
49
- typedef struct sunos_transfer_priv {
50
- struct aiocb aiocb;
51
- struct libusb_transfer *transfer;
52
- } sunos_xfer_priv_t;
53
-
54
- struct node_args {
55
- struct libusb_context *ctx;
56
- struct discovered_devs **discdevs;
57
- const char *last_ugenpath;
58
- di_devlink_handle_t dlink_hdl;
59
- };
60
-
61
- struct devlink_cbarg {
62
- struct node_args *nargs; /* di node walk arguments */
63
- di_node_t myself; /* the di node */
64
- di_minor_t minor;
65
- };
66
-
67
- typedef struct walk_link {
68
- char *path;
69
- int len;
70
- char **linkpp;
71
- } walk_link_t;
72
-
73
- /* AIO callback args */
74
- struct aio_callback_args{
75
- struct libusb_transfer *transfer;
76
- struct aiocb aiocb;
77
- };
78
-
79
- #endif /* LIBUSB_SUNOS_H */
@@ -1,126 +0,0 @@
1
- /*
2
- * libusb synchronization using POSIX Threads
3
- *
4
- * Copyright © 2011 Vitali Lovich <vlovich@aliph.com>
5
- * Copyright © 2011 Peter Stuge <peter@stuge.se>
6
- *
7
- * This library is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * This library is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with this library; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- */
21
-
22
- #include "libusbi.h"
23
-
24
- #include <errno.h>
25
- #include <limits.h>
26
- #if defined(__ANDROID__)
27
- # include <unistd.h>
28
- #elif defined(__HAIKU__)
29
- # include <os/kernel/OS.h>
30
- #elif defined(__linux__)
31
- # include <sys/syscall.h>
32
- # include <unistd.h>
33
- #elif defined(__NetBSD__)
34
- # include <lwp.h>
35
- #elif defined(__OpenBSD__)
36
- # include <unistd.h>
37
- #elif defined(__sun__)
38
- # include <sys/lwp.h>
39
- #endif
40
-
41
- void usbi_cond_init(pthread_cond_t *cond)
42
- {
43
- #ifdef HAVE_PTHREAD_CONDATTR_SETCLOCK
44
- pthread_condattr_t condattr;
45
-
46
- PTHREAD_CHECK(pthread_condattr_init(&condattr));
47
- PTHREAD_CHECK(pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC));
48
- PTHREAD_CHECK(pthread_cond_init(cond, &condattr));
49
- PTHREAD_CHECK(pthread_condattr_destroy(&condattr));
50
- #else
51
- PTHREAD_CHECK(pthread_cond_init(cond, NULL));
52
- #endif
53
- }
54
-
55
- int usbi_cond_timedwait(pthread_cond_t *cond,
56
- pthread_mutex_t *mutex, const struct timeval *tv)
57
- {
58
- struct timespec timeout;
59
- int r;
60
-
61
- #ifdef HAVE_PTHREAD_CONDATTR_SETCLOCK
62
- usbi_get_monotonic_time(&timeout);
63
- #else
64
- usbi_get_real_time(&timeout);
65
- #endif
66
-
67
- timeout.tv_sec += tv->tv_sec;
68
- timeout.tv_nsec += tv->tv_usec * 1000L;
69
- if (timeout.tv_nsec >= NSEC_PER_SEC) {
70
- timeout.tv_nsec -= NSEC_PER_SEC;
71
- timeout.tv_sec++;
72
- }
73
-
74
- r = pthread_cond_timedwait(cond, mutex, &timeout);
75
- if (r == 0)
76
- return 0;
77
- else if (r == ETIMEDOUT)
78
- return LIBUSB_ERROR_TIMEOUT;
79
- else
80
- return LIBUSB_ERROR_OTHER;
81
- }
82
-
83
- unsigned long usbi_get_tid(void)
84
- {
85
- static _Thread_local unsigned long tl_tid;
86
- unsigned long tid;
87
-
88
- if (tl_tid)
89
- return tl_tid;
90
-
91
- #if defined(__ANDROID__)
92
- tid = (unsigned long)gettid();
93
- #elif defined(__APPLE__)
94
- #ifdef HAVE_PTHREAD_THREADID_NP
95
- uint64_t thread_id;
96
-
97
- if (pthread_threadid_np(NULL, &thread_id) == 0)
98
- tid = (unsigned long)thread_id;
99
- else
100
- tid = ULONG_MAX;
101
- #else
102
- tid = (unsigned long)pthread_mach_thread_np(pthread_self());
103
- #endif
104
- #elif defined(__HAIKU__)
105
- tid = (unsigned long)get_pthread_thread_id(pthread_self());
106
- #elif defined(__linux__)
107
- tid = (unsigned long)syscall(SYS_gettid);
108
- #elif defined(__NetBSD__)
109
- tid = (unsigned long)_lwp_self();
110
- #elif defined(__OpenBSD__)
111
- tid = (unsigned long)getthrid();
112
- #elif defined(__sun__)
113
- tid = (unsigned long)_lwp_self();
114
- #else
115
- tid = ULONG_MAX;
116
- #endif
117
-
118
- if (tid == ULONG_MAX) {
119
- /* If we don't have a thread ID, at least return a unique
120
- * value that can be used to distinguish individual
121
- * threads. */
122
- tid = (unsigned long)(uintptr_t)pthread_self();
123
- }
124
-
125
- return tl_tid = tid;
126
- }
@@ -1,98 +0,0 @@
1
- /*
2
- * libusb synchronization using POSIX Threads
3
- *
4
- * Copyright © 2010 Peter Stuge <peter@stuge.se>
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_POSIX_H
22
- #define LIBUSB_THREADS_POSIX_H
23
-
24
- #include <pthread.h>
25
-
26
- #define PTHREAD_CHECK(expression) ASSERT_EQ(expression, 0)
27
-
28
- #define USBI_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
29
- typedef pthread_mutex_t usbi_mutex_static_t;
30
- static inline void usbi_mutex_static_lock(usbi_mutex_static_t *mutex)
31
- {
32
- PTHREAD_CHECK(pthread_mutex_lock(mutex));
33
- }
34
- static inline void usbi_mutex_static_unlock(usbi_mutex_static_t *mutex)
35
- {
36
- PTHREAD_CHECK(pthread_mutex_unlock(mutex));
37
- }
38
-
39
- typedef pthread_mutex_t usbi_mutex_t;
40
- static inline void usbi_mutex_init(usbi_mutex_t *mutex)
41
- {
42
- PTHREAD_CHECK(pthread_mutex_init(mutex, NULL));
43
- }
44
- static inline void usbi_mutex_lock(usbi_mutex_t *mutex)
45
- {
46
- PTHREAD_CHECK(pthread_mutex_lock(mutex));
47
- }
48
- static inline void usbi_mutex_unlock(usbi_mutex_t *mutex)
49
- {
50
- PTHREAD_CHECK(pthread_mutex_unlock(mutex));
51
- }
52
- static inline int usbi_mutex_trylock(usbi_mutex_t *mutex)
53
- {
54
- return pthread_mutex_trylock(mutex) == 0;
55
- }
56
- static inline void usbi_mutex_destroy(usbi_mutex_t *mutex)
57
- {
58
- PTHREAD_CHECK(pthread_mutex_destroy(mutex));
59
- }
60
-
61
- typedef pthread_cond_t usbi_cond_t;
62
- void usbi_cond_init(pthread_cond_t *cond);
63
- static inline void usbi_cond_wait(usbi_cond_t *cond, usbi_mutex_t *mutex)
64
- {
65
- PTHREAD_CHECK(pthread_cond_wait(cond, mutex));
66
- }
67
- int usbi_cond_timedwait(usbi_cond_t *cond,
68
- usbi_mutex_t *mutex, const struct timeval *tv);
69
- static inline void usbi_cond_broadcast(usbi_cond_t *cond)
70
- {
71
- PTHREAD_CHECK(pthread_cond_broadcast(cond));
72
- }
73
- static inline void usbi_cond_destroy(usbi_cond_t *cond)
74
- {
75
- PTHREAD_CHECK(pthread_cond_destroy(cond));
76
- }
77
-
78
- typedef pthread_key_t usbi_tls_key_t;
79
- static inline void usbi_tls_key_create(usbi_tls_key_t *key)
80
- {
81
- PTHREAD_CHECK(pthread_key_create(key, NULL));
82
- }
83
- static inline void *usbi_tls_key_get(usbi_tls_key_t key)
84
- {
85
- return pthread_getspecific(key);
86
- }
87
- static inline void usbi_tls_key_set(usbi_tls_key_t key, void *ptr)
88
- {
89
- PTHREAD_CHECK(pthread_setspecific(key, ptr));
90
- }
91
- static inline void usbi_tls_key_delete(usbi_tls_key_t key)
92
- {
93
- PTHREAD_CHECK(pthread_key_delete(key));
94
- }
95
-
96
- unsigned long usbi_get_tid(void);
97
-
98
- #endif /* LIBUSB_THREADS_POSIX_H */
@@ -1,40 +0,0 @@
1
- /*
2
- * libusb synchronization on Microsoft Windows
3
- *
4
- * Copyright © 2010 Michael Plante <michael.plante@gmail.com>
5
- * Copyright © 2020 Chris Dickens <christopher.a.dickens@gmail.com>
6
- *
7
- * This library is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * This library is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with this library; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- */
21
-
22
- #include "libusbi.h"
23
-
24
- int usbi_cond_timedwait(usbi_cond_t *cond,
25
- usbi_mutex_t *mutex, const struct timeval *tv)
26
- {
27
- DWORD millis;
28
-
29
- millis = (DWORD)(tv->tv_sec * 1000L) + (tv->tv_usec / 1000L);
30
- /* round up to next millisecond */
31
- if (tv->tv_usec % 1000L)
32
- millis++;
33
-
34
- if (SleepConditionVariableCS(cond, mutex, millis))
35
- return 0;
36
- else if (GetLastError() == ERROR_TIMEOUT)
37
- return LIBUSB_ERROR_TIMEOUT;
38
- else
39
- return LIBUSB_ERROR_OTHER;
40
- }
@@ -1,113 +0,0 @@
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 WINAPI_CHECK(expression) ASSERT_NE(expression, 0)
25
-
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)
29
- {
30
- while (InterlockedExchange(mutex, 1L) == 1L)
31
- SleepEx(0, TRUE);
32
- }
33
- static inline void usbi_mutex_static_unlock(usbi_mutex_static_t *mutex)
34
- {
35
- InterlockedExchange(mutex, 0L);
36
- }
37
-
38
- typedef CRITICAL_SECTION usbi_mutex_t;
39
- static inline void usbi_mutex_init(usbi_mutex_t *mutex)
40
- {
41
- InitializeCriticalSection(mutex);
42
- }
43
- static inline void usbi_mutex_lock(usbi_mutex_t *mutex)
44
- {
45
- EnterCriticalSection(mutex);
46
- }
47
- static inline void usbi_mutex_unlock(usbi_mutex_t *mutex)
48
- {
49
- LeaveCriticalSection(mutex);
50
- }
51
- static inline int usbi_mutex_trylock(usbi_mutex_t *mutex)
52
- {
53
- return TryEnterCriticalSection(mutex) != 0;
54
- }
55
- static inline void usbi_mutex_destroy(usbi_mutex_t *mutex)
56
- {
57
- DeleteCriticalSection(mutex);
58
- }
59
-
60
- #if !defined(HAVE_STRUCT_TIMESPEC) && !defined(_TIMESPEC_DEFINED)
61
- #define HAVE_STRUCT_TIMESPEC 1
62
- #define _TIMESPEC_DEFINED 1
63
- struct timespec {
64
- long tv_sec;
65
- long tv_nsec;
66
- };
67
- #endif /* HAVE_STRUCT_TIMESPEC || _TIMESPEC_DEFINED */
68
-
69
- typedef CONDITION_VARIABLE usbi_cond_t;
70
- static inline void usbi_cond_init(usbi_cond_t *cond)
71
- {
72
- InitializeConditionVariable(cond);
73
- }
74
- static inline void usbi_cond_wait(usbi_cond_t *cond, usbi_mutex_t *mutex)
75
- {
76
- WINAPI_CHECK(SleepConditionVariableCS(cond, mutex, INFINITE));
77
- }
78
- int usbi_cond_timedwait(usbi_cond_t *cond,
79
- usbi_mutex_t *mutex, const struct timeval *tv);
80
- static inline void usbi_cond_broadcast(usbi_cond_t *cond)
81
- {
82
- WakeAllConditionVariable(cond);
83
- }
84
- static inline void usbi_cond_destroy(usbi_cond_t *cond)
85
- {
86
- UNUSED(cond);
87
- }
88
-
89
- typedef DWORD usbi_tls_key_t;
90
- static inline void usbi_tls_key_create(usbi_tls_key_t *key)
91
- {
92
- *key = TlsAlloc();
93
- assert(*key != TLS_OUT_OF_INDEXES);
94
- }
95
- static inline void *usbi_tls_key_get(usbi_tls_key_t key)
96
- {
97
- return TlsGetValue(key);
98
- }
99
- static inline void usbi_tls_key_set(usbi_tls_key_t key, void *ptr)
100
- {
101
- WINAPI_CHECK(TlsSetValue(key, ptr));
102
- }
103
- static inline void usbi_tls_key_delete(usbi_tls_key_t key)
104
- {
105
- WINAPI_CHECK(TlsFree(key));
106
- }
107
-
108
- static inline unsigned long usbi_get_tid(void)
109
- {
110
- return (unsigned long)GetCurrentThreadId();
111
- }
112
-
113
- #endif /* LIBUSB_THREADS_WINDOWS_H */