X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2Ftimeq.c;h=0136c51a473f6b8b0bde5b9fd1026267a6a26672;hb=8a1a716ef73af7b5288f7b5f8ab1b37be80f1247;hp=b53b58ddd25689d91674d75537e6bcb25c289560;hpb=291f15058a67b95bdfe6f6861cdfcb8ffd626149;p=NeonServV5.git diff --git a/src/timeq.c b/src/timeq.c index b53b58d..0136c51 100644 --- a/src/timeq.c +++ b/src/timeq.c @@ -1,4 +1,4 @@ -/* timeq.c - NeonServ v5.5 +/* timeq.c - NeonServ v5.6 * Copyright (C) 2011-2012 Philipp Kreil (pk910) * * This program is free software: you can redistribute it and/or modify @@ -29,6 +29,7 @@ static IOHANDLER_CALLBACK(timeq_callback) { switch(event->type) { case IOEVENT_TIMEOUT: entry->callback(entry->data); + entry->iofd = NULL; timeq_del(entry); break; default: @@ -48,10 +49,12 @@ struct timeq_entry* timeq_uadd(int useconds, int module_id, timeq_callback_t *ca perror("malloc() failed"); return NULL; } + #ifdef HAVE_THREADS if(!pthread_mutex_initialized) { THREAD_MUTEX_INIT(synchronized); pthread_mutex_initialized = 1; } + #endif gettimeofday(&timeout, NULL); SYNCHRONIZE(synchronized); timeout.tv_usec += (useconds % 1000); @@ -64,7 +67,8 @@ struct timeq_entry* timeq_uadd(int useconds, int module_id, timeq_callback_t *ca entry->name = NULL; entry->next = timeq_events; entry->prev = NULL; - timeq_events->prev = entry; + if(timeq_events) + timeq_events->prev = entry; timeq_events = entry; DESYNCHRONIZE(synchronized); return entry; @@ -81,7 +85,9 @@ struct timeq_entry* timeq_uadd_name(char *name, int useconds, int module_id, tim } int timeq_del(struct timeq_entry* entry) { + #ifdef HAVE_THREADS if(!pthread_mutex_initialized) return 0; + #endif SYNCHRONIZE(synchronized); if(entry->next) entry->next->prev = entry->prev; @@ -91,7 +97,8 @@ int timeq_del(struct timeq_entry* entry) { timeq_events = entry->next; if(entry->name) free(entry->name); - iohandler_close(entry->iofd); + if(entry->iofd) + iohandler_close(entry->iofd); free(entry); DESYNCHRONIZE(synchronized); return 1;