Cleaned up local event queue.

Signed-off-by: Jan Vidar Krey <janvidar@extatic.org>
This commit is contained in:
Jan Vidar Krey 2009-03-18 02:56:49 +01:00
parent 4f8edfe9c8
commit c671851be8
6 changed files with 15 additions and 39 deletions

View File

@ -35,9 +35,8 @@ int event_queue_initialize(struct event_queue** queue, event_queue_callback call
(*queue)->q1 = list_create();
(*queue)->q2 = list_create();
(*queue)->event = (struct event*) hub_malloc_zero(sizeof(struct event));
if (!(*queue)->q1 || !(*queue)->q2 || !(*queue)->event)
if (!(*queue)->q1 || !(*queue)->q2)
{
list_destroy((*queue)->q1);
list_destroy((*queue)->q2);
@ -47,7 +46,6 @@ int event_queue_initialize(struct event_queue** queue, event_queue_callback call
(*queue)->callback = callback;
(*queue)->callback_data = ptr;
evtimer_set((*queue)->event, libevent_queue_process, *queue);
return 0;
}
@ -57,12 +55,6 @@ void event_queue_shutdown(struct event_queue* queue)
/* Should be empty at this point! */
list_destroy(queue->q1);
list_destroy(queue->q2);
if (queue->event)
{
evtimer_del(queue->event);
hub_free(queue->event);
}
hub_free(queue);
}
@ -135,12 +127,6 @@ void event_queue_post(struct event_queue* queue, struct event_data* message)
#endif
list_append(q, data);
if (!queue->locked && queue->event)
{
libevent_queue_schedule(queue);
}
}
else
{
@ -154,19 +140,5 @@ size_t event_queue_size(struct event_queue* queue)
return list_size(queue->q1) + list_size(queue->q2);
}
void libevent_queue_schedule(struct event_queue* queue)
{
struct timeval zero = { 0, };
evtimer_add(queue->event, &zero);
}
void libevent_queue_process(int fd, short events, void* arg)
{
struct event_queue* queue = (struct event_queue*) arg;
if (event_queue_process(queue))
{
libevent_queue_schedule(queue);
}
}

View File

@ -36,7 +36,6 @@ struct event_queue
struct linked_list* q2; /* secondary, when primary is locked */
event_queue_callback callback;
void* callback_data;
struct event* event; /* libevent handle */
};
extern int event_queue_initialize(struct event_queue** queue, event_queue_callback callback, void* ptr);
@ -45,11 +44,5 @@ extern void event_queue_shutdown(struct event_queue* queue);
extern void event_queue_post(struct event_queue* queue, struct event_data* message);
extern size_t event_queue_size(struct event_queue* queue);
/**
* Only used internally with libevent.
*/
extern void libevent_queue_process(int fd, short events, void* arg);
extern void libevent_queue_schedule(struct event_queue* queue);
#endif /* HAVE_UHUB_EVENT_QUEUE_H */

View File

@ -479,7 +479,7 @@ struct hub_info* hub_start_service(struct hub_config* config)
net_address_to_string(AF_INET6, &((struct sockaddr_in6*) &addr)->sin6_addr, address_buf, INET6_ADDRSTRLEN);
}
hub->evbase = event_init();
hub->evbase = event_base_new();
if (!hub->evbase)
{
hub_log(log_error, "Unable to initialize libevent.");
@ -614,6 +614,7 @@ struct hub_info* hub_start_service(struct hub_config* config)
}
event_set(&hub->ev_accept, hub->fd_tcp, EV_READ | EV_PERSIST, net_on_accept, hub);
event_base_set(hub->evbase, &hub->ev_accept);
if (event_add(&hub->ev_accept, NULL) == -1)
{
user_manager_shutdown(hub);
@ -627,6 +628,7 @@ struct hub_info* hub_start_service(struct hub_config* config)
#ifdef ADC_UDP_OPERATION
event_set(&hub->ev_datagram, hub->fd_udp, EV_READ | EV_PERSIST, net_on_packet, hub);
event_base_set(hub->evbase, &hub->ev_datagram);
if (event_add(&hub->ev_datagram, NULL) == -1)
{
user_manager_shutdown(hub);
@ -977,7 +979,10 @@ void hub_event_loop(struct hub_info* hub)
do
{
ret = event_base_loop(hub->evbase, EVLOOP_ONCE);
if (ret != 0)
break;
event_queue_process(hub->queue);
}
while (ret == hub_status_running);
while (hub->status == hub_status_running);
}

View File

@ -100,6 +100,7 @@ void setup_signal_handlers(struct hub_info* hub)
for (i = 0; signals[i]; i++)
{
signal_set(&signal_events[i], signals[i], hub_handle_signal, hub);
event_base_set(hub->evbase, &signal_events[i]);
if (signal_add(&signal_events[i], NULL))
{
hub_log(log_error, "Error setting signal handler %d", signals[i]);

View File

@ -291,7 +291,10 @@ void net_on_accept(int server_fd, short ev, void *arg)
event_set(user->ev_read, fd, EV_READ | EV_PERSIST, net_on_read, user);
event_set(user->ev_write, fd, EV_WRITE, net_on_write, user);
event_base_set(hub->evbase, user->ev_read);
event_base_set(hub->evbase, user->ev_write);
event_add(user->ev_read, &timeout);
}
}

View File

@ -74,6 +74,7 @@ static void timer_statistics(int fd, short ev, void *arg)
struct timeval timeout = { TIMEOUT_STATS, 0 };
user_manager_update_stats(hub);
evtimer_set(&hub->ev_timer, timer_statistics, hub);
event_base_set(hub->evbase, &hub->ev_timer);
evtimer_add(&hub->ev_timer, &timeout);
}
@ -97,6 +98,7 @@ int user_manager_init(struct hub_info* hub)
hub->users = users;
evtimer_set(&hub->ev_timer, timer_statistics, hub);
event_base_set(hub->evbase, &hub->ev_timer);
evtimer_add(&hub->ev_timer, &timeout);
return 0;
}