summaryrefslogtreecommitdiff
path: root/libusb/hotplug.c
diff options
context:
space:
mode:
authorChris Dickens <christopher.a.dickens@gmail.com>2020-08-10 19:01:42 -0700
committerChris Dickens <christopher.a.dickens@gmail.com>2020-08-10 19:01:42 -0700
commit9576ad4b8f94698aeba5218caf9e9e1f28a6f44d (patch)
tree77443a6323fd8518c6c98e8cff764e18d395b95d /libusb/hotplug.c
parent96898a25ccfde6e87737991000a41695ed6b3812 (diff)
downloadlibusb-9576ad4b8f94698aeba5218caf9e9e1f28a6f44d.tar.gz
core: Introduce list iteration helpers
The syntax for traversing over lists is somewhat cluttered. It could be made much better with the use of the 'typeof' keyword, but unfortunately this is not universally supported by all compilers. We can, however, improve the situation by introducing some macros for the common cases. To that end, this commit introduces a number of 'for_each' macros that iterate over a specific linked list. Current syntax: list_for_each_entry(itransfer, &ctx->flying_transfers, list, struct usbi_transfer) New syntax: for_each_transfer(ctx, itransfer) Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Diffstat (limited to 'libusb/hotplug.c')
-rw-r--r--libusb/hotplug.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/libusb/hotplug.c b/libusb/hotplug.c
index e3e83c3..c02cc56 100644
--- a/libusb/hotplug.c
+++ b/libusb/hotplug.c
@@ -184,7 +184,7 @@ void usbi_hotplug_match(struct libusb_context *ctx, struct libusb_device *dev,
usbi_mutex_lock(&ctx->hotplug_cbs_lock);
- list_for_each_entry_safe(hotplug_cb, next, &ctx->hotplug_cbs, list, struct libusb_hotplug_callback) {
+ for_each_hotplug_cb_safe(ctx, hotplug_cb, next) {
if (hotplug_cb->flags & USBI_HOTPLUG_NEEDS_FREE) {
/* process deregistration in usbi_hotplug_deregister() */
continue;
@@ -331,7 +331,7 @@ void API_EXPORTED libusb_hotplug_deregister_callback(libusb_context *ctx,
ctx = usbi_get_context(ctx);
usbi_mutex_lock(&ctx->hotplug_cbs_lock);
- list_for_each_entry(hotplug_cb, &ctx->hotplug_cbs, list, struct libusb_hotplug_callback) {
+ for_each_hotplug_cb(ctx, hotplug_cb) {
if (callback_handle == hotplug_cb->handle) {
/* Mark this callback for deregistration */
hotplug_cb->flags |= USBI_HOTPLUG_NEEDS_FREE;
@@ -369,7 +369,7 @@ void * LIBUSB_CALL libusb_hotplug_get_user_data(libusb_context *ctx,
ctx = usbi_get_context(ctx);
usbi_mutex_lock(&ctx->hotplug_cbs_lock);
- list_for_each_entry(hotplug_cb, &ctx->hotplug_cbs, list, struct libusb_hotplug_callback) {
+ for_each_hotplug_cb(ctx, hotplug_cb) {
if (callback_handle == hotplug_cb->handle) {
user_data = hotplug_cb->user_data;
}
@@ -384,7 +384,7 @@ void usbi_hotplug_deregister(struct libusb_context *ctx, int forced)
struct libusb_hotplug_callback *hotplug_cb, *next;
usbi_mutex_lock(&ctx->hotplug_cbs_lock);
- list_for_each_entry_safe(hotplug_cb, next, &ctx->hotplug_cbs, list, struct libusb_hotplug_callback) {
+ for_each_hotplug_cb_safe(ctx, hotplug_cb, next) {
if (forced || (hotplug_cb->flags & USBI_HOTPLUG_NEEDS_FREE)) {
usbi_dbg("freeing hotplug cb %p with handle %d", hotplug_cb,
hotplug_cb->handle);