From 1ee33e9bc90e31e1fa1d20ddba431ced98dbe978 Mon Sep 17 00:00:00 2001 From: Michael Poole Date: Wed, 4 Oct 2006 01:41:05 +0000 Subject: [PATCH] Make timeq_init() automatic. src/main.c (main): Remove call to timeq_init(). src/timeq.h (timeq_init): Remove declaration. src/timeq.c (timeq_cleanup): Assign NULL to timeq to handle late timeq_del() calls. (timeq_init): Make static. (timeq_next): If timeq is NULL, return a large positive number. (timeq_add): If timeq is NULL, initialize it. (timeq_del): If timeq is NULL, do nothing. git-archimport-id: srvx@srvx.net--2006/srvx--devo--1.3--patch-54 --- ChangeLog | 21 +++++++++++++++++++++ src/main.c | 1 - src/timeq.c | 10 ++++++++-- src/timeq.h | 1 - 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index f111a6f..3697b8c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,27 @@ # arch-tag: automatic-ChangeLog--srvx@srvx.net--2006/srvx--devo--1.3 # +2006-10-04 01:41:05 GMT Michael Poole patch-54 + + Summary: + Make timeq_init() automatic. + Revision: + srvx--devo--1.3--patch-54 + + src/main.c (main): Remove call to timeq_init(). + + src/timeq.h (timeq_init): Remove declaration. + + src/timeq.c (timeq_cleanup): Assign NULL to timeq to handle late timeq_del() calls. + (timeq_init): Make static. + (timeq_next): If timeq is NULL, return a large positive number. + (timeq_add): If timeq is NULL, initialize it. + (timeq_del): If timeq is NULL, do nothing. + + modified files: + ChangeLog src/main.c src/timeq.c src/timeq.h + + 2006-10-04 01:37:40 GMT Michael Poole patch-53 Summary: diff --git a/src/main.c b/src/main.c index fe73b4f..ba79b8e 100644 --- a/src/main.c +++ b/src/main.c @@ -824,7 +824,6 @@ int main(int argc, char *argv[]) MAIN_LOG = log_register_type("srvx", "file:main.log"); if (debug) log_debug(); - timeq_init(); ioset_init(); init_structs(); init_parse(); diff --git a/src/timeq.c b/src/timeq.c index 63906b2..aa73fbc 100644 --- a/src/timeq.c +++ b/src/timeq.c @@ -34,9 +34,10 @@ timeq_cleanup(void) { timeq_del(0, 0, 0, TIMEQ_IGNORE_WHEN|TIMEQ_IGNORE_FUNC|TIMEQ_IGNORE_DATA); heap_delete(timeq); + timeq = NULL; } -void +static void timeq_init(void) { timeq = heap_new(int_comparator); @@ -47,6 +48,8 @@ time_t timeq_next(void) { void *time; + if (!timeq) + return ~0; heap_peek(timeq, &time, 0); return (time_t)time; } @@ -60,6 +63,8 @@ timeq_add(time_t when, timeq_func func, void *data) ent->func = func; ent->data = data; w = (void*)when; + if (!timeq) + timeq_init(); heap_insert(timeq, w, ent); } @@ -93,7 +98,8 @@ timeq_del(time_t when, timeq_func func, void *data, int mask) extra.func = func; extra.data = data; extra.mask = mask; - heap_remove_pred(timeq, timeq_del_matching, &extra); + if (timeq) + heap_remove_pred(timeq, timeq_del_matching, &extra); } unsigned int diff --git a/src/timeq.h b/src/timeq.h index ae65e36..f3ffe90 100644 --- a/src/timeq.h +++ b/src/timeq.h @@ -27,7 +27,6 @@ typedef void (*timeq_func)(void *data); #define TIMEQ_IGNORE_FUNC 0x02 #define TIMEQ_IGNORE_DATA 0x04 -void timeq_init(void); void timeq_add(time_t when, timeq_func func, void *data); void timeq_del(time_t when, timeq_func func, void *data, int mask); time_t timeq_next(void); -- 2.20.1