int Context::eventHandlingOK(State & state, Context_wrapper * wrapper){ Stack * stack = state.stack; int result = 0; result = libusb_event_handling_ok(wrapper->context); stack->push<bool>(result == 1); return 1; }
/* ---- * device_handle_events() * * Function called by device_read() and device_write() to perform * the multi-thread correct event handling. * ---- */ static int device_handle_events(Open8055Card *card, int *completed) { int rc = 0; struct timeval tv; Py_BEGIN_ALLOW_THREADS while (!*completed && rc == 0) { if (libusb_try_lock_events(libusbCxt) == 0) { /* ---- * We got the event lock, so we are the event handler. * ---- */ while(!*completed) { if (!libusb_event_handling_ok(libusbCxt)) { libusb_unlock_events(libusbCxt); break; } tv.tv_sec = 1; tv.tv_usec = 0; rc = libusb_handle_events_locked(libusbCxt, &tv); if (rc != 0) break; } libusb_unlock_events(libusbCxt); } else { /* ---- * Somebody else is handling events ... wait for them. * ---- */ libusb_lock_event_waiters(libusbCxt); while (!completed) { /* ---- * Now that we have the waiters lock, recheck that * somebody is really processing events. * ---- */ if (!libusb_event_handler_active(libusbCxt)) break; /* ---- * OK to really wait now. * ---- */ libusb_wait_for_event(libusbCxt, NULL); } libusb_unlock_event_waiters(libusbCxt); } } Py_END_ALLOW_THREADS return rc; }