Ejemplo n.º 1
0
/*
 * lms_mux_init() initializes the I/O multiplexer
 *
 */
int lms_mux_init()
{
	register unsigned int i;

	lms_mux_evtb = event_init();
	event_priority_init(6);

	for (i = 0; i < LMS_HIGHSOCK; ++i)
	{
		_lms_mux_revents[i] = (struct event *)NULL;
		_lms_mux_wevents[i] = (struct event *)NULL;
	}

	return(0);
}
Ejemplo n.º 2
0
/*
 * Set up a thread's information.
 */
static void setup_thread(LIBEVENT_THREAD *me) {
    me->base = event_init();
    if (! me->base) {
        fprintf(stderr, "Can't allocate event base\n");
        exit(1);
    }

#ifdef DUP_AWARE
    event_priority_init(NUM_PRIORITIES);
#endif

    /* Listen for notifications from other threads */
    event_set(&me->notify_event, me->notify_receive_fd,
              EV_READ | EV_PERSIST, thread_libevent_process, me);
    event_base_set(me->base, &me->notify_event);

    if (event_add(&me->notify_event, 0) == -1) {
        fprintf(stderr, "Can't monitor libevent notify pipe\n");
        exit(1);
    }

    me->new_conn_queue = malloc(sizeof(struct conn_queue));
    if (me->new_conn_queue == NULL) {
        perror("Failed to allocate memory for connection queue");
        exit(EXIT_FAILURE);
    }
    cq_init(me->new_conn_queue);

    if (pthread_mutex_init(&me->stats.mutex, NULL) != 0) {
        perror("Failed to initialize mutex");
        exit(EXIT_FAILURE);
    }

    me->suffix_cache = cache_create("suffix", SUFFIX_SIZE, sizeof(char*),
                                    NULL, NULL);
    if (me->suffix_cache == NULL) {
        fprintf(stderr, "Failed to create suffix cache\n");
        exit(EXIT_FAILURE);
    }
}