* thread from doing event handling) because we will be removing a file
* descriptor from the polling loop. */
- /* record that we are messing with poll fds */
- usbi_mutex_lock(&ctx->pollfd_modify_lock);
- ctx->pollfd_modify++;
- usbi_mutex_unlock(&ctx->pollfd_modify_lock);
+ /* record that we are closing a device */
+ usbi_mutex_lock(&ctx->device_close_lock);
+ ctx->device_close++;
+ usbi_mutex_unlock(&ctx->device_close_lock);
/* write some data on control pipe to interrupt event handlers */
r = usbi_write(ctx->ctrl_pipe[1], &dummy, sizeof(dummy));
if (r <= 0) {
usbi_warn(ctx, "internal signalling write failed, closing anyway");
do_close(ctx, dev_handle);
- usbi_mutex_lock(&ctx->pollfd_modify_lock);
- ctx->pollfd_modify--;
- usbi_mutex_unlock(&ctx->pollfd_modify_lock);
+ usbi_mutex_lock(&ctx->device_close_lock);
+ ctx->device_close--;
+ usbi_mutex_unlock(&ctx->device_close_lock);
return;
}
/* Close the device */
do_close(ctx, dev_handle);
- /* we're done with modifying poll fds */
- usbi_mutex_lock(&ctx->pollfd_modify_lock);
- ctx->pollfd_modify--;
- usbi_mutex_unlock(&ctx->pollfd_modify_lock);
+ /* we're done with closing this device */
+ usbi_mutex_lock(&ctx->device_close_lock);
+ ctx->device_close--;
+ usbi_mutex_unlock(&ctx->device_close_lock);
/* Release event handling lock and wake up event waiters */
libusb_unlock_events(ctx);
usbi_mutex_init(&ctx->flying_transfers_lock, NULL);
usbi_mutex_init(&ctx->pollfds_lock, NULL);
- usbi_mutex_init(&ctx->pollfd_modify_lock, NULL);
+ usbi_mutex_init(&ctx->device_close_lock, NULL);
usbi_mutex_init_recursive(&ctx->events_lock, NULL);
usbi_mutex_init(&ctx->event_waiters_lock, NULL);
usbi_cond_init(&ctx->event_waiters_cond, NULL);
err:
usbi_mutex_destroy(&ctx->flying_transfers_lock);
usbi_mutex_destroy(&ctx->pollfds_lock);
- usbi_mutex_destroy(&ctx->pollfd_modify_lock);
+ usbi_mutex_destroy(&ctx->device_close_lock);
usbi_mutex_destroy(&ctx->events_lock);
usbi_mutex_destroy(&ctx->event_waiters_lock);
usbi_cond_destroy(&ctx->event_waiters_cond);
#endif
usbi_mutex_destroy(&ctx->flying_transfers_lock);
usbi_mutex_destroy(&ctx->pollfds_lock);
- usbi_mutex_destroy(&ctx->pollfd_modify_lock);
+ usbi_mutex_destroy(&ctx->device_close_lock);
usbi_mutex_destroy(&ctx->events_lock);
usbi_mutex_destroy(&ctx->event_waiters_lock);
usbi_cond_destroy(&ctx->event_waiters_cond);
unsigned int ru;
USBI_GET_CONTEXT(ctx);
- /* is someone else waiting to modify poll fds? if so, don't let this thread
+ /* is someone else waiting to close a device? if so, don't let this thread
* start event handling */
- usbi_mutex_lock(&ctx->pollfd_modify_lock);
- ru = ctx->pollfd_modify;
- usbi_mutex_unlock(&ctx->pollfd_modify_lock);
+ usbi_mutex_lock(&ctx->device_close_lock);
+ ru = ctx->device_close;
+ usbi_mutex_unlock(&ctx->device_close_lock);
if (ru) {
- usbi_dbg("someone else is modifying poll fds");
+ usbi_dbg("someone else is closing a device");
return 1;
}
/* FIXME: perhaps we should be a bit more efficient by not broadcasting
* the availability of the events lock when we are modifying pollfds
- * (check ctx->pollfd_modify)? */
+ * (check ctx->device_close)? */
usbi_mutex_lock(&ctx->event_waiters_lock);
usbi_cond_broadcast(&ctx->event_waiters_cond);
usbi_mutex_unlock(&ctx->event_waiters_lock);
unsigned int r;
USBI_GET_CONTEXT(ctx);
- /* is someone else waiting to modify poll fds? if so, don't let this thread
+ /* is someone else waiting to close a device? if so, don't let this thread
* continue event handling */
- usbi_mutex_lock(&ctx->pollfd_modify_lock);
- r = ctx->pollfd_modify;
- usbi_mutex_unlock(&ctx->pollfd_modify_lock);
+ usbi_mutex_lock(&ctx->device_close_lock);
+ r = ctx->device_close;
+ usbi_mutex_unlock(&ctx->device_close_lock);
if (r) {
- usbi_dbg("someone else is modifying poll fds");
+ usbi_dbg("someone else is closing a device");
return 0;
}
unsigned int r;
USBI_GET_CONTEXT(ctx);
- /* is someone else waiting to modify poll fds? if so, don't let this thread
+ /* is someone else waiting to close a device? if so, don't let this thread
* start event handling -- indicate that event handling is happening */
- usbi_mutex_lock(&ctx->pollfd_modify_lock);
- r = ctx->pollfd_modify;
- usbi_mutex_unlock(&ctx->pollfd_modify_lock);
+ usbi_mutex_lock(&ctx->device_close_lock);
+ r = ctx->device_close;
+ usbi_mutex_unlock(&ctx->device_close_lock);
if (r) {
- usbi_dbg("someone else is modifying poll fds");
+ usbi_dbg("someone else is closing a device");
return 1;
}
/* read the dummy data from the control pipe unless someone is closing
* a device */
- usbi_mutex_lock(&ctx->pollfd_modify_lock);
- ru = ctx->pollfd_modify;
- usbi_mutex_unlock(&ctx->pollfd_modify_lock);
+ usbi_mutex_lock(&ctx->device_close_lock);
+ ru = ctx->device_close;
+ usbi_mutex_unlock(&ctx->device_close_lock);
if (!ru) {
ret = usbi_read(ctx->ctrl_pipe[0], &dummy, sizeof(dummy));
if (ret != sizeof(dummy)) {