Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions libusb/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ struct hid_device_ {
/* Read thread objects */
hidapi_thread_state thread_state;
int shutdown_thread;
int read_interrupted;
int libusb_read_interrupted;
int transfer_loop_finished;
int read_thread_init_error;
struct libusb_transfer *transfer;
Expand Down Expand Up @@ -1821,7 +1821,7 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t
interrupt state first: an interrupted read fails even when input is
queued. Queued reports remain readable after
hid_read_clear_interrupt(). */
if (dev->read_interrupted) {
if (dev->libusb_read_interrupted) {
bytes_read = -1;
register_read_error(dev, "hid_read(_timeout): operation interrupted");
goto ret;
Expand All @@ -1844,13 +1844,13 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t

if (milliseconds == -1) {
/* Blocking */
while (dev->input_ring.count == 0 && !dev->shutdown_thread && !dev->read_interrupted) {
while (dev->input_ring.count == 0 && !dev->shutdown_thread && !dev->libusb_read_interrupted) {
hidapi_thread_cond_wait(&dev->thread_state);
}
if (dev->input_ring.count > 0) {
bytes_read = ring_pop_into(dev, data, length);
}
else if (dev->read_interrupted) {
else if (dev->libusb_read_interrupted) {
register_read_error(dev, "hid_read(_timeout): operation interrupted");
}
else {
Expand All @@ -1865,14 +1865,14 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t
hidapi_thread_gettime(&ts);
hidapi_thread_addtime(&ts, milliseconds);

while (dev->input_ring.count == 0 && !dev->shutdown_thread && !dev->read_interrupted) {
while (dev->input_ring.count == 0 && !dev->shutdown_thread && !dev->libusb_read_interrupted) {
res = hidapi_thread_cond_timedwait(&dev->thread_state, &ts);
if (res == 0) {
if (dev->input_ring.count > 0) {
bytes_read = ring_pop_into(dev, data, length);
break;
}
if (dev->read_interrupted) {
if (dev->libusb_read_interrupted) {
register_read_error(dev, "hid_read(_timeout): operation interrupted");
break;
}
Expand Down Expand Up @@ -1953,7 +1953,7 @@ int HID_API_EXPORT hid_set_nonblocking(hid_device *dev, int nonblock)
void HID_API_EXPORT hid_read_interrupt(hid_device *dev)
{
hidapi_thread_mutex_lock(&dev->thread_state);
dev->read_interrupted = 1;
dev->libusb_read_interrupted = 1;
hidapi_thread_cond_broadcast(&dev->thread_state);
hidapi_thread_mutex_unlock(&dev->thread_state);
}
Expand All @@ -1962,7 +1962,7 @@ void HID_API_EXPORT hid_read_interrupt(hid_device *dev)
int HID_API_EXPORT hid_is_read_interrupted(hid_device *dev)
{
hidapi_thread_mutex_lock(&dev->thread_state);
int v = dev->read_interrupted;
int v = dev->libusb_read_interrupted;
hidapi_thread_mutex_unlock(&dev->thread_state);
return v;
}
Expand All @@ -1971,7 +1971,7 @@ int HID_API_EXPORT hid_is_read_interrupted(hid_device *dev)
void HID_API_EXPORT hid_read_clear_interrupt(hid_device *dev)
{
hidapi_thread_mutex_lock(&dev->thread_state);
dev->read_interrupted = 0;
dev->libusb_read_interrupted = 0;
hidapi_thread_mutex_unlock(&dev->thread_state);
}

Expand Down
20 changes: 10 additions & 10 deletions mac/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ struct hid_device_ {
pthread_barrier_t barrier; /* Ensures correct startup sequence */
pthread_barrier_t shutdown_barrier; /* Ensures correct shutdown sequence */
int shutdown_thread;
int read_interrupted;
int mac_read_interrupted;
wchar_t *last_error_str;
wchar_t *last_read_error_str;
};
Expand All @@ -163,7 +163,7 @@ static hid_device *new_hid_device(void)
dev->input_report_buf = NULL;
dev->device_info = NULL;
dev->shutdown_thread = 0;
dev->read_interrupted = 0;
dev->mac_read_interrupted = 0;
dev->last_error_str = NULL;
dev->last_read_error_str = NULL;

Expand Down Expand Up @@ -1192,7 +1192,7 @@ static int cond_wait(hid_device *dev, pthread_cond_t *cond, pthread_mutex_t *mut
to sleep. See the pthread_cond_timedwait() man page for
details. */

if (dev->shutdown_thread || dev->disconnected || dev->read_interrupted) {
if (dev->shutdown_thread || dev->disconnected || dev->mac_read_interrupted) {
return -1;
}
}
Expand All @@ -1213,7 +1213,7 @@ static int cond_timedwait(hid_device *dev, pthread_cond_t *cond, pthread_mutex_t
to sleep. See the pthread_cond_timedwait() man page for
details. */

if (dev->shutdown_thread || dev->disconnected || dev->read_interrupted) {
if (dev->shutdown_thread || dev->disconnected || dev->mac_read_interrupted) {
return -1;
}
}
Expand All @@ -1239,7 +1239,7 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t
interrupt state first: an interrupted read fails even when input is
queued. Queued reports remain readable after
hid_read_clear_interrupt(). */
if (dev->read_interrupted) {
if (dev->mac_read_interrupted) {
bytes_read = -1;
register_error_str(&dev->last_read_error_str, "hid_read_timeout: operation interrupted");
goto ret;
Expand Down Expand Up @@ -1275,7 +1275,7 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t
res = cond_wait(dev, &dev->condition, &dev->mutex);
if (res == 0)
bytes_read = ring_pop_into(dev, data, length);
else if (dev->read_interrupted) {
else if (dev->mac_read_interrupted) {
register_error_str(&dev->last_read_error_str, "hid_read_timeout: operation interrupted");
bytes_read = -1;
} else {
Expand Down Expand Up @@ -1303,7 +1303,7 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t
bytes_read = ring_pop_into(dev, data, length);
} else if (res == ETIMEDOUT) {
bytes_read = 0;
} else if (dev->read_interrupted) {
} else if (dev->mac_read_interrupted) {
register_error_str(&dev->last_read_error_str, "hid_read_timeout: operation interrupted");
bytes_read = -1;
} else {
Expand Down Expand Up @@ -1364,23 +1364,23 @@ int HID_API_EXPORT hid_set_nonblocking(hid_device *dev, int nonblock)
void HID_API_EXPORT hid_read_interrupt(hid_device *dev)
{
pthread_mutex_lock(&dev->mutex);
dev->read_interrupted = 1;
dev->mac_read_interrupted = 1;
pthread_cond_broadcast(&dev->condition);
pthread_mutex_unlock(&dev->mutex);
}

int HID_API_EXPORT hid_is_read_interrupted(hid_device *dev)
{
pthread_mutex_lock(&dev->mutex);
int v = dev->read_interrupted;
int v = dev->mac_read_interrupted;
pthread_mutex_unlock(&dev->mutex);
return v;
}

void HID_API_EXPORT hid_read_clear_interrupt(hid_device *dev)
{
pthread_mutex_lock(&dev->mutex);
dev->read_interrupted = 0;
dev->mac_read_interrupted = 0;
pthread_mutex_unlock(&dev->mutex);
}

Expand Down
Loading