Skip to content

Commit

Permalink
Fix alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
k1-801 committed Apr 7, 2024
1 parent 59dae19 commit 6bec901
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions libusb/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,7 @@ static void hid_internal_invoke_callbacks(struct hid_device_info* info, hid_hotp
}
current = &callback->next;
}

hid_hotplug_context.mutex_state = 1;
pthread_mutex_unlock(&hid_hotplug_context.cb_mutex);
}
Expand Down
2 changes: 2 additions & 0 deletions linux/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,7 @@ void HID_API_EXPORT hid_free_enumeration(struct hid_device_info *devs)
static void hid_internal_invoke_callbacks(struct hid_device_info *info, hid_hotplug_event event)
{
hid_hotplug_context.mutex_state = 2;

struct hid_hotplug_callback **current = &hid_hotplug_context.hotplug_cbs;
while (*current) {
struct hid_hotplug_callback *callback = *current;
Expand All @@ -1126,6 +1127,7 @@ static void hid_internal_invoke_callbacks(struct hid_device_info *info, hid_hotp
}
current = &callback->next;
}

hid_hotplug_context.mutex_state = 1;
}

Expand Down
12 changes: 6 additions & 6 deletions mac/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -932,23 +932,25 @@ void HID_API_EXPORT hid_free_enumeration(struct hid_device_info *devs)

static void hid_internal_invoke_callbacks(struct hid_device_info *info, hid_hotplug_event event)
{
hid_hotplug_context.mutex_state = 2;

struct hid_hotplug_callback **current = &hid_hotplug_context.hotplug_cbs;
while (*current) {
struct hid_hotplug_callback *callback = *current;
if ((callback->events & event) && hid_internal_match_device_id(info->vendor_id, info->product_id,
callback->vendor_id, callback->product_id)) {
int result = callback->callback(callback->handle, info, event, callback->user_data);
/* If the result is non-zero, we remove the callback and proceed */
/* If the result is non-zero, we mark the callback for removal and proceed */
/* Do not use the deregister call as it locks the mutex, and we are currently in a lock */
if (result) {
struct hid_hotplug_callback *callback = *current;
*current = (*current)->next;
free(callback);
(*current)->events = 0;
continue;
}
}
current = &callback->next;
}

hid_hotplug_context.mutex_state = 1;
}

static void hid_internal_hotplug_connect_callback(void *context, IOReturn result, void *sender, IOHIDDeviceRef device)
Expand All @@ -968,7 +970,6 @@ static void hid_internal_hotplug_connect_callback(void *context, IOReturn result
{
/* Lock the mutex to avoid race conditions */
pthread_mutex_lock(&hid_hotplug_context.mutex);
hid_hotplug_context.mutex_state = 2;

/* Invoke all callbacks */
while(info_cur)
Expand All @@ -994,7 +995,6 @@ static void hid_internal_hotplug_connect_callback(void *context, IOReturn result

if (hid_hotplug_context.thread_state > 0)
{
hid_hotplug_context.mutex_state = 1;
pthread_mutex_unlock(&hid_hotplug_context.mutex);
}
}
Expand Down

0 comments on commit 6bec901

Please sign in to comment.