void *router_core_thread(void *arg) { qdr_core_t *core = (qdr_core_t*) arg; qdr_action_list_t action_list; qdr_action_t *action; qdr_forwarder_setup_CT(core); qdr_route_table_setup_CT(core); qdr_agent_setup_CT(core); qd_log(core->log, QD_LOG_INFO, "Router Core thread running. %s/%s", core->router_area, core->router_id); while (core->running) { // // Use the lock only to protect the condition variable and the action list // sys_mutex_lock(core->action_lock); // // Block on the condition variable when there is no action to do // while (core->running && DEQ_IS_EMPTY(core->action_list)) sys_cond_wait(core->action_cond, core->action_lock); // // Move the entire action list to a private list so we can process it without // holding the lock // DEQ_MOVE(core->action_list, action_list); sys_mutex_unlock(core->action_lock); // // Process and free all of the action items in the list // action = DEQ_HEAD(action_list); while (action) { DEQ_REMOVE_HEAD(action_list); if (action->label) qd_log(core->log, QD_LOG_TRACE, "Core action '%s'%s", action->label, core->running ? "" : " (discard)"); action->action_handler(core, action, !core->running); free_qdr_action_t(action); action = DEQ_HEAD(action_list); } } qd_log(core->log, QD_LOG_INFO, "Router Core thread exited"); return 0; }
static void qdr_general_handler(void *context) { qdr_core_t *core = (qdr_core_t*) context; qdr_general_work_list_t work_list; qdr_general_work_t *work; sys_mutex_lock(core->work_lock); DEQ_MOVE(core->work_list, work_list); sys_mutex_unlock(core->work_lock); work = DEQ_HEAD(work_list); while (work) { DEQ_REMOVE_HEAD(work_list); work->handler(core, work); free_qdr_general_work_t(work); work = DEQ_HEAD(work_list); } }