diff options
author | Chris Dickens <christopher.a.dickens@gmail.com> | 2015-12-09 23:45:21 -0800 |
---|---|---|
committer | Chris Dickens <christopher.a.dickens@gmail.com> | 2015-12-17 00:28:20 -0800 |
commit | 87a97e4f2065cc7190b0098b4d0df5a68e10a547 (patch) | |
tree | 41208e5bd779ac1b871a5fd680ae5b9ee878376c | |
parent | b7526c19a57e9c584bdc689fa2447804580dbf94 (diff) | |
download | libusb-87a97e4f2065cc7190b0098b4d0df5a68e10a547.tar.gz |
core: Store different event types as a bitmask within the context
This change introduces a new event_flags member to the libusb_context
that holds a bitmask of different events that have occurred. This will
allow multiple "one-shot" events (those that don't require counting) to
be stored in a single variable. The only existing event of this type,
pollfds_modified, has been converted to use this bitmask instead.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
-rw-r--r-- | libusb/io.c | 8 | ||||
-rw-r--r-- | libusb/libusbi.h | 16 | ||||
-rw-r--r-- | libusb/version_nano.h | 2 |
3 files changed, 16 insertions, 10 deletions
diff --git a/libusb/io.c b/libusb/io.c index 01cf5be..2b2bf29 100644 --- a/libusb/io.c +++ b/libusb/io.c @@ -2070,7 +2070,7 @@ static int handle_events(struct libusb_context *ctx, struct timeval *tv) /* only reallocate the poll fds when the list of poll fds has been modified * since the last poll, otherwise reuse them to save the additional overhead */ usbi_mutex_lock(&ctx->event_data_lock); - if (ctx->pollfds_modified) { + if (ctx->event_flags & USBI_EVENT_POLLFDS_MODIFIED) { usbi_dbg("poll fds modified, reallocating"); if (ctx->pollfds) { @@ -2097,7 +2097,7 @@ static int handle_events(struct libusb_context *ctx, struct timeval *tv) } /* reset the flag now that we have the updated list */ - ctx->pollfds_modified = 0; + ctx->event_flags &= ~USBI_EVENT_POLLFDS_MODIFIED; /* if no further pending events, clear the event pipe so that we do * not immediately return from poll */ @@ -2146,7 +2146,7 @@ redo_poll: usbi_mutex_lock(&ctx->event_data_lock); /* check if someone added a new poll fd */ - if (ctx->pollfds_modified) + if (ctx->event_flags & USBI_EVENT_POLLFDS_MODIFIED) usbi_dbg("someone updated the poll fds"); /* check if someone is closing a device */ @@ -2606,7 +2606,7 @@ static void usbi_fd_notification(struct libusb_context *ctx) /* Record that there is a new poll fd. * Only signal an event if there are no prior pending events. */ pending_events = usbi_pending_events(ctx); - ctx->pollfds_modified = 1; + ctx->event_flags |= USBI_EVENT_POLLFDS_MODIFIED; if (!pending_events) usbi_signal_event(ctx); } diff --git a/libusb/libusbi.h b/libusb/libusbi.h index f1afd99..73d3492 100644 --- a/libusb/libusbi.h +++ b/libusb/libusbi.h @@ -291,18 +291,19 @@ struct libusb_context { /* A lock to protect internal context event data. */ usbi_mutex_t event_data_lock; + /* A bitmask of flags that are set to indicate specific events that need to + * be handled. Protected by event_data_lock. */ + unsigned int event_flags; + /* A counter that is set when we want to interrupt and prevent event handling, * in order to safely close a device. Protected by event_data_lock. */ unsigned int device_close; /* list and count of poll fds and an array of poll fd structures that is - * (re)allocated as necessary prior to polling, and a flag to indicate - * when the list of poll fds has changed since the last poll. - * Protected by event_data_lock. */ + * (re)allocated as necessary prior to polling. Protected by event_data_lock. */ struct list_head ipollfds; struct pollfd *pollfds; POLL_NFDS_TYPE pollfds_cnt; - unsigned int pollfds_modified; /* A list of pending hotplug messages. Protected by event_data_lock. */ struct list_head hotplug_msgs; @@ -319,6 +320,11 @@ struct libusb_context { struct list_head list; }; +enum usbi_event_flags { + /* The list of pollfds has been modified */ + USBI_EVENT_POLLFDS_MODIFIED = 1 << 0, +}; + /* Macros for managing event handling state */ #define usbi_handling_events(ctx) \ (usbi_tls_key_get((ctx)->event_handling_key) != NULL) @@ -331,7 +337,7 @@ struct libusb_context { /* Update the following macro if new event sources are added */ #define usbi_pending_events(ctx) \ - ((ctx)->device_close || (ctx)->pollfds_modified \ + ((ctx)->event_flags || (ctx)->device_close \ || !list_empty(&(ctx)->hotplug_msgs) || !list_empty(&(ctx)->completed_transfers)) #ifdef USBI_TIMERFD_AVAILABLE diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 0e62923..53bfa23 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11015 +#define LIBUSB_NANO 11016 |