Fixed long delay on main thread caused by blocking rumble writes in HIDAPI drivers

There is now a thread that handles all HIDAPI rumble requests and a lock that guarantees that we're not reading and writing the device at the same time.
This commit is contained in:
Sam Lantinga
2020-02-04 15:26:56 -08:00
parent 6efebf1768
commit 1684606fdf
7 changed files with 44 additions and 19 deletions

View File

@@ -23,6 +23,10 @@
#ifndef SDL_JOYSTICK_HIDAPI_H
#define SDL_JOYSTICK_HIDAPI_H
#include "SDL_atomic.h"
#include "SDL_mutex.h"
#include "SDL_joystick.h"
#include "SDL_gamecontroller.h"
#include "../../hidapi/hidapi/hidapi.h"
#include "../usb_ids.h"
@@ -50,6 +54,9 @@
#define SDL_JOYSTICK_HIDAPI_STEAM
#endif
/* The maximum size of a USB packet for HID devices */
#define USB_PACKET_LENGTH 64
/* Forward declaration */
struct _SDL_HIDAPI_DeviceDriver;
@@ -70,7 +77,9 @@ typedef struct _SDL_HIDAPI_Device
struct _SDL_HIDAPI_DeviceDriver *driver;
void *context;
SDL_mutex *dev_lock;
hid_device *dev;
SDL_atomic_t rumble_pending;
int num_joysticks;
SDL_JoystickID *joysticks;
@@ -98,9 +107,6 @@ typedef struct _SDL_HIDAPI_DeviceDriver
} SDL_HIDAPI_DeviceDriver;
/* The maximum size of a USB packet for HID devices */
#define USB_PACKET_LENGTH 64
/* HIDAPI device support */
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS4;
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteam;