// Wait for some event static bool poll_uv_loop(int32_t ms) { bool timed_out; uv_run_mode run_mode = UV_RUN_ONCE; if (input_ready()) { // If there's a pending input event to be consumed, do it now return true; } input_start(); timed_out = false; if (ms > 0) { // Timeout passed as argument to the timer timer.data = &timed_out; // We only start the timer after the loop is running, for that we // use an prepare handle(pass the interval as data to it) timer_prepare.data = &ms; uv_prepare_start(&timer_prepare, timer_prepare_cb); } else if (ms == 0) { // For ms == 0, we need to do a non-blocking event poll by // setting the run mode to UV_RUN_NOWAIT. run_mode = UV_RUN_NOWAIT; } do { // Run one event loop iteration, blocking for events if run_mode is // UV_RUN_ONCE uv_run(uv_default_loop(), run_mode); } while ( // Continue running if ... !input_ready() && // we have no input !has_pending_events() && // no events are waiting to be processed run_mode != UV_RUN_NOWAIT && // ms != 0 !timed_out // we didn't get a timeout ); input_stop(); if (ms > 0) { // Stop the timer uv_timer_stop(&timer); } return input_ready() || has_pending_events(); }
std::vector<std::string> FlotillaDock::get_pending_events(void){ std::vector<std::string> events; mutex.lock(); while (has_pending_events()){ events.push_back(event_queue.front()); event_queue.pop(); } mutex.unlock(); return events; }
// Runs the appropriate action for each queued event static void process_all_events() { EventNode *next; Event *event; while (has_pending_events()) { next = head->next; event = head->event; free(head); head = next; switch (event->type) { case kEventSignal: signal_handle(event); break; default: abort(); } } }