Exemplo n.º 1
0
/**
 * event-handler thread
 *
 */
void *chassis_event_thread_loop(chassis_event_thread_t *thread) {
    cur_thid = thread->index;
    gboolean has_no_active_con = FALSE;

    /**
     * check once a second if we shall shutdown the proxy
     */
    while (!chassis_is_shutdown_immediate() && (!chassis_is_shutdown_normal() || !has_no_active_con)) {
        struct timeval timeout;
        int r;

        /* check exit status */
        if (chassis_is_shutdown_normal()) {
            if (thread->connection_nums == 0) {
            has_no_active_con = TRUE;
                g_log_dbproxy(g_debug, "no connection in thread %d", thread->index);
                continue;
            }
        }

        if (!chassis_is_shutdown_immediate()) {
            chassis_event_thread_update_conn_status(thread);
        }

        timeout.tv_sec = 1;
        timeout.tv_usec = 0;

        g_assert(event_base_loopexit(thread->event_base, &timeout) == 0);

        r = event_base_dispatch(thread->event_base);

        if (r == -1) {
#ifdef WIN32
            errno = WSAGetLastError();
#endif
            if (errno == EINTR) continue;
            g_log_dbproxy(g_critical, "leaving chassis_event_thread_loop early, errno != EINTR was: %s (%d)", g_strerror(errno), errno);
            break;
        }
    }

    g_log_dbproxy(g_message, "work thread %d will exit", thread->index);
    g_atomic_int_set(&thread->exit_phase, EVENT_THREAD_EXITED);

    return NULL;
}
Exemplo n.º 2
0
gboolean chassis_is_shutdown() {
    return (chassis_is_shutdown_normal() || chassis_is_shutdown_immediate());
}