/// Handle all pending signal events. static void event_fire_delayed() { // If is_event is one, we are running the event-handler non-recursively. // // When the event handler has called a piece of code that triggers another event, we do not want // to fire delayed events because of concurrency problems. if (!blocked.empty() && is_event == 1) { event_list_t new_blocked; for (size_t i = 0; i < blocked.size(); i++) { event_t *e = blocked.at(i); if (event_is_blocked(*e)) { new_blocked.push_back(new event_t(*e)); } else { event_fire_internal(*e); event_free(e); } } blocked.swap(new_blocked); } int al = active_list; while (sig_list[al].count > 0) { signal_list_t *lst; // Switch signal lists. sig_list[1 - al].count = 0; sig_list[1 - al].overflow = 0; al = 1 - al; active_list = al; // Set up. lst = &sig_list[1 - al]; event_t e = event_t::signal_event(0); e.arguments.resize(1); if (lst->overflow) { debug(0, _(L"Signal list overflow. Signals have been ignored.")); } // Send all signals in our private list. for (int i = 0; i < lst->count; i++) { e.param1.signal = lst->signal[i]; e.arguments.at(0) = sig2wcs(e.param1.signal); if (event_is_blocked(e)) { blocked.push_back(new event_t(e)); } else { event_fire_internal(e); } } } }
void event_fire(const event_t *event) { if (event && event->type == EVENT_SIGNAL) { event_fire_signal(event->param1.signal); } else { is_event++; /* Fire events triggered by signals */ event_fire_delayed(); if (event) { if (event_is_blocked(*event)) { blocked.push_back(new event_t(*event)); } else { event_fire_internal(*event); } } is_event--; } }
/** Handle all pending signal events */ static void event_fire_delayed() { size_t i; /* If is_event is one, we are running the event-handler non-recursively. When the event handler has called a piece of code that triggers another event, we do not want to fire delayed events because of concurrency problems. */ if (! blocked.empty() && is_event==1) { event_list_t new_blocked; for (i=0; i<blocked.size(); i++) { event_t *e = blocked.at(i); if (event_is_blocked(e)) { new_blocked.push_back(e); } else { event_fire_internal(e); event_free(e); } } blocked.swap(new_blocked); } while (sig_list[active_list].count > 0) { signal_list_t *lst; /* Switch signal lists */ sig_list[1-active_list].count=0; sig_list[1-active_list].overflow=0; active_list=1-active_list; /* Set up */ event_t e = event_t::signal_event(0); e.arguments.reset(new wcstring_list_t(1)); //one element lst = &sig_list[1-active_list]; if (lst->overflow) { debug(0, _(L"Signal list overflow. Signals have been ignored.")); } /* Send all signals in our private list */ for (int i=0; i < lst->count; i++) { e.param1.signal = lst->signal[i]; e.arguments->at(0) = sig2wcs(e.param1.signal); if (event_is_blocked(&e)) { blocked.push_back(event_copy(&e, 1)); } else { event_fire_internal(&e); } } e.arguments.reset(NULL); } }