Since ncld uses CLD timers and thus we had to have them in libcldc, we may as well use them in Chunk. This gives us an automatic importation of bugfixes. Signed-off-by: Pete Zaitcev <zaitcev@xxxxxxxxxx> --- server/chunkd.h | 27 ++------------ server/cldu.c | 4 +- server/util.c | 84 +++++----------------------------------------- 3 files changed, 17 insertions(+), 98 deletions(-) commit 6a7f28a8a6312e06c075032aeaa4741f5cbde2f2 Author: Master <zaitcev@xxxxxxxxxxxxxxxxxx> Date: Sat Apr 17 19:39:56 2010 -0600 Switch chunkd to the CLD's timer (auto-import bugfixes). diff --git a/server/chunkd.h b/server/chunkd.h index c6c2a27..e7c7369 100644 --- a/server/chunkd.h +++ b/server/chunkd.h @@ -28,6 +28,7 @@ #include <chunk_msg.h> #include <hail_log.h> #include <tchdb.h> +#include <cldc.h> /* for cld_timer */ #include <objcache.h> #ifndef ARRAY_SIZE @@ -57,15 +58,6 @@ struct client_write; typedef bool (*cli_evt_func)(struct client *, unsigned int); typedef bool (*cli_write_func)(struct client *, struct client_write *, bool); -struct timer { - bool fired; - bool on_list; - void (*cb)(struct timer *); - void *userdata; - time_t expires; - char name[32]; -}; - struct client_write { const void *buf; /* write buffer */ uint64_t len; /* write buffer length */ @@ -303,23 +295,14 @@ extern void syslogerr(const char *prefix); extern void strup(char *s); extern int write_pid_file(const char *pid_fn); extern int fsetflags(const char *prefix, int fd, int or_flags); -extern void timer_add(struct timer *timer, time_t expires); -extern void timer_del(struct timer *timer); +extern void timer_init(struct cld_timer *timer, const char *name, + void (*cb)(struct cld_timer *), void *userdata); +extern void timer_add(struct cld_timer *timer, time_t expires); +extern void timer_del(struct cld_timer *timer); extern time_t timers_run(void); extern char *time2str(char *strbuf, time_t time); extern void hexstr(const unsigned char *buf, size_t buf_len, char *outstr); -static inline void timer_init(struct timer *timer, const char *name, - void (*cb)(struct timer *), - void *userdata) -{ - memset(timer, 0, sizeof(*timer)); - timer->cb = cb; - timer->userdata = userdata; - strncpy(timer->name, name, sizeof(timer->name)); - timer->name[sizeof(timer->name) - 1] = 0; -} - /* server.c */ extern SSL_CTX *ssl_ctx; extern int debugging; diff --git a/server/cldu.c b/server/cldu.c index b2d3388..957bd81 100644 --- a/server/cldu.c +++ b/server/cldu.c @@ -46,7 +46,7 @@ struct cld_session { int actx; /* Active host cldv[actx] */ struct cld_host cldv[N_CLD]; - struct timer timer; + struct cld_timer timer; char *ffname; struct ncld_fh *ffh; /* keep open for lock */ @@ -95,7 +95,7 @@ static void cldu_saveargs(struct cld_session *sp, char *infopath, sp->ploc = loc; } -static void cldu_timer_event(struct timer *timer) +static void cldu_timer_event(struct cld_timer *timer) { struct cld_session *cs = timer->userdata; int newactive; diff --git a/server/util.c b/server/util.c index cc5a1eb..30d4b91 100644 --- a/server/util.c +++ b/server/util.c @@ -35,8 +35,6 @@ #include <glib.h> #include "chunkd.h" -static GList *timer_list; - size_t strlist_len(GList *l) { GList *tmp = l; @@ -195,89 +193,27 @@ char *time2str(char *strbuf, time_t src_time) return strbuf; } -static gint timer_cmp(gconstpointer a_, gconstpointer b_) -{ - const struct timer *a = a_; - const struct timer *b = b_; +struct cld_timer_list timer_list; - if (a->expires > b->expires) - return 1; - if (a->expires == b->expires) - return 0; - return -1; +void timer_init(struct cld_timer *timer, const char *name, + void (*cb)(struct cld_timer *), void *userdata) +{ + cld_timer_init(timer, name, cb, userdata); } -void timer_add(struct timer *timer, time_t expires) +void timer_add(struct cld_timer *timer, time_t expires) { - if (timer->on_list) { - timer_list = g_list_remove(timer_list, timer); - - if (debugging) - applog(LOG_WARNING, "BUG? timer %s added twice " - "(expires: old %llu, new %llu)", - timer->name, - (unsigned long long) timer->expires, - (unsigned long long) expires); - } - - timer->on_list = true; - timer->fired = false; - timer->expires = expires; - - timer_list = g_list_insert_sorted(timer_list, timer, timer_cmp); + cld_timer_add(&timer_list, timer, expires); } -void timer_del(struct timer *timer) +void timer_del(struct cld_timer *timer) { - if (!timer->on_list) - return; - - timer_list = g_list_remove(timer_list, timer); - - timer->on_list = false; + cld_timer_del(&timer_list, timer); } time_t timers_run(void) { - struct timer *timer; - time_t now = time(NULL); - time_t next_timeout = 0; - GList *tmp, *cur; - GList *exec_list = NULL; - - tmp = timer_list; - while (tmp) { - timer = tmp->data; - cur = tmp; - tmp = tmp->next; - - if (timer->expires > now) - break; - - timer_list = g_list_remove_link(timer_list, cur); - exec_list = g_list_concat(exec_list, cur); - - timer->on_list = false; - } - - tmp = exec_list; - while (tmp) { - timer = tmp->data; - tmp = tmp->next; - - timer->fired = true; - timer->cb(timer); - } - - if (timer_list) { - timer = timer_list->data; - if (timer->expires > now) - next_timeout = (timer->expires - now); - else - next_timeout = 1; - } - - return next_timeout; + return cld_timers_run(&timer_list); } #ifndef HAVE_STRNLEN -- To unsubscribe from this list: send the line "unsubscribe hail-devel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html