From 6b221320ae9ea0a511307eb23bc01bfc4bebd877 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sun, 11 Jan 2004 09:16:29 +0000 Subject: [PATCH] Replace bsd_queue with dlist in lib/watchdog git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1001 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/lib/dlist.c | 2 +- bacula/src/lib/watchdog.c | 52 ++++++++++++++++++++------------------- bacula/src/lib/watchdog.h | 20 ++++++--------- bacula/src/version.h | 4 +-- 4 files changed, 38 insertions(+), 40 deletions(-) diff --git a/bacula/src/lib/dlist.c b/bacula/src/lib/dlist.c index 3b6d289147..ffc35c52cb 100644 --- a/bacula/src/lib/dlist.c +++ b/bacula/src/lib/dlist.c @@ -163,7 +163,7 @@ void dlist::destroy() struct MYJCR { char *buf; - dlist link; + dlink link; }; int main() diff --git a/bacula/src/lib/watchdog.c b/bacula/src/lib/watchdog.c index bcba37e565..8ab21c438d 100755 --- a/bacula/src/lib/watchdog.c +++ b/bacula/src/lib/watchdog.c @@ -30,10 +30,6 @@ #include "bacula.h" #include "jcr.h" -/* This breaks Kern's #include rules, but I don't want to put it into bacula.h - * until it has been discussed with him */ -#include "bsd_queue.h" - /* Exported globals */ time_t watchdog_time; /* this has granularity of SLEEP_TIME */ @@ -52,10 +48,8 @@ static bool wd_is_init = false; static pthread_t wd_tid; /* Static globals */ -static TAILQ_HEAD(/* no struct */, s_watchdog_t) wd_queue = - TAILQ_HEAD_INITIALIZER(wd_queue); -static TAILQ_HEAD(/* no struct */, s_watchdog_t) wd_inactive = - TAILQ_HEAD_INITIALIZER(wd_inactive); +static dlist *wd_queue; +static dlist *wd_inactive; /* * Start watchdog thread @@ -66,10 +60,18 @@ static TAILQ_HEAD(/* no struct */, s_watchdog_t) wd_inactive = int start_watchdog(void) { int stat; + watchdog_t *dummy = NULL; + if (wd_is_init) { + return 0; + } Dmsg0(200, "Initialising NicB-hacked watchdog thread\n"); watchdog_time = time(NULL); quit = false; + + wd_queue = new dlist(wd_queue, &dummy->link); + wd_inactive = new dlist(wd_inactive, &dummy->link); + if ((stat = pthread_create(&wd_tid, NULL, watchdog_thread, NULL)) != 0) { return stat; } @@ -86,7 +88,7 @@ int start_watchdog(void) int stop_watchdog(void) { int stat; - watchdog_t *p, *n; + watchdog_t *p; if (!wd_is_init) { return 0; @@ -102,21 +104,23 @@ int stop_watchdog(void) stat = pthread_join(wd_tid, NULL); - TAILQ_FOREACH_SAFE(p, &wd_queue, qe, n) { - TAILQ_REMOVE(&wd_queue, p, qe); + foreach_dlist(p, wd_queue) { if (p->destructor != NULL) { p->destructor(p); } free(p); } + delete wd_queue; + wd_queue = NULL; - TAILQ_FOREACH_SAFE(p, &wd_inactive, qe, n) { - TAILQ_REMOVE(&wd_inactive, p, qe); + foreach_dlist(p, wd_inactive) { if (p->destructor != NULL) { p->destructor(p); } free(p); } + delete wd_inactive; + wd_inactive = NULL; return stat; } @@ -155,7 +159,7 @@ bool register_watchdog(watchdog_t *wd) P(mutex); wd->next_fire = watchdog_time + wd->interval; - TAILQ_INSERT_TAIL(&wd_queue, wd, qe); + wd_queue->append(wd); Dmsg3(200, "Registered watchdog %p, interval %d%s\n", wd, wd->interval, wd->one_shot ? " one shot" : ""); V(mutex); @@ -165,30 +169,29 @@ bool register_watchdog(watchdog_t *wd) bool unregister_watchdog_unlocked(watchdog_t *wd) { - watchdog_t *p, *n; + watchdog_t *p; if (!wd_is_init) { Emsg0(M_ABORT, 0, "BUG! unregister_watchdog_unlocked called before start_watchdog\n"); } - TAILQ_FOREACH_SAFE(p, &wd_queue, qe, n) { + foreach_dlist(p, wd_queue) { if (wd == p) { - TAILQ_REMOVE(&wd_queue, wd, qe); + wd_queue->remove(wd); Dmsg1(200, "Unregistered watchdog %p\n", wd); return true; } } - TAILQ_FOREACH_SAFE(p, &wd_inactive, qe, n) { + foreach_dlist(p, wd_inactive) { if (wd == p) { - TAILQ_REMOVE(&wd_inactive, wd, qe); + wd_inactive->remove(wd); Dmsg1(200, "Unregistered inactive watchdog %p\n", wd); return true; } } Dmsg1(200, "Failed to unregister watchdog %p\n", wd); - return false; } @@ -212,7 +215,7 @@ static void *watchdog_thread(void *arg) Dmsg0(200, "NicB-reworked watchdog thread entered\n"); while (true) { - watchdog_t *p, *n; + watchdog_t *p; P(mutex); if (quit) { @@ -222,15 +225,15 @@ static void *watchdog_thread(void *arg) watchdog_time = time(NULL); - TAILQ_FOREACH_SAFE(p, &wd_queue, qe, n) { + foreach_dlist(p, wd_queue) { if (p->next_fire < watchdog_time) { /* Run the callback */ p->callback(p); /* Reschedule (or move to inactive list if it's a one-shot timer) */ if (p->one_shot) { - TAILQ_REMOVE(&wd_queue, p, qe); - TAILQ_INSERT_TAIL(&wd_inactive, p, qe); + wd_queue->remove(p); + wd_inactive->append(p); } else { p->next_fire = watchdog_time + p->interval; } @@ -241,6 +244,5 @@ static void *watchdog_thread(void *arg) } Dmsg0(200, "NicB-reworked watchdog thread exited\n"); - return NULL; } diff --git a/bacula/src/lib/watchdog.h b/bacula/src/lib/watchdog.h index aaae0c74cc..724bfe9239 100644 --- a/bacula/src/lib/watchdog.h +++ b/bacula/src/lib/watchdog.h @@ -29,18 +29,14 @@ #define TIMEOUT_SIGNAL SIGUSR2 -/* This breaks Kern's #include rules, but I don't want to put it into bacula.h - * until it has been discussed with him */ -#include "bsd_queue.h" - struct s_watchdog_t { - bool one_shot; - time_t interval; - void (*callback)(struct s_watchdog_t *wd); - void (*destructor)(struct s_watchdog_t *wd); - void *data; - /* Private data below - don't touch outside of watchdog.c */ - TAILQ_ENTRY(s_watchdog_t) qe; - time_t next_fire; + bool one_shot; + time_t interval; + void (*callback)(struct s_watchdog_t *wd); + void (*destructor)(struct s_watchdog_t *wd); + void *data; + /* Private data below - don't touch outside of watchdog.c */ + dlink link; + time_t next_fire; }; typedef struct s_watchdog_t watchdog_t; diff --git a/bacula/src/version.h b/bacula/src/version.h index 8946634f62..cd5136cf57 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -2,8 +2,8 @@ #undef VERSION #define VERSION "1.33" #define VSTRING "1" -#define BDATE "10 Jan 2004" -#define LSMDATE "10Jan04" +#define BDATE "11 Jan 2004" +#define LSMDATE "11Jan04" /* Debug flags */ #undef DEBUG -- 2.39.5