From 213ffc2bdfb63f211de58f7d6ec3463734d545f0 Mon Sep 17 00:00:00 2001 From: Tormod Volden Date: Sun, 12 May 2024 15:29:06 +0200 Subject: [PATCH] Use preprocessor macros instead of enums for event flag constants Signed-off-by: Tormod Volden --- libusb/core.c | 2 +- libusb/io.c | 20 ++++++++++---------- libusb/libusbi.h | 27 +++++++++++++-------------- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/libusb/core.c b/libusb/core.c index dcc027ce4..010201c5f 100644 --- a/libusb/core.c +++ b/libusb/core.c @@ -1603,7 +1603,7 @@ void API_EXPORTED libusb_close(libusb_device_handle *dev_handle) * Clear the event pipe if there are no further pending events. */ usbi_mutex_lock(&ctx->event_data_lock); if (!--ctx->device_close) - ctx->event_flags &= ~(unsigned int)USBI_EVENT_DEVICE_CLOSE; + ctx->event_flags &= ~USBI_EVENT_DEVICE_CLOSE; if (!ctx->event_flags) usbi_clear_event(&ctx->event); usbi_mutex_unlock(&ctx->event_data_lock); diff --git a/libusb/io.c b/libusb/io.c index dec8ec897..038824c9d 100644 --- a/libusb/io.c +++ b/libusb/io.c @@ -2117,35 +2117,35 @@ static int handle_event_trigger(struct libusb_context *ctx) usbi_mutex_lock(&ctx->event_data_lock); /* check if someone modified the event sources */ - if (ctx->event_flags & (unsigned int)USBI_EVENT_EVENT_SOURCES_MODIFIED) + if (ctx->event_flags & USBI_EVENT_EVENT_SOURCES_MODIFIED) usbi_dbg(ctx, "someone updated the event sources"); - if (ctx->event_flags & (unsigned int)USBI_EVENT_USER_INTERRUPT) { + if (ctx->event_flags & USBI_EVENT_USER_INTERRUPT) { usbi_dbg(ctx, "someone purposefully interrupted"); - ctx->event_flags &= ~(unsigned int)USBI_EVENT_USER_INTERRUPT; + ctx->event_flags &= ~USBI_EVENT_USER_INTERRUPT; } - if (ctx->event_flags & (unsigned int)USBI_EVENT_HOTPLUG_CB_DEREGISTERED) { + if (ctx->event_flags & USBI_EVENT_HOTPLUG_CB_DEREGISTERED) { usbi_dbg(ctx, "someone unregistered a hotplug cb"); - ctx->event_flags &= ~(unsigned int)USBI_EVENT_HOTPLUG_CB_DEREGISTERED; + ctx->event_flags &= ~USBI_EVENT_HOTPLUG_CB_DEREGISTERED; hotplug_event = 1; } /* check if someone is closing a device */ - if (ctx->event_flags & (unsigned int)USBI_EVENT_DEVICE_CLOSE) + if (ctx->event_flags & USBI_EVENT_DEVICE_CLOSE) usbi_dbg(ctx, "someone is closing a device"); /* check for any pending hotplug messages */ if (ctx->event_flags & USBI_EVENT_HOTPLUG_MSG_PENDING) { usbi_dbg(ctx, "hotplug message received"); - ctx->event_flags &= ~(unsigned int)USBI_EVENT_HOTPLUG_MSG_PENDING; + ctx->event_flags &= ~USBI_EVENT_HOTPLUG_MSG_PENDING; hotplug_event = 1; assert(!list_empty(&ctx->hotplug_msgs)); list_cut(&hotplug_msgs, &ctx->hotplug_msgs); } /* complete any pending transfers */ - if (ctx->event_flags & (unsigned int)USBI_EVENT_TRANSFER_COMPLETED) { + if (ctx->event_flags & USBI_EVENT_TRANSFER_COMPLETED) { struct usbi_transfer *itransfer, *tmp; struct list_head completed_transfers; @@ -2167,7 +2167,7 @@ static int handle_event_trigger(struct libusb_context *ctx) /* an error occurred, put the remaining transfers back on the list */ list_splice_front(&completed_transfers, &ctx->completed_transfers); } else if (list_empty(&ctx->completed_transfers)) { - ctx->event_flags &= ~(unsigned int)USBI_EVENT_TRANSFER_COMPLETED; + ctx->event_flags &= ~USBI_EVENT_TRANSFER_COMPLETED; } } @@ -2232,7 +2232,7 @@ static int handle_events(struct libusb_context *ctx, struct timeval *tv) } /* reset the flag now that we have the updated list */ - ctx->event_flags &= ~(unsigned int)USBI_EVENT_EVENT_SOURCES_MODIFIED; + ctx->event_flags &= ~USBI_EVENT_EVENT_SOURCES_MODIFIED; /* if no further pending events, clear the event so that we do * not immediately return from the wait function */ diff --git a/libusb/libusbi.h b/libusb/libusbi.h index 6d19a930c..5cbc69e9d 100644 --- a/libusb/libusbi.h +++ b/libusb/libusbi.h @@ -471,25 +471,24 @@ static inline struct libusb_context *usbi_get_context(struct libusb_context *ctx return ctx; } -enum usbi_event_flags { - /* The list of event sources has been modified */ - USBI_EVENT_EVENT_SOURCES_MODIFIED = 1U << 0, +/* event flags of the ctx structure */ +/* The list of event sources has been modified */ +#define USBI_EVENT_EVENT_SOURCES_MODIFIED (1U << 0) - /* The user has interrupted the event handler */ - USBI_EVENT_USER_INTERRUPT = 1U << 1, +/* The user has interrupted the event handler */ +#define USBI_EVENT_USER_INTERRUPT (1U << 1) - /* A hotplug callback deregistration is pending */ - USBI_EVENT_HOTPLUG_CB_DEREGISTERED = 1U << 2, +/* A hotplug callback deregistration is pending */ +#define USBI_EVENT_HOTPLUG_CB_DEREGISTERED (1U << 2) - /* One or more hotplug messages are pending */ - USBI_EVENT_HOTPLUG_MSG_PENDING = 1U << 3, +/* One or more hotplug messages are pending */ +#define USBI_EVENT_HOTPLUG_MSG_PENDING (1U << 3) - /* One or more completed transfers are pending */ - USBI_EVENT_TRANSFER_COMPLETED = 1U << 4, +/* One or more completed transfers are pending */ +#define USBI_EVENT_TRANSFER_COMPLETED (1U << 4) - /* A device is in the process of being closed */ - USBI_EVENT_DEVICE_CLOSE = 1U << 5, -}; +/* A device is in the process of being closed */ +#define USBI_EVENT_DEVICE_CLOSE (1U << 5) /* Macros for managing event handling state */ static inline int usbi_handling_events(struct libusb_context *ctx)