From: "Rémi Bernon" Subject: [PATCH 3/5] winebus.sys: Use a pthread_mutex_t instead of CRITICAL_SECTION. Message-Id: <20210917065035.3294478-3-rbernon@codeweavers.com> Date: Fri, 17 Sep 2021 08:50:33 +0200 In-Reply-To: <20210917065035.3294478-1-rbernon@codeweavers.com> References: <20210917065035.3294478-1-rbernon@codeweavers.com> Signed-off-by: Rémi Bernon --- dlls/winebus.sys/Makefile.in | 2 +- dlls/winebus.sys/bus_iohid.c | 19 +++++++------------ dlls/winebus.sys/bus_sdl.c | 20 +++++++------------- dlls/winebus.sys/bus_udev.c | 35 +++++++++++++++-------------------- 4 files changed, 30 insertions(+), 46 deletions(-) diff --git a/dlls/winebus.sys/Makefile.in b/dlls/winebus.sys/Makefile.in index 1675bf1951c..ec731c2b85c 100644 --- a/dlls/winebus.sys/Makefile.in +++ b/dlls/winebus.sys/Makefile.in @@ -1,6 +1,6 @@ MODULE = winebus.sys IMPORTS = ntoskrnl advapi32 -EXTRALIBS = $(IOKIT_LIBS) $(UDEV_LIBS) +EXTRALIBS = $(IOKIT_LIBS) $(UDEV_LIBS) $(PTHREAD_LIBS) EXTRAINCL = $(UDEV_CFLAGS) $(SDL2_CFLAGS) EXTRADLLFLAGS = -mno-cygwin -Wl,--subsystem,native diff --git a/dlls/winebus.sys/bus_iohid.c b/dlls/winebus.sys/bus_iohid.c index 70a7cd0b005..8dc9e6c3df1 100644 --- a/dlls/winebus.sys/bus_iohid.c +++ b/dlls/winebus.sys/bus_iohid.c @@ -83,6 +83,8 @@ #undef PAGE_SHIFT #endif /* HAVE_IOKIT_HID_IOHIDLIB_H */ +#include + #include "ntstatus.h" #define WIN32_NO_STATUS #include "windef.h" @@ -98,14 +100,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(plugplay); #ifdef HAVE_IOHIDMANAGERCREATE -static CRITICAL_SECTION iohid_cs; -static CRITICAL_SECTION_DEBUG iohid_cs_debug = -{ - 0, 0, &iohid_cs, - { &iohid_cs_debug.ProcessLocksList, &iohid_cs_debug.ProcessLocksList }, - 0, 0, { (DWORD_PTR)(__FILE__ ": iohid_cs") } -}; -static CRITICAL_SECTION iohid_cs = { &iohid_cs_debug, -1, 0, 0, 0, 0 }; +static pthread_mutex_t iohid_cs = PTHREAD_MUTEX_INITIALIZER; static IOHIDManagerRef hid_manager; static CFRunLoopRef run_loop; @@ -184,9 +179,9 @@ static void iohid_device_stop(struct unix_device *iface) IOHIDDeviceRegisterInputReportCallback(private->device, NULL, 0, NULL, NULL); - RtlEnterCriticalSection(&iohid_cs); + pthread_mutex_lock(&iohid_cs); list_remove(&private->unix_device.entry); - RtlLeaveCriticalSection(&iohid_cs); + pthread_mutex_unlock(&iohid_cs); } static NTSTATUS iohid_device_get_report_descriptor(struct unix_device *iface, BYTE *buffer, @@ -407,9 +402,9 @@ NTSTATUS WINAPI iohid_bus_wait(void *args) do { if (bus_event_queue_pop(&event_queue, result)) return STATUS_PENDING; - RtlEnterCriticalSection(&iohid_cs); + pthread_mutex_lock(&iohid_cs); ret = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 10, TRUE); - RtlLeaveCriticalSection(&iohid_cs); + pthread_mutex_unlock(&iohid_cs); } while (ret != kCFRunLoopRunStopped); TRACE("IOHID main loop exiting\n"); diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c index 956340faf02..b7c3b28ba4e 100644 --- a/dlls/winebus.sys/bus_sdl.c +++ b/dlls/winebus.sys/bus_sdl.c @@ -35,6 +35,8 @@ # include #endif +#include + #include "ntstatus.h" #define WIN32_NO_STATUS #include "windef.h" @@ -62,15 +64,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(plugplay); WINE_DECLARE_DEBUG_CHANNEL(hid_report); -static CRITICAL_SECTION sdl_cs; -static CRITICAL_SECTION_DEBUG sdl_cs_debug = -{ - 0, 0, &sdl_cs, - { &sdl_cs_debug.ProcessLocksList, &sdl_cs_debug.ProcessLocksList }, - 0, 0, { (DWORD_PTR)(__FILE__ ": sdl_cs") } -}; -static CRITICAL_SECTION sdl_cs = { &sdl_cs_debug, -1, 0, 0, 0, 0 }; - +static pthread_mutex_t sdl_cs = PTHREAD_MUTEX_INITIALIZER; static const WCHAR sdl_busidW[] = {'S','D','L','J','O','Y',0}; static struct sdl_bus_options options; @@ -513,9 +507,9 @@ static void sdl_device_stop(struct unix_device *iface) if (private->sdl_controller) pSDL_GameControllerClose(private->sdl_controller); if (private->sdl_haptic) pSDL_HapticClose(private->sdl_haptic); - RtlEnterCriticalSection(&sdl_cs); + pthread_mutex_lock(&sdl_cs); list_remove(&private->unix_device.entry); - RtlLeaveCriticalSection(&sdl_cs); + pthread_mutex_unlock(&sdl_cs); } static NTSTATUS sdl_device_get_reportdescriptor(struct unix_device *iface, BYTE *buffer, @@ -787,7 +781,7 @@ static void process_device_event(SDL_Event *event) TRACE_(hid_report)("Received action %x\n", event->type); - RtlEnterCriticalSection(&sdl_cs); + pthread_mutex_lock(&sdl_cs); if (event->type == SDL_JOYDEVICEADDED) sdl_add_device(((SDL_JoyDeviceEvent *)event)->which); @@ -813,7 +807,7 @@ static void process_device_event(SDL_Event *event) else WARN("failed to find device with id %d\n", id); } - RtlLeaveCriticalSection(&sdl_cs); + pthread_mutex_unlock(&sdl_cs); } NTSTATUS WINAPI sdl_bus_init(void *args) diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c index 928548b8893..c73a6dd2259 100644 --- a/dlls/winebus.sys/bus_udev.c +++ b/dlls/winebus.sys/bus_udev.c @@ -58,6 +58,8 @@ # endif #endif +#include + #include "ntstatus.h" #define WIN32_NO_STATUS #include "windef.h" @@ -91,14 +93,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(plugplay); WINE_DECLARE_DEBUG_CHANNEL(hid_report); -static CRITICAL_SECTION udev_cs; -static CRITICAL_SECTION_DEBUG udev_cs_debug = -{ - 0, 0, &udev_cs, - { &udev_cs_debug.ProcessLocksList, &udev_cs_debug.ProcessLocksList }, - 0, 0, { (DWORD_PTR)(__FILE__ ": udev_cs") } -}; -static CRITICAL_SECTION udev_cs = { &udev_cs_debug, -1, 0, 0, 0, 0 }; +static pthread_mutex_t udev_cs = PTHREAD_MUTEX_INITIALIZER; static struct udev *udev_context = NULL; static struct udev_monitor *udev_monitor; @@ -622,9 +617,9 @@ static void hidraw_device_destroy(struct unix_device *iface) static NTSTATUS hidraw_device_start(struct unix_device *iface) { - RtlEnterCriticalSection(&udev_cs); + pthread_mutex_lock(&udev_cs); start_polling_device(iface); - RtlLeaveCriticalSection(&udev_cs); + pthread_mutex_unlock(&udev_cs); return STATUS_SUCCESS; } @@ -632,10 +627,10 @@ static void hidraw_device_stop(struct unix_device *iface) { struct platform_private *private = impl_from_unix_device(iface); - RtlEnterCriticalSection(&udev_cs); + pthread_mutex_lock(&udev_cs); stop_polling_device(iface); list_remove(&private->unix_device.entry); - RtlLeaveCriticalSection(&udev_cs); + pthread_mutex_unlock(&udev_cs); } static NTSTATUS hidraw_device_get_report_descriptor(struct unix_device *iface, BYTE *buffer, @@ -824,9 +819,9 @@ static NTSTATUS lnxev_device_start(struct unix_device *iface) if ((status = build_report_descriptor(ext, ext->base.udev_device))) return status; - RtlEnterCriticalSection(&udev_cs); + pthread_mutex_lock(&udev_cs); start_polling_device(iface); - RtlLeaveCriticalSection(&udev_cs); + pthread_mutex_unlock(&udev_cs); return STATUS_SUCCESS; } @@ -834,10 +829,10 @@ static void lnxev_device_stop(struct unix_device *iface) { struct wine_input_private *ext = input_impl_from_unix_device(iface); - RtlEnterCriticalSection(&udev_cs); + pthread_mutex_lock(&udev_cs); stop_polling_device(iface); list_remove(&ext->base.unix_device.entry); - RtlLeaveCriticalSection(&udev_cs); + pthread_mutex_unlock(&udev_cs); } static NTSTATUS lnxev_device_get_report_descriptor(struct unix_device *iface, BYTE *buffer, @@ -1246,16 +1241,16 @@ NTSTATUS WINAPI udev_bus_wait(void *args) { if (bus_event_queue_pop(&event_queue, result)) return STATUS_PENDING; - RtlEnterCriticalSection(&udev_cs); + pthread_mutex_lock(&udev_cs); while (close_count--) close(close_fds[close_count]); memcpy(pfd, poll_fds, poll_count * sizeof(*pfd)); count = poll_count; close_count = 0; - RtlLeaveCriticalSection(&udev_cs); + pthread_mutex_unlock(&udev_cs); while (poll(pfd, count, -1) <= 0) {} - RtlEnterCriticalSection(&udev_cs); + pthread_mutex_lock(&udev_cs); if (pfd[0].revents) process_monitor_event(udev_monitor); if (pfd[1].revents) read(deviceloop_control[0], &ctrl, 1); for (i = 2; i < count; ++i) @@ -1264,7 +1259,7 @@ NTSTATUS WINAPI udev_bus_wait(void *args) device = find_device_from_fd(pfd[i].fd); if (device) device->read_report(&device->unix_device); } - RtlLeaveCriticalSection(&udev_cs); + pthread_mutex_unlock(&udev_cs); } TRACE("UDEV main loop exiting\n"); -- 2.33.0