Make timeq_init() automatic.
authorMichael Poole <mdpoole@troilus.org>
Wed, 4 Oct 2006 01:41:05 +0000 (01:41 +0000)
committerMichael Poole <mdpoole@troilus.org>
Wed, 4 Oct 2006 01:41:05 +0000 (01:41 +0000)
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
src/main.c
src/timeq.c
src/timeq.h

index f111a6ff306dc6e0dd4b2566dfb5360db264de9f..3697b8c091015b4e5ce4a44793c2d842feff2498 100644 (file)
--- 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 <mdpoole@troilus.org>     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 <mdpoole@troilus.org>     patch-53
 
     Summary:
index fe73b4f64b88abd96b6fc902f59f54ad6b07fbef..ba79b8e813339904aadf26ccd1d670608ff939b7 100644 (file)
@@ -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();
index 63906b2a96b6700bf0bd05d9148c649e4b034f5d..aa73fbcf41b2a60158b16cde59136c5aedc4a376 100644 (file)
@@ -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
index ae65e36b03920a0063dca62bc157fec578e08bbe..f3ffe90872fb4a5355249de75a8495cec350c29c 100644 (file)
@@ -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);