/* 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) {
}
/* 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 */
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 */
/* 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);
}
/* 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;
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)
/* 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