Commit cc2f6693 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

winebus.sys: Use a pthread_mutex_t instead of CRITICAL_SECTION.

parent 8f6932fd
MODULE = winebus.sys MODULE = winebus.sys
IMPORTS = ntoskrnl advapi32 IMPORTS = ntoskrnl advapi32
EXTRALIBS = $(IOKIT_LIBS) $(UDEV_LIBS) EXTRALIBS = $(IOKIT_LIBS) $(UDEV_LIBS) $(PTHREAD_LIBS)
EXTRAINCL = $(UDEV_CFLAGS) $(SDL2_CFLAGS) EXTRAINCL = $(UDEV_CFLAGS) $(SDL2_CFLAGS)
EXTRADLLFLAGS = -mno-cygwin -Wl,--subsystem,native EXTRADLLFLAGS = -mno-cygwin -Wl,--subsystem,native
......
...@@ -83,6 +83,8 @@ ...@@ -83,6 +83,8 @@
#undef PAGE_SHIFT #undef PAGE_SHIFT
#endif /* HAVE_IOKIT_HID_IOHIDLIB_H */ #endif /* HAVE_IOKIT_HID_IOHIDLIB_H */
#include <pthread.h>
#include "ntstatus.h" #include "ntstatus.h"
#define WIN32_NO_STATUS #define WIN32_NO_STATUS
#include "windef.h" #include "windef.h"
...@@ -98,14 +100,7 @@ ...@@ -98,14 +100,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(plugplay); WINE_DEFAULT_DEBUG_CHANNEL(plugplay);
#ifdef HAVE_IOHIDMANAGERCREATE #ifdef HAVE_IOHIDMANAGERCREATE
static CRITICAL_SECTION iohid_cs; static pthread_mutex_t iohid_cs = PTHREAD_MUTEX_INITIALIZER;
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 IOHIDManagerRef hid_manager; static IOHIDManagerRef hid_manager;
static CFRunLoopRef run_loop; static CFRunLoopRef run_loop;
...@@ -184,9 +179,9 @@ static void iohid_device_stop(struct unix_device *iface) ...@@ -184,9 +179,9 @@ static void iohid_device_stop(struct unix_device *iface)
IOHIDDeviceRegisterInputReportCallback(private->device, NULL, 0, NULL, NULL); IOHIDDeviceRegisterInputReportCallback(private->device, NULL, 0, NULL, NULL);
RtlEnterCriticalSection(&iohid_cs); pthread_mutex_lock(&iohid_cs);
list_remove(&private->unix_device.entry); 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, static NTSTATUS iohid_device_get_report_descriptor(struct unix_device *iface, BYTE *buffer,
...@@ -407,9 +402,9 @@ NTSTATUS WINAPI iohid_bus_wait(void *args) ...@@ -407,9 +402,9 @@ NTSTATUS WINAPI iohid_bus_wait(void *args)
do do
{ {
if (bus_event_queue_pop(&event_queue, result)) return STATUS_PENDING; if (bus_event_queue_pop(&event_queue, result)) return STATUS_PENDING;
RtlEnterCriticalSection(&iohid_cs); pthread_mutex_lock(&iohid_cs);
ret = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 10, TRUE); ret = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 10, TRUE);
RtlLeaveCriticalSection(&iohid_cs); pthread_mutex_unlock(&iohid_cs);
} while (ret != kCFRunLoopRunStopped); } while (ret != kCFRunLoopRunStopped);
TRACE("IOHID main loop exiting\n"); TRACE("IOHID main loop exiting\n");
......
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
# include <SDL.h> # include <SDL.h>
#endif #endif
#include <pthread.h>
#include "ntstatus.h" #include "ntstatus.h"
#define WIN32_NO_STATUS #define WIN32_NO_STATUS
#include "windef.h" #include "windef.h"
...@@ -62,15 +64,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(plugplay); ...@@ -62,15 +64,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(plugplay);
WINE_DECLARE_DEBUG_CHANNEL(hid_report); WINE_DECLARE_DEBUG_CHANNEL(hid_report);
static CRITICAL_SECTION sdl_cs; static pthread_mutex_t sdl_cs = PTHREAD_MUTEX_INITIALIZER;
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 const WCHAR sdl_busidW[] = {'S','D','L','J','O','Y',0}; static const WCHAR sdl_busidW[] = {'S','D','L','J','O','Y',0};
static struct sdl_bus_options options; static struct sdl_bus_options options;
...@@ -513,9 +507,9 @@ static void sdl_device_stop(struct unix_device *iface) ...@@ -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_controller) pSDL_GameControllerClose(private->sdl_controller);
if (private->sdl_haptic) pSDL_HapticClose(private->sdl_haptic); if (private->sdl_haptic) pSDL_HapticClose(private->sdl_haptic);
RtlEnterCriticalSection(&sdl_cs); pthread_mutex_lock(&sdl_cs);
list_remove(&private->unix_device.entry); 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, static NTSTATUS sdl_device_get_reportdescriptor(struct unix_device *iface, BYTE *buffer,
...@@ -787,7 +781,7 @@ static void process_device_event(SDL_Event *event) ...@@ -787,7 +781,7 @@ static void process_device_event(SDL_Event *event)
TRACE_(hid_report)("Received action %x\n", event->type); TRACE_(hid_report)("Received action %x\n", event->type);
RtlEnterCriticalSection(&sdl_cs); pthread_mutex_lock(&sdl_cs);
if (event->type == SDL_JOYDEVICEADDED) if (event->type == SDL_JOYDEVICEADDED)
sdl_add_device(((SDL_JoyDeviceEvent *)event)->which); sdl_add_device(((SDL_JoyDeviceEvent *)event)->which);
...@@ -813,7 +807,7 @@ static void process_device_event(SDL_Event *event) ...@@ -813,7 +807,7 @@ static void process_device_event(SDL_Event *event)
else WARN("failed to find device with id %d\n", id); 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) NTSTATUS WINAPI sdl_bus_init(void *args)
......
...@@ -58,6 +58,8 @@ ...@@ -58,6 +58,8 @@
# endif # endif
#endif #endif
#include <pthread.h>
#include "ntstatus.h" #include "ntstatus.h"
#define WIN32_NO_STATUS #define WIN32_NO_STATUS
#include "windef.h" #include "windef.h"
...@@ -91,14 +93,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(plugplay); ...@@ -91,14 +93,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(plugplay);
WINE_DECLARE_DEBUG_CHANNEL(hid_report); WINE_DECLARE_DEBUG_CHANNEL(hid_report);
static CRITICAL_SECTION udev_cs; static pthread_mutex_t udev_cs = PTHREAD_MUTEX_INITIALIZER;
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 struct udev *udev_context = NULL; static struct udev *udev_context = NULL;
static struct udev_monitor *udev_monitor; static struct udev_monitor *udev_monitor;
...@@ -622,9 +617,9 @@ static void hidraw_device_destroy(struct unix_device *iface) ...@@ -622,9 +617,9 @@ static void hidraw_device_destroy(struct unix_device *iface)
static NTSTATUS hidraw_device_start(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); start_polling_device(iface);
RtlLeaveCriticalSection(&udev_cs); pthread_mutex_unlock(&udev_cs);
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
...@@ -632,10 +627,10 @@ static void hidraw_device_stop(struct unix_device *iface) ...@@ -632,10 +627,10 @@ static void hidraw_device_stop(struct unix_device *iface)
{ {
struct platform_private *private = impl_from_unix_device(iface); struct platform_private *private = impl_from_unix_device(iface);
RtlEnterCriticalSection(&udev_cs); pthread_mutex_lock(&udev_cs);
stop_polling_device(iface); stop_polling_device(iface);
list_remove(&private->unix_device.entry); 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, 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) ...@@ -824,9 +819,9 @@ static NTSTATUS lnxev_device_start(struct unix_device *iface)
if ((status = build_report_descriptor(ext, ext->base.udev_device))) if ((status = build_report_descriptor(ext, ext->base.udev_device)))
return status; return status;
RtlEnterCriticalSection(&udev_cs); pthread_mutex_lock(&udev_cs);
start_polling_device(iface); start_polling_device(iface);
RtlLeaveCriticalSection(&udev_cs); pthread_mutex_unlock(&udev_cs);
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
...@@ -834,10 +829,10 @@ static void lnxev_device_stop(struct unix_device *iface) ...@@ -834,10 +829,10 @@ static void lnxev_device_stop(struct unix_device *iface)
{ {
struct wine_input_private *ext = input_impl_from_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); stop_polling_device(iface);
list_remove(&ext->base.unix_device.entry); 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, static NTSTATUS lnxev_device_get_report_descriptor(struct unix_device *iface, BYTE *buffer,
...@@ -1246,16 +1241,16 @@ NTSTATUS WINAPI udev_bus_wait(void *args) ...@@ -1246,16 +1241,16 @@ NTSTATUS WINAPI udev_bus_wait(void *args)
{ {
if (bus_event_queue_pop(&event_queue, result)) return STATUS_PENDING; 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]); while (close_count--) close(close_fds[close_count]);
memcpy(pfd, poll_fds, poll_count * sizeof(*pfd)); memcpy(pfd, poll_fds, poll_count * sizeof(*pfd));
count = poll_count; count = poll_count;
close_count = 0; close_count = 0;
RtlLeaveCriticalSection(&udev_cs); pthread_mutex_unlock(&udev_cs);
while (poll(pfd, count, -1) <= 0) {} 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[0].revents) process_monitor_event(udev_monitor);
if (pfd[1].revents) read(deviceloop_control[0], &ctrl, 1); if (pfd[1].revents) read(deviceloop_control[0], &ctrl, 1);
for (i = 2; i < count; ++i) for (i = 2; i < count; ++i)
...@@ -1264,7 +1259,7 @@ NTSTATUS WINAPI udev_bus_wait(void *args) ...@@ -1264,7 +1259,7 @@ NTSTATUS WINAPI udev_bus_wait(void *args)
device = find_device_from_fd(pfd[i].fd); device = find_device_from_fd(pfd[i].fd);
if (device) device->read_report(&device->unix_device); if (device) device->read_report(&device->unix_device);
} }
RtlLeaveCriticalSection(&udev_cs); pthread_mutex_unlock(&udev_cs);
} }
TRACE("UDEV main loop exiting\n"); TRACE("UDEV main loop exiting\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment