X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2Ftimeq.c;h=4b30285a543746963472a1ac6ae576d07fc9c250;hb=706e48b1e666054030c491d864f740071e390038;hp=41e4b1a3b1dec349c6547c191e87bd9defac812e;hpb=b53d0c5f88063f075a48a0426f9d5d6b3490b9fc;p=NeonServV5.git diff --git a/src/timeq.c b/src/timeq.c index 41e4b1a..4b30285 100644 --- a/src/timeq.c +++ b/src/timeq.c @@ -44,11 +44,11 @@ void timeq_tick() { DESYNCHRONIZE(synchronized); } -struct timeq_entry* timeq_add(int seconds, timeq_callback_t *callback, void *data) { - return timeq_uadd(seconds * 1000, callback, data); +struct timeq_entry* timeq_add(int seconds, int module_id, timeq_callback_t *callback, void *data) { + return timeq_uadd(seconds * 1000, module_id, callback, data); } -struct timeq_entry* timeq_uadd(int useconds, timeq_callback_t *callback, void *data) { +struct timeq_entry* timeq_uadd(int useconds, int module_id, timeq_callback_t *callback, void *data) { struct timeval now; gettimeofday(&now, NULL); struct timeq_entry *entry = malloc(sizeof(*entry)); @@ -61,6 +61,7 @@ struct timeq_entry* timeq_uadd(int useconds, timeq_callback_t *callback, void *d now.tv_usec += (useconds % 1000); now.tv_sec += (useconds / 1000); entry->execute = now; + entry->module_id = module_id; entry->callback = callback; entry->data = data; entry->name = NULL; @@ -82,13 +83,13 @@ struct timeq_entry* timeq_uadd(int useconds, timeq_callback_t *callback, void *d return entry; } -struct timeq_entry* timeq_add_name(char *name, int seconds, timeq_callback_t *callback, void *data) { - return timeq_uadd_name(name, seconds * 1000, callback, data); +struct timeq_entry* timeq_add_name(char *name, int seconds, int module_id, timeq_callback_t *callback, void *data) { + return timeq_uadd_name(name, seconds * 1000, module_id, callback, data); } -struct timeq_entry* timeq_uadd_name(char *name, int useconds, timeq_callback_t *callback, void *data) { +struct timeq_entry* timeq_uadd_name(char *name, int useconds, int module_id, timeq_callback_t *callback, void *data) { SYNCHRONIZE(synchronized); - struct timeq_entry *entry = timeq_uadd(useconds, callback, data); + struct timeq_entry *entry = timeq_uadd(useconds, module_id, callback, data); entry->name = strdup(name); DESYNCHRONIZE(synchronized); return entry; @@ -149,3 +150,21 @@ int timeq_name_exists(char *name) { DESYNCHRONIZE(synchronized); return 0; } + +void unregister_module_timers(int module_id) { + SYNCHRONIZE(synchronized); + struct timeq_entry *centry, *next, *last = NULL; + for(centry = timeq_events; centry; centry = next) { + next = centry->next; + if(centry->module_id == module_id) { + if(last) + last->next = centry->next; + else + timeq_events = centry->next; + free(centry->name); + free(centry); + } else + last = centry; + } + DESYNCHRONIZE(synchronized); +}