hail-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pete Zaitcev <zaitcev@redhat.com>
To: Jeff Garzik <jeff@garzik.org>
Cc: Project Hail List <hail-devel@vger.kernel.org>
Subject: [Patch 05/12] Chunk: Use CLD timers
Date: Sat, 17 Apr 2010 22:41:09 -0600	[thread overview]
Message-ID: <20100417224109.51e829b2@redhat.com> (raw)

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@redhat.com>

---
 server/chunkd.h |   27 ++------------
 server/cldu.c   |    4 +-
 server/util.c   |   84 +++++-----------------------------------------
 3 files changed, 17 insertions(+), 98 deletions(-)

commit 6a7f28a8a6312e06c075032aeaa4741f5cbde2f2
Author: Master <zaitcev@lembas.zaitcev.lan>
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

             reply	other threads:[~2010-04-18  4:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-18  4:41 Pete Zaitcev [this message]
2010-04-19  3:50 ` [Patch 05/12] Chunk: Use CLD timers Jeff Garzik
2010-04-19  4:08 ` Jeff Garzik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100417224109.51e829b2@redhat.com \
    --to=zaitcev@redhat.com \
    --cc=hail-devel@vger.kernel.org \
    --cc=jeff@garzik.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).