X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2Ftimeq.c;fp=src%2Ftimeq.c;h=41e4b1a3b1dec349c6547c191e87bd9defac812e;hb=7650fa6f3ccabbbf8a8b02b1a706bafb1a17a169;hp=17b190488381576cfa9837b7c24709061258dc0c;hpb=f90d21daf31f8d69e24406678be696afa8cae962;p=NeonServV5.git diff --git a/src/timeq.c b/src/timeq.c index 17b1904..41e4b1a 100644 --- a/src/timeq.c +++ b/src/timeq.c @@ -29,9 +29,10 @@ void init_timeq() { void timeq_tick() { SYNCHRONIZE(synchronized); struct timeq_entry *entry, *next; - time_t now = time(0); + struct timeval now; + gettimeofday(&now, NULL); for(entry = timeq_events; entry; entry = next) { - if(entry->execute <= now) { + if(!timeval_is_bigger(entry->execute, now)) { next = entry->next; if(timeq_events == entry) timeq_events = next; @@ -44,7 +45,12 @@ void timeq_tick() { } struct timeq_entry* timeq_add(int seconds, timeq_callback_t *callback, void *data) { - time_t now = time(0); + return timeq_uadd(seconds * 1000, callback, data); +} + +struct timeq_entry* timeq_uadd(int useconds, timeq_callback_t *callback, void *data) { + struct timeval now; + gettimeofday(&now, NULL); struct timeq_entry *entry = malloc(sizeof(*entry)); if (!entry) { @@ -52,13 +58,15 @@ struct timeq_entry* timeq_add(int seconds, timeq_callback_t *callback, void *dat return NULL; } SYNCHRONIZE(synchronized); - entry->execute = now + seconds; + now.tv_usec += (useconds % 1000); + now.tv_sec += (useconds / 1000); + entry->execute = now; entry->callback = callback; entry->data = data; entry->name = NULL; struct timeq_entry *next, *prev = NULL; for(next = timeq_events; next; next = next->next) { - if(next->execute >= entry->execute) + if(timeval_is_bigger(next->execute, now)) break; else prev = next; @@ -75,8 +83,12 @@ struct timeq_entry* timeq_add(int seconds, timeq_callback_t *callback, void *dat } 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_uadd_name(char *name, int useconds, timeq_callback_t *callback, void *data) { SYNCHRONIZE(synchronized); - struct timeq_entry *entry = timeq_add(seconds, callback, data); + struct timeq_entry *entry = timeq_uadd(useconds, callback, data); entry->name = strdup(name); DESYNCHRONIZE(synchronized); return entry;