usb 2.1.3 → 2.3.1
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.
- package/CHANGELOG.md +23 -0
- package/README.md +19 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/usb/bindings.d.ts +4 -0
- package/dist/usb/device.js +5 -0
- package/dist/usb/device.js.map +1 -1
- package/dist/usb/index.js +7 -16
- package/dist/usb/index.js.map +1 -1
- package/dist/webusb/webusb-device.d.ts +0 -1
- package/dist/webusb/webusb-device.js +149 -243
- package/dist/webusb/webusb-device.js.map +1 -1
- package/libusb/.gitattributes +2 -6
- package/libusb/.private/appveyor_build.sh +22 -0
- package/libusb/.private/bm.sh +1 -1
- package/libusb/.private/ci-build.sh +67 -0
- package/libusb/.private/ci-container-build.sh +70 -0
- package/libusb/.private/post-rewrite.sh +5 -1
- package/libusb/.private/pre-commit.sh +5 -1
- package/libusb/.private/wbs.txt +4 -19
- package/libusb/.travis.yml +32 -23
- package/libusb/AUTHORS +86 -3
- package/libusb/ChangeLog +54 -3
- package/libusb/INSTALL_WIN.txt +22 -44
- package/libusb/Makefile.am +32 -10
- package/libusb/{README.md → README} +2 -2
- package/libusb/README.git +3 -3
- package/libusb/Xcode/common.xcconfig +23 -19
- package/libusb/Xcode/config.h +25 -13
- package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +511 -109
- package/libusb/android/README +90 -54
- package/libusb/android/config.h +23 -43
- package/libusb/android/examples/unrooted_android.c +300 -0
- package/libusb/android/examples/unrooted_android.h +36 -0
- package/libusb/android/jni/Android.mk +1 -1
- package/libusb/android/jni/Application.mk +16 -0
- package/libusb/android/jni/examples.mk +63 -29
- package/libusb/android/jni/libusb.mk +14 -8
- package/libusb/android/jni/tests.mk +13 -24
- package/libusb/appveyor.yml +73 -30
- package/libusb/autogen.sh +5 -3
- package/libusb/bootstrap.sh +6 -2
- package/libusb/configure.ac +314 -227
- package/libusb/doc/Makefile.in +22 -0
- package/libusb/doc/doxygen.cfg.in +460 -223
- package/libusb/examples/Makefile.am +6 -13
- package/libusb/examples/dpfp.c +276 -73
- package/libusb/examples/ezusb.c +18 -8
- package/libusb/examples/ezusb.h +6 -17
- package/libusb/examples/fxload.c +4 -5
- package/libusb/examples/hotplugtest.c +1 -1
- package/libusb/examples/sam3u_benchmark.c +59 -24
- package/libusb/examples/testlibusb.c +138 -104
- package/libusb/examples/xusb.c +26 -22
- package/libusb/libusb/Makefile.am +57 -70
- package/libusb/libusb/Makefile.am.extra +26 -0
- package/libusb/libusb/core.c +432 -423
- package/libusb/libusb/descriptor.c +365 -419
- package/libusb/libusb/hotplug.c +200 -104
- package/libusb/libusb/io.c +522 -535
- package/libusb/libusb/libusb-1.0.def +7 -3
- package/libusb/libusb/libusb-1.0.rc +1 -9
- package/libusb/libusb/libusb.h +302 -226
- package/libusb/libusb/libusbi.h +607 -316
- package/libusb/libusb/os/darwin_usb.c +703 -329
- package/libusb/libusb/os/darwin_usb.h +39 -15
- package/libusb/libusb/os/events_posix.c +300 -0
- package/libusb/libusb/os/events_posix.h +59 -0
- package/libusb/libusb/os/events_windows.c +214 -0
- package/libusb/{msvc/missing.h → libusb/os/events_windows.h} +25 -11
- package/libusb/libusb/os/haiku_pollfs.cpp +14 -9
- package/libusb/libusb/os/haiku_usb.h +12 -12
- package/libusb/libusb/os/haiku_usb_backend.cpp +36 -37
- package/libusb/libusb/os/haiku_usb_raw.cpp +80 -116
- package/libusb/libusb/os/linux_netlink.c +55 -63
- package/libusb/libusb/os/linux_udev.c +61 -69
- package/libusb/libusb/os/linux_usbfs.c +926 -1015
- package/libusb/libusb/os/linux_usbfs.h +74 -57
- package/libusb/libusb/os/netbsd_usb.c +103 -168
- package/libusb/libusb/os/null_usb.c +111 -0
- package/libusb/libusb/os/openbsd_usb.c +71 -120
- package/libusb/libusb/os/sunos_usb.c +289 -375
- package/libusb/libusb/os/sunos_usb.h +0 -1
- package/libusb/libusb/os/threads_posix.c +81 -32
- package/libusb/libusb/os/threads_posix.h +19 -23
- package/libusb/libusb/os/threads_windows.c +9 -95
- package/libusb/libusb/os/threads_windows.h +33 -31
- package/libusb/libusb/os/windows_common.c +915 -0
- package/libusb/libusb/os/windows_common.h +330 -42
- package/libusb/libusb/os/windows_usbdk.c +161 -267
- package/libusb/libusb/os/windows_usbdk.h +5 -2
- package/libusb/libusb/os/windows_winusb.c +1355 -1192
- package/libusb/libusb/os/windows_winusb.h +167 -167
- package/libusb/libusb/strerror.c +20 -30
- package/libusb/libusb/sync.c +20 -21
- package/libusb/libusb/version.h +1 -1
- package/libusb/libusb/version_nano.h +1 -1
- package/libusb/msvc/.gitattributes +3 -0
- package/libusb/msvc/config.h +27 -20
- package/libusb/msvc/{hotplugtest_2012.vcxproj → dpfp_2013.vcxproj} +14 -10
- package/libusb/msvc/dpfp_2013.vcxproj.filters +26 -0
- package/libusb/msvc/{hotplugtest_2010.vcxproj → dpfp_2015.vcxproj} +14 -9
- package/libusb/msvc/dpfp_2015.vcxproj.filters +26 -0
- package/libusb/msvc/dpfp_2017.vcxproj +106 -0
- package/libusb/msvc/dpfp_2017.vcxproj.filters +26 -0
- package/libusb/msvc/dpfp_2019.vcxproj +106 -0
- package/libusb/msvc/dpfp_2019.vcxproj.filters +26 -0
- package/libusb/msvc/dpfp_threaded_2013.vcxproj +87 -0
- package/libusb/msvc/dpfp_threaded_2013.vcxproj.filters +26 -0
- package/libusb/msvc/dpfp_threaded_2015.vcxproj +87 -0
- package/libusb/msvc/dpfp_threaded_2015.vcxproj.filters +26 -0
- package/libusb/msvc/dpfp_threaded_2017.vcxproj +106 -0
- package/libusb/msvc/dpfp_threaded_2017.vcxproj.filters +26 -0
- package/libusb/msvc/{fxload_2012.vcxproj → dpfp_threaded_2019.vcxproj} +32 -17
- package/libusb/msvc/dpfp_threaded_2019.vcxproj.filters +26 -0
- package/libusb/msvc/fxload_2013.vcxproj +6 -3
- package/libusb/msvc/fxload_2013.vcxproj.filters +35 -0
- package/libusb/msvc/fxload_2015.vcxproj +6 -3
- package/libusb/msvc/fxload_2015.vcxproj.filters +35 -0
- package/libusb/msvc/fxload_2017.vcxproj +6 -7
- package/libusb/msvc/fxload_2017.vcxproj.filters +35 -0
- package/libusb/msvc/{fxload_2010.vcxproj → fxload_2019.vcxproj} +29 -6
- package/libusb/msvc/fxload_2019.vcxproj.filters +35 -0
- package/libusb/{examples → msvc}/getopt/getopt.c +0 -0
- package/libusb/{examples → msvc}/getopt/getopt.h +0 -0
- package/libusb/{examples → msvc}/getopt/getopt1.c +0 -0
- package/libusb/msvc/getopt_2013.vcxproj +4 -5
- package/libusb/msvc/getopt_2013.vcxproj.filters +26 -0
- package/libusb/msvc/getopt_2015.vcxproj +4 -4
- package/libusb/msvc/getopt_2015.vcxproj.filters +26 -0
- package/libusb/msvc/getopt_2017.vcxproj +4 -10
- package/libusb/msvc/getopt_2017.vcxproj.filters +26 -0
- package/libusb/msvc/{getopt_2010.vcxproj → getopt_2019.vcxproj} +25 -5
- package/libusb/msvc/getopt_2019.vcxproj.filters +26 -0
- package/libusb/msvc/hotplugtest_2013.vcxproj +6 -3
- package/libusb/msvc/hotplugtest_2013.vcxproj.filters +23 -0
- package/libusb/msvc/hotplugtest_2015.vcxproj +6 -3
- package/libusb/msvc/hotplugtest_2015.vcxproj.filters +23 -0
- package/libusb/msvc/hotplugtest_2017.vcxproj +6 -7
- package/libusb/msvc/hotplugtest_2017.vcxproj.filters +23 -0
- package/libusb/msvc/hotplugtest_2019.vcxproj +105 -0
- package/libusb/msvc/hotplugtest_2019.vcxproj.filters +23 -0
- package/libusb/msvc/libusb_2013.sln +50 -20
- package/libusb/msvc/libusb_2015.sln +51 -21
- package/libusb/msvc/libusb_2017.sln +90 -36
- package/libusb/msvc/libusb_2019.sln +240 -0
- package/libusb/msvc/libusb_dll_2013.vcxproj +6 -9
- package/libusb/msvc/libusb_dll_2013.vcxproj.filters +94 -0
- package/libusb/msvc/libusb_dll_2015.vcxproj +6 -8
- package/libusb/msvc/libusb_dll_2015.vcxproj.filters +94 -0
- package/libusb/msvc/libusb_dll_2017.vcxproj +6 -16
- package/libusb/msvc/libusb_dll_2017.vcxproj.filters +94 -0
- package/libusb/msvc/{libusb_dll_2010.vcxproj → libusb_dll_2019.vcxproj} +27 -9
- package/libusb/msvc/libusb_dll_2019.vcxproj.filters +94 -0
- package/libusb/msvc/libusb_static_2013.vcxproj +5 -9
- package/libusb/msvc/libusb_static_2013.vcxproj.filters +80 -0
- package/libusb/msvc/libusb_static_2015.vcxproj +5 -8
- package/libusb/msvc/libusb_static_2015.vcxproj.filters +80 -0
- package/libusb/msvc/libusb_static_2017.vcxproj +5 -8
- package/libusb/msvc/libusb_static_2017.vcxproj.filters +80 -0
- package/libusb/msvc/{libusb_static_2010.vcxproj → libusb_static_2019.vcxproj} +26 -9
- package/libusb/msvc/libusb_static_2019.vcxproj.filters +80 -0
- package/libusb/msvc/listdevs_2013.vcxproj +6 -3
- package/libusb/msvc/listdevs_2013.vcxproj.filters +23 -0
- package/libusb/msvc/listdevs_2015.vcxproj +6 -3
- package/libusb/msvc/listdevs_2015.vcxproj.filters +23 -0
- package/libusb/msvc/listdevs_2017.vcxproj +6 -7
- package/libusb/msvc/listdevs_2017.vcxproj.filters +23 -0
- package/libusb/msvc/listdevs_2019.vcxproj +105 -0
- package/libusb/msvc/listdevs_2019.vcxproj.filters +23 -0
- package/libusb/msvc/{listdevs_2010.vcxproj → sam3u_benchmark_2013.vcxproj} +13 -8
- package/libusb/msvc/sam3u_benchmark_2013.vcxproj.filters +26 -0
- package/libusb/msvc/{listdevs_2012.vcxproj → sam3u_benchmark_2015.vcxproj} +13 -9
- package/libusb/msvc/sam3u_benchmark_2015.vcxproj.filters +26 -0
- package/libusb/msvc/sam3u_benchmark_2017.vcxproj +106 -0
- package/libusb/msvc/sam3u_benchmark_2017.vcxproj.filters +26 -0
- package/libusb/msvc/sam3u_benchmark_2019.vcxproj +106 -0
- package/libusb/msvc/sam3u_benchmark_2019.vcxproj.filters +26 -0
- package/libusb/msvc/stress_2013.vcxproj +4 -2
- package/libusb/msvc/stress_2013.vcxproj.filters +32 -0
- package/libusb/msvc/stress_2015.vcxproj +4 -2
- package/libusb/msvc/stress_2015.vcxproj.filters +32 -0
- package/libusb/msvc/stress_2017.vcxproj +4 -6
- package/libusb/msvc/stress_2017.vcxproj.filters +32 -0
- package/libusb/msvc/{stress_2010.vcxproj → stress_2019.vcxproj} +26 -4
- package/libusb/msvc/stress_2019.vcxproj.filters +32 -0
- package/libusb/msvc/testlibusb_2013.vcxproj +6 -3
- package/libusb/msvc/testlibusb_2013.vcxproj.filters +23 -0
- package/libusb/msvc/testlibusb_2015.vcxproj +6 -3
- package/libusb/msvc/testlibusb_2015.vcxproj.filters +23 -0
- package/libusb/msvc/testlibusb_2017.vcxproj +6 -7
- package/libusb/msvc/testlibusb_2017.vcxproj.filters +23 -0
- package/libusb/msvc/{testlibusb_2010.vcxproj → testlibusb_2019.vcxproj} +28 -5
- package/libusb/msvc/testlibusb_2019.vcxproj.filters +23 -0
- package/libusb/msvc/xusb_2013.vcxproj +6 -3
- package/libusb/msvc/xusb_2013.vcxproj.filters +23 -0
- package/libusb/msvc/xusb_2015.vcxproj +6 -3
- package/libusb/msvc/xusb_2015.vcxproj.filters +23 -0
- package/libusb/msvc/xusb_2017.vcxproj +6 -7
- package/libusb/msvc/xusb_2017.vcxproj.filters +23 -0
- package/libusb/msvc/{xusb_2010.vcxproj → xusb_2019.vcxproj} +28 -5
- package/libusb/msvc/xusb_2019.vcxproj.filters +23 -0
- package/libusb/tests/Makefile.am +13 -1
- package/libusb/tests/libusb_testlib.h +12 -43
- package/libusb/tests/stress.c +59 -50
- package/libusb/tests/testlib.c +78 -171
- package/libusb/tests/umockdev.c +1175 -0
- package/libusb.gypi +10 -11
- package/package.json +1 -1
- package/prebuilds/android-arm/node.napi.armv7.node +0 -0
- package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
- package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
- package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
- package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
- package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
- package/prebuilds/linux-ia32/node.napi.node +0 -0
- package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
- package/prebuilds/linux-x64/node.napi.musl.node +0 -0
- package/prebuilds/win32-ia32/node.napi.node +0 -0
- package/prebuilds/win32-x64/node.napi.node +0 -0
- package/src/device.cc +12 -7
- package/src/node_usb.cc +10 -0
- package/test/usb.coffee +6 -0
- package/tsc/index.ts +2 -0
- package/tsc/usb/bindings.ts +5 -0
- package/tsc/usb/device.ts +6 -0
- package/tsc/usb/index.ts +5 -8
- package/tsc/webusb/webusb-device.ts +67 -124
- package/dist/webusb/mutex.d.ts +0 -22
- package/dist/webusb/mutex.js +0 -89
- package/dist/webusb/mutex.js.map +0 -1
- package/libusb/.private/bd.cmd +0 -89
- package/libusb/.private/bwince.cmd +0 -57
- package/libusb/.private/wbs_wince.txt +0 -42
- package/libusb/Brewfile +0 -4
- package/libusb/appveyor_cygwin.bat +0 -11
- package/libusb/appveyor_minGW.bat +0 -19
- package/libusb/doc/Makefile.am +0 -9
- package/libusb/examples/dpfp_threaded.c +0 -557
- package/libusb/libusb/hotplug.h +0 -99
- package/libusb/libusb/os/poll_posix.c +0 -84
- package/libusb/libusb/os/poll_posix.h +0 -14
- package/libusb/libusb/os/poll_windows.c +0 -447
- package/libusb/libusb/os/poll_windows.h +0 -98
- package/libusb/libusb/os/wince_usb.c +0 -888
- package/libusb/libusb/os/wince_usb.h +0 -126
- package/libusb/libusb/os/windows_nt_common.c +0 -1010
- package/libusb/libusb/os/windows_nt_common.h +0 -110
- package/libusb/libusb/os/windows_nt_shared_types.h +0 -147
- package/libusb/msvc/appveyor.bat +0 -27
- package/libusb/msvc/ddk_build.cmd +0 -219
- package/libusb/msvc/errno.h +0 -102
- package/libusb/msvc/fxload_sources +0 -23
- package/libusb/msvc/getopt_2005.vcproj +0 -288
- package/libusb/msvc/getopt_2012.vcxproj +0 -73
- package/libusb/msvc/getopt_sources +0 -24
- package/libusb/msvc/hotplugtest_sources +0 -20
- package/libusb/msvc/inttypes.h +0 -295
- package/libusb/msvc/libusb.dsw +0 -71
- package/libusb/msvc/libusb_2005.sln +0 -95
- package/libusb/msvc/libusb_2010.sln +0 -105
- package/libusb/msvc/libusb_2012.sln +0 -105
- package/libusb/msvc/libusb_dll.dsp +0 -194
- package/libusb/msvc/libusb_dll_2005.vcproj +0 -464
- package/libusb/msvc/libusb_dll_2012.vcxproj +0 -107
- package/libusb/msvc/libusb_dll_wince.vcproj +0 -1251
- package/libusb/msvc/libusb_sources +0 -43
- package/libusb/msvc/libusb_static.dsp +0 -174
- package/libusb/msvc/libusb_static_2005.vcproj +0 -390
- package/libusb/msvc/libusb_static_2012.vcxproj +0 -98
- package/libusb/msvc/libusb_static_wince.vcproj +0 -1179
- package/libusb/msvc/libusb_wince.sln +0 -246
- package/libusb/msvc/listdevs.dsp +0 -103
- package/libusb/msvc/listdevs_2005.vcproj +0 -360
- package/libusb/msvc/listdevs_sources +0 -20
- package/libusb/msvc/listdevs_wince.vcproj +0 -1120
- package/libusb/msvc/missing.c +0 -80
- package/libusb/msvc/stdint.h +0 -256
- package/libusb/msvc/stress_2005.vcproj +0 -390
- package/libusb/msvc/stress_2012.vcxproj +0 -87
- package/libusb/msvc/stress_sources +0 -21
- package/libusb/msvc/stress_wince.vcproj +0 -1128
- package/libusb/msvc/testlibusb_2012.vcxproj +0 -83
- package/libusb/msvc/testlibusb_sources +0 -20
- package/libusb/msvc/xusb.dsp +0 -102
- package/libusb/msvc/xusb_2005.vcproj +0 -344
- package/libusb/msvc/xusb_2012.vcxproj +0 -83
- package/libusb/msvc/xusb_sources +0 -20
- package/libusb/msvc/xusb_wince.vcproj +0 -1120
- package/libusb/travis-autogen.sh +0 -39
- package/tsc/webusb/mutex.ts +0 -38
|
@@ -30,7 +30,6 @@
|
|
|
30
30
|
typedef struct sunos_device_priv {
|
|
31
31
|
uint8_t cfgvalue; /* active config value */
|
|
32
32
|
uint8_t *raw_cfgdescr; /* active config descriptor */
|
|
33
|
-
struct libusb_device_descriptor dev_descr; /* usb device descriptor */
|
|
34
33
|
char *ugenpath; /* name of the ugen(4) node */
|
|
35
34
|
char *phypath; /* physical path */
|
|
36
35
|
} sunos_dev_priv_t;
|
|
@@ -19,23 +19,39 @@
|
|
|
19
19
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
#include
|
|
22
|
+
#include "libusbi.h"
|
|
23
23
|
|
|
24
|
-
#include <
|
|
25
|
-
#if defined(
|
|
26
|
-
# if defined(__OpenBSD__)
|
|
27
|
-
# define _BSD_SOURCE
|
|
28
|
-
# endif
|
|
24
|
+
#include <errno.h>
|
|
25
|
+
#if defined(__ANDROID__)
|
|
29
26
|
# include <unistd.h>
|
|
27
|
+
#elif defined(__HAIKU__)
|
|
28
|
+
# include <os/kernel/OS.h>
|
|
29
|
+
#elif defined(__linux__)
|
|
30
30
|
# include <sys/syscall.h>
|
|
31
|
-
#
|
|
32
|
-
#
|
|
33
|
-
#
|
|
34
|
-
#
|
|
31
|
+
# include <unistd.h>
|
|
32
|
+
#elif defined(__NetBSD__)
|
|
33
|
+
# include <lwp.h>
|
|
34
|
+
#elif defined(__OpenBSD__)
|
|
35
|
+
# define _BSD_SOURCE
|
|
36
|
+
# include <sys/syscall.h>
|
|
37
|
+
# include <unistd.h>
|
|
38
|
+
#elif defined(__sun__)
|
|
39
|
+
# include <sys/lwp.h>
|
|
35
40
|
#endif
|
|
36
41
|
|
|
37
|
-
|
|
38
|
-
|
|
42
|
+
void usbi_cond_init(pthread_cond_t *cond)
|
|
43
|
+
{
|
|
44
|
+
#ifdef HAVE_PTHREAD_CONDATTR_SETCLOCK
|
|
45
|
+
pthread_condattr_t condattr;
|
|
46
|
+
|
|
47
|
+
PTHREAD_CHECK(pthread_condattr_init(&condattr));
|
|
48
|
+
PTHREAD_CHECK(pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC));
|
|
49
|
+
PTHREAD_CHECK(pthread_cond_init(cond, &condattr));
|
|
50
|
+
PTHREAD_CHECK(pthread_condattr_destroy(&condattr));
|
|
51
|
+
#else
|
|
52
|
+
PTHREAD_CHECK(pthread_cond_init(cond, NULL));
|
|
53
|
+
#endif
|
|
54
|
+
}
|
|
39
55
|
|
|
40
56
|
int usbi_cond_timedwait(pthread_cond_t *cond,
|
|
41
57
|
pthread_mutex_t *mutex, const struct timeval *tv)
|
|
@@ -43,38 +59,71 @@ int usbi_cond_timedwait(pthread_cond_t *cond,
|
|
|
43
59
|
struct timespec timeout;
|
|
44
60
|
int r;
|
|
45
61
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
62
|
+
#ifdef HAVE_PTHREAD_CONDATTR_SETCLOCK
|
|
63
|
+
usbi_get_monotonic_time(&timeout);
|
|
64
|
+
#else
|
|
65
|
+
usbi_get_real_time(&timeout);
|
|
66
|
+
#endif
|
|
49
67
|
|
|
50
68
|
timeout.tv_sec += tv->tv_sec;
|
|
51
|
-
timeout.tv_nsec += tv->tv_usec *
|
|
52
|
-
|
|
53
|
-
timeout.tv_nsec -=
|
|
69
|
+
timeout.tv_nsec += tv->tv_usec * 1000L;
|
|
70
|
+
if (timeout.tv_nsec >= NSEC_PER_SEC) {
|
|
71
|
+
timeout.tv_nsec -= NSEC_PER_SEC;
|
|
54
72
|
timeout.tv_sec++;
|
|
55
73
|
}
|
|
56
74
|
|
|
57
|
-
|
|
75
|
+
r = pthread_cond_timedwait(cond, mutex, &timeout);
|
|
76
|
+
if (r == 0)
|
|
77
|
+
return 0;
|
|
78
|
+
else if (r == ETIMEDOUT)
|
|
79
|
+
return LIBUSB_ERROR_TIMEOUT;
|
|
80
|
+
else
|
|
81
|
+
return LIBUSB_ERROR_OTHER;
|
|
58
82
|
}
|
|
59
83
|
|
|
60
|
-
int usbi_get_tid(void)
|
|
84
|
+
unsigned int usbi_get_tid(void)
|
|
61
85
|
{
|
|
62
|
-
int
|
|
86
|
+
static _Thread_local unsigned int tl_tid;
|
|
87
|
+
int tid;
|
|
88
|
+
|
|
89
|
+
if (tl_tid)
|
|
90
|
+
return tl_tid;
|
|
91
|
+
|
|
63
92
|
#if defined(__ANDROID__)
|
|
64
|
-
|
|
93
|
+
tid = gettid();
|
|
94
|
+
#elif defined(__APPLE__)
|
|
95
|
+
#ifdef HAVE_PTHREAD_THREADID_NP
|
|
96
|
+
uint64_t thread_id;
|
|
97
|
+
|
|
98
|
+
if (pthread_threadid_np(NULL, &thread_id) == 0)
|
|
99
|
+
tid = (int)thread_id;
|
|
100
|
+
else
|
|
101
|
+
tid = -1;
|
|
102
|
+
#else
|
|
103
|
+
tid = (int)pthread_mach_thread_np(pthread_self());
|
|
104
|
+
#endif
|
|
105
|
+
#elif defined(__HAIKU__)
|
|
106
|
+
tid = get_pthread_thread_id(pthread_self());
|
|
65
107
|
#elif defined(__linux__)
|
|
66
|
-
|
|
108
|
+
tid = (int)syscall(SYS_gettid);
|
|
109
|
+
#elif defined(__NetBSD__)
|
|
110
|
+
tid = _lwp_self();
|
|
67
111
|
#elif defined(__OpenBSD__)
|
|
68
112
|
/* The following only works with OpenBSD > 5.1 as it requires
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
#elif defined(
|
|
72
|
-
|
|
73
|
-
#elif defined(__CYGWIN__)
|
|
74
|
-
ret = GetCurrentThreadId();
|
|
113
|
+
* real thread support. For 5.1 and earlier, -1 is returned. */
|
|
114
|
+
tid = syscall(SYS_getthrid);
|
|
115
|
+
#elif defined(__sun__)
|
|
116
|
+
tid = _lwp_self();
|
|
75
117
|
#else
|
|
76
|
-
|
|
118
|
+
tid = -1;
|
|
77
119
|
#endif
|
|
78
|
-
|
|
79
|
-
|
|
120
|
+
|
|
121
|
+
if (tid == -1) {
|
|
122
|
+
/* If we don't have a thread ID, at least return a unique
|
|
123
|
+
* value that can be used to distinguish individual
|
|
124
|
+
* threads. */
|
|
125
|
+
tid = (int)(intptr_t)pthread_self();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return tl_tid = (unsigned int)tid;
|
|
80
129
|
}
|
|
@@ -22,67 +22,63 @@
|
|
|
22
22
|
#define LIBUSB_THREADS_POSIX_H
|
|
23
23
|
|
|
24
24
|
#include <pthread.h>
|
|
25
|
-
|
|
26
|
-
#
|
|
27
|
-
#endif
|
|
25
|
+
|
|
26
|
+
#define PTHREAD_CHECK(expression) ASSERT_EQ(expression, 0)
|
|
28
27
|
|
|
29
28
|
#define USBI_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
|
|
30
29
|
typedef pthread_mutex_t usbi_mutex_static_t;
|
|
31
30
|
static inline void usbi_mutex_static_lock(usbi_mutex_static_t *mutex)
|
|
32
31
|
{
|
|
33
|
-
(
|
|
32
|
+
PTHREAD_CHECK(pthread_mutex_lock(mutex));
|
|
34
33
|
}
|
|
35
34
|
static inline void usbi_mutex_static_unlock(usbi_mutex_static_t *mutex)
|
|
36
35
|
{
|
|
37
|
-
(
|
|
36
|
+
PTHREAD_CHECK(pthread_mutex_unlock(mutex));
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
typedef pthread_mutex_t usbi_mutex_t;
|
|
41
|
-
static inline
|
|
40
|
+
static inline void usbi_mutex_init(usbi_mutex_t *mutex)
|
|
42
41
|
{
|
|
43
|
-
|
|
42
|
+
PTHREAD_CHECK(pthread_mutex_init(mutex, NULL));
|
|
44
43
|
}
|
|
45
44
|
static inline void usbi_mutex_lock(usbi_mutex_t *mutex)
|
|
46
45
|
{
|
|
47
|
-
(
|
|
46
|
+
PTHREAD_CHECK(pthread_mutex_lock(mutex));
|
|
48
47
|
}
|
|
49
48
|
static inline void usbi_mutex_unlock(usbi_mutex_t *mutex)
|
|
50
49
|
{
|
|
51
|
-
(
|
|
50
|
+
PTHREAD_CHECK(pthread_mutex_unlock(mutex));
|
|
52
51
|
}
|
|
53
52
|
static inline int usbi_mutex_trylock(usbi_mutex_t *mutex)
|
|
54
53
|
{
|
|
55
|
-
return pthread_mutex_trylock(mutex);
|
|
54
|
+
return pthread_mutex_trylock(mutex) == 0;
|
|
56
55
|
}
|
|
57
56
|
static inline void usbi_mutex_destroy(usbi_mutex_t *mutex)
|
|
58
57
|
{
|
|
59
|
-
(
|
|
58
|
+
PTHREAD_CHECK(pthread_mutex_destroy(mutex));
|
|
60
59
|
}
|
|
61
60
|
|
|
62
61
|
typedef pthread_cond_t usbi_cond_t;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
(void)pthread_cond_init(cond, NULL);
|
|
66
|
-
}
|
|
67
|
-
static inline int usbi_cond_wait(usbi_cond_t *cond, usbi_mutex_t *mutex)
|
|
62
|
+
void usbi_cond_init(pthread_cond_t *cond);
|
|
63
|
+
static inline void usbi_cond_wait(usbi_cond_t *cond, usbi_mutex_t *mutex)
|
|
68
64
|
{
|
|
69
|
-
|
|
65
|
+
PTHREAD_CHECK(pthread_cond_wait(cond, mutex));
|
|
70
66
|
}
|
|
71
67
|
int usbi_cond_timedwait(usbi_cond_t *cond,
|
|
72
68
|
usbi_mutex_t *mutex, const struct timeval *tv);
|
|
73
69
|
static inline void usbi_cond_broadcast(usbi_cond_t *cond)
|
|
74
70
|
{
|
|
75
|
-
(
|
|
71
|
+
PTHREAD_CHECK(pthread_cond_broadcast(cond));
|
|
76
72
|
}
|
|
77
73
|
static inline void usbi_cond_destroy(usbi_cond_t *cond)
|
|
78
74
|
{
|
|
79
|
-
(
|
|
75
|
+
PTHREAD_CHECK(pthread_cond_destroy(cond));
|
|
80
76
|
}
|
|
81
77
|
|
|
82
78
|
typedef pthread_key_t usbi_tls_key_t;
|
|
83
79
|
static inline void usbi_tls_key_create(usbi_tls_key_t *key)
|
|
84
80
|
{
|
|
85
|
-
(
|
|
81
|
+
PTHREAD_CHECK(pthread_key_create(key, NULL));
|
|
86
82
|
}
|
|
87
83
|
static inline void *usbi_tls_key_get(usbi_tls_key_t key)
|
|
88
84
|
{
|
|
@@ -90,13 +86,13 @@ static inline void *usbi_tls_key_get(usbi_tls_key_t key)
|
|
|
90
86
|
}
|
|
91
87
|
static inline void usbi_tls_key_set(usbi_tls_key_t key, void *ptr)
|
|
92
88
|
{
|
|
93
|
-
(
|
|
89
|
+
PTHREAD_CHECK(pthread_setspecific(key, ptr));
|
|
94
90
|
}
|
|
95
91
|
static inline void usbi_tls_key_delete(usbi_tls_key_t key)
|
|
96
92
|
{
|
|
97
|
-
(
|
|
93
|
+
PTHREAD_CHECK(pthread_key_delete(key));
|
|
98
94
|
}
|
|
99
95
|
|
|
100
|
-
int usbi_get_tid(void);
|
|
96
|
+
unsigned int usbi_get_tid(void);
|
|
101
97
|
|
|
102
98
|
#endif /* LIBUSB_THREADS_POSIX_H */
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* libusb synchronization on Microsoft Windows
|
|
3
3
|
*
|
|
4
4
|
* Copyright © 2010 Michael Plante <michael.plante@gmail.com>
|
|
5
|
+
* Copyright © 2020 Chris Dickens <christopher.a.dickens@gmail.com>
|
|
5
6
|
*
|
|
6
7
|
* This library is free software; you can redistribute it and/or
|
|
7
8
|
* modify it under the terms of the GNU Lesser General Public
|
|
@@ -18,109 +19,22 @@
|
|
|
18
19
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
19
20
|
*/
|
|
20
21
|
|
|
21
|
-
#include <config.h>
|
|
22
|
-
|
|
23
|
-
#include <errno.h>
|
|
24
|
-
|
|
25
22
|
#include "libusbi.h"
|
|
26
23
|
|
|
27
|
-
struct usbi_cond_perthread {
|
|
28
|
-
struct list_head list;
|
|
29
|
-
HANDLE event;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
void usbi_mutex_static_lock(usbi_mutex_static_t *mutex)
|
|
33
|
-
{
|
|
34
|
-
while (InterlockedExchange(mutex, 1L) == 1L)
|
|
35
|
-
SleepEx(0, TRUE);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
void usbi_cond_init(usbi_cond_t *cond)
|
|
39
|
-
{
|
|
40
|
-
list_init(&cond->waiters);
|
|
41
|
-
list_init(&cond->not_waiting);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
static int usbi_cond_intwait(usbi_cond_t *cond,
|
|
45
|
-
usbi_mutex_t *mutex, DWORD timeout_ms)
|
|
46
|
-
{
|
|
47
|
-
struct usbi_cond_perthread *pos;
|
|
48
|
-
DWORD r;
|
|
49
|
-
|
|
50
|
-
// Same assumption as usbi_cond_broadcast() holds
|
|
51
|
-
if (list_empty(&cond->not_waiting)) {
|
|
52
|
-
pos = malloc(sizeof(*pos));
|
|
53
|
-
if (pos == NULL)
|
|
54
|
-
return ENOMEM; // This errno is not POSIX-allowed.
|
|
55
|
-
pos->event = CreateEvent(NULL, FALSE, FALSE, NULL); // auto-reset.
|
|
56
|
-
if (pos->event == NULL) {
|
|
57
|
-
free(pos);
|
|
58
|
-
return ENOMEM;
|
|
59
|
-
}
|
|
60
|
-
} else {
|
|
61
|
-
pos = list_first_entry(&cond->not_waiting, struct usbi_cond_perthread, list);
|
|
62
|
-
list_del(&pos->list); // remove from not_waiting list.
|
|
63
|
-
// Ensure the event is clear before waiting
|
|
64
|
-
WaitForSingleObject(pos->event, 0);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
list_add(&pos->list, &cond->waiters);
|
|
68
|
-
|
|
69
|
-
LeaveCriticalSection(mutex);
|
|
70
|
-
r = WaitForSingleObject(pos->event, timeout_ms);
|
|
71
|
-
EnterCriticalSection(mutex);
|
|
72
|
-
|
|
73
|
-
list_del(&pos->list);
|
|
74
|
-
list_add(&pos->list, &cond->not_waiting);
|
|
75
|
-
|
|
76
|
-
if (r == WAIT_OBJECT_0)
|
|
77
|
-
return 0;
|
|
78
|
-
else if (r == WAIT_TIMEOUT)
|
|
79
|
-
return ETIMEDOUT;
|
|
80
|
-
else
|
|
81
|
-
return EINVAL;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// N.B.: usbi_cond_*wait() can also return ENOMEM, even though pthread_cond_*wait cannot!
|
|
85
|
-
int usbi_cond_wait(usbi_cond_t *cond, usbi_mutex_t *mutex)
|
|
86
|
-
{
|
|
87
|
-
return usbi_cond_intwait(cond, mutex, INFINITE);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
24
|
int usbi_cond_timedwait(usbi_cond_t *cond,
|
|
91
25
|
usbi_mutex_t *mutex, const struct timeval *tv)
|
|
92
26
|
{
|
|
93
27
|
DWORD millis;
|
|
94
28
|
|
|
95
|
-
millis = (DWORD)(tv->tv_sec *
|
|
29
|
+
millis = (DWORD)(tv->tv_sec * 1000L) + (tv->tv_usec / 1000L);
|
|
96
30
|
/* round up to next millisecond */
|
|
97
|
-
if (tv->tv_usec %
|
|
31
|
+
if (tv->tv_usec % 1000L)
|
|
98
32
|
millis++;
|
|
99
|
-
return usbi_cond_intwait(cond, mutex, millis);
|
|
100
|
-
}
|
|
101
33
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
list_for_each_entry(pos, &cond->waiters, list, struct usbi_cond_perthread)
|
|
110
|
-
SetEvent(pos->event);
|
|
111
|
-
// The wait function will remove its respective item from the list.
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
void usbi_cond_destroy(usbi_cond_t *cond)
|
|
115
|
-
{
|
|
116
|
-
// This assumes no one is using this anymore. The check MAY NOT BE safe.
|
|
117
|
-
struct usbi_cond_perthread *pos, *next;
|
|
118
|
-
|
|
119
|
-
if (!list_empty(&cond->waiters))
|
|
120
|
-
return; // (!see above!)
|
|
121
|
-
list_for_each_entry_safe(pos, next, &cond->not_waiting, list, struct usbi_cond_perthread) {
|
|
122
|
-
CloseHandle(pos->event);
|
|
123
|
-
list_del(&pos->list);
|
|
124
|
-
free(pos);
|
|
125
|
-
}
|
|
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;
|
|
126
40
|
}
|
|
@@ -21,23 +21,24 @@
|
|
|
21
21
|
#ifndef LIBUSB_THREADS_WINDOWS_H
|
|
22
22
|
#define LIBUSB_THREADS_WINDOWS_H
|
|
23
23
|
|
|
24
|
+
#define WINAPI_CHECK(expression) ASSERT_NE(expression, 0)
|
|
25
|
+
|
|
24
26
|
#define USBI_MUTEX_INITIALIZER 0L
|
|
25
|
-
#ifdef _WIN32_WCE
|
|
26
27
|
typedef LONG usbi_mutex_static_t;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
+
}
|
|
31
33
|
static inline void usbi_mutex_static_unlock(usbi_mutex_static_t *mutex)
|
|
32
34
|
{
|
|
33
35
|
InterlockedExchange(mutex, 0L);
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
typedef CRITICAL_SECTION usbi_mutex_t;
|
|
37
|
-
static inline
|
|
39
|
+
static inline void usbi_mutex_init(usbi_mutex_t *mutex)
|
|
38
40
|
{
|
|
39
41
|
InitializeCriticalSection(mutex);
|
|
40
|
-
return 0;
|
|
41
42
|
}
|
|
42
43
|
static inline void usbi_mutex_lock(usbi_mutex_t *mutex)
|
|
43
44
|
{
|
|
@@ -49,46 +50,47 @@ static inline void usbi_mutex_unlock(usbi_mutex_t *mutex)
|
|
|
49
50
|
}
|
|
50
51
|
static inline int usbi_mutex_trylock(usbi_mutex_t *mutex)
|
|
51
52
|
{
|
|
52
|
-
return
|
|
53
|
+
return TryEnterCriticalSection(mutex) != 0;
|
|
53
54
|
}
|
|
54
55
|
static inline void usbi_mutex_destroy(usbi_mutex_t *mutex)
|
|
55
56
|
{
|
|
56
57
|
DeleteCriticalSection(mutex);
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
|
|
60
|
-
#if (!defined(HAVE_STRUCT_TIMESPEC) && !defined(_TIMESPEC_DEFINED))
|
|
60
|
+
#if !defined(HAVE_STRUCT_TIMESPEC) && !defined(_TIMESPEC_DEFINED)
|
|
61
61
|
#define HAVE_STRUCT_TIMESPEC 1
|
|
62
62
|
#define _TIMESPEC_DEFINED 1
|
|
63
63
|
struct timespec {
|
|
64
64
|
long tv_sec;
|
|
65
65
|
long tv_nsec;
|
|
66
66
|
};
|
|
67
|
-
#endif /* HAVE_STRUCT_TIMESPEC
|
|
68
|
-
|
|
69
|
-
// We *were* getting ETIMEDOUT from pthread.h:
|
|
70
|
-
#ifndef ETIMEDOUT
|
|
71
|
-
#define ETIMEDOUT 10060 /* This is the value in winsock.h. */
|
|
72
|
-
#endif
|
|
67
|
+
#endif /* HAVE_STRUCT_TIMESPEC || _TIMESPEC_DEFINED */
|
|
73
68
|
|
|
74
|
-
typedef
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
+
}
|
|
83
78
|
int usbi_cond_timedwait(usbi_cond_t *cond,
|
|
84
79
|
usbi_mutex_t *mutex, const struct timeval *tv);
|
|
85
|
-
void usbi_cond_broadcast(usbi_cond_t *cond)
|
|
86
|
-
|
|
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
|
+
}
|
|
87
88
|
|
|
88
89
|
typedef DWORD usbi_tls_key_t;
|
|
89
90
|
static inline void usbi_tls_key_create(usbi_tls_key_t *key)
|
|
90
91
|
{
|
|
91
92
|
*key = TlsAlloc();
|
|
93
|
+
assert(*key != TLS_OUT_OF_INDEXES);
|
|
92
94
|
}
|
|
93
95
|
static inline void *usbi_tls_key_get(usbi_tls_key_t key)
|
|
94
96
|
{
|
|
@@ -96,16 +98,16 @@ static inline void *usbi_tls_key_get(usbi_tls_key_t key)
|
|
|
96
98
|
}
|
|
97
99
|
static inline void usbi_tls_key_set(usbi_tls_key_t key, void *ptr)
|
|
98
100
|
{
|
|
99
|
-
(
|
|
101
|
+
WINAPI_CHECK(TlsSetValue(key, ptr));
|
|
100
102
|
}
|
|
101
103
|
static inline void usbi_tls_key_delete(usbi_tls_key_t key)
|
|
102
104
|
{
|
|
103
|
-
(
|
|
105
|
+
WINAPI_CHECK(TlsFree(key));
|
|
104
106
|
}
|
|
105
107
|
|
|
106
|
-
static inline int usbi_get_tid(void)
|
|
108
|
+
static inline unsigned int usbi_get_tid(void)
|
|
107
109
|
{
|
|
108
|
-
return (int)GetCurrentThreadId();
|
|
110
|
+
return (unsigned int)GetCurrentThreadId();
|
|
109
111
|
}
|
|
110
112
|
|
|
111
113
|
#endif /* LIBUSB_THREADS_WINDOWS_H */
|