Ejemplo n.º 1
0
void
libusb_exit(libusb_context *ctx)
{
	ctx = GET_CONTEXT(ctx);

	if (ctx == NULL)
		return;

	/* stop hotplug thread, if any */

	if (ctx->hotplug_handler != NO_THREAD) {
		pthread_t td;
		void *ptr;

		HOTPLUG_LOCK(ctx);
		td = ctx->hotplug_handler;
		ctx->hotplug_handler = NO_THREAD;
		HOTPLUG_UNLOCK(ctx);

		pthread_join(td, &ptr);
	}

	/* XXX cleanup devices */

	libusb10_remove_pollfd(ctx, &ctx->ctx_poll);
	close(ctx->ctrl_pipe[0]);
	close(ctx->ctrl_pipe[1]);
	pthread_mutex_destroy(&ctx->ctx_lock);
	pthread_mutex_destroy(&ctx->hotplug_lock);
	pthread_cond_destroy(&ctx->ctx_cond);

	pthread_mutex_lock(&default_context_lock);
	if (ctx == usbi_default_context) {
		usbi_default_context = NULL;
	}
	pthread_mutex_unlock(&default_context_lock);

	free(ctx);
}
Ejemplo n.º 2
0
void
libusb_exit(libusb_context *ctx)
{
	ctx = GET_CONTEXT(ctx);

	if (ctx == NULL)
		return;

	/* XXX cleanup devices */

	libusb10_remove_pollfd(ctx, &ctx->ctx_poll);
	close(ctx->ctrl_pipe[0]);
	close(ctx->ctrl_pipe[1]);
	pthread_mutex_destroy(&ctx->ctx_lock);
	pthread_cond_destroy(&ctx->ctx_cond);

	pthread_mutex_lock(&default_context_lock);
	if (ctx == usbi_default_context) {
		usbi_default_context = NULL;
	}
	pthread_mutex_unlock(&default_context_lock);

	free(ctx);
}