no need for using a TAILQ queue for the host children list, use a
authorreyk <reyk@openbsd.org>
Sat, 19 Jul 2008 11:38:54 +0000 (11:38 +0000)
committerreyk <reyk@openbsd.org>
Sat, 19 Jul 2008 11:38:54 +0000 (11:38 +0000)
singly-linked SLIST instead.  the only noticeable change is the
reversed order to notify the children but it does not really matter
here.  also only walk through the children host list if the host
itself is a potential parent.

usr.sbin/relayd/hce.c
usr.sbin/relayd/parse.y
usr.sbin/relayd/pfe.c
usr.sbin/relayd/relayd.h

index 262f7f6..b6aa659 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: hce.c,v 1.42 2008/07/19 10:52:32 reyk Exp $   */
+/*     $OpenBSD: hce.c,v 1.43 2008/07/19 11:38:54 reyk Exp $   */
 
 /*
  * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -332,11 +332,11 @@ hce_notify_done(struct host *host, const char *msg)
 
        host->last_up = host->up;
 
-       if (TAILQ_EMPTY(&host->children))
+       if (SLIST_EMPTY(&host->children))
                return;
 
        /* Notify for all other hosts that inherit the state from this one */
-       TAILQ_FOREACH(h, &host->children, child) {
+       SLIST_FOREACH(h, &host->children, child) {
                h->up = hostup;         
                hce_notify_done(h, msg);
        }
index 9a881ed..b8812ca 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: parse.y,v 1.120 2008/07/19 10:52:32 reyk Exp $        */
+/*     $OpenBSD: parse.y,v 1.121 2008/07/19 11:38:54 reyk Exp $        */
 
 /*
  * Copyright (c) 2007, 2008 Reyk Floeter <reyk@openbsd.org>
@@ -1267,7 +1267,7 @@ host              : STRING retry parent   {
                        $$->conf.id = 0; /* will be set later */
                        $$->conf.retry = $2;
                        $$->conf.parentid = $3;
-                       TAILQ_INIT(&$$->children);
+                       SLIST_INIT(&$$->children);
                }
                ;
 
@@ -1860,7 +1860,7 @@ parse_config(const char *filename, int opts)
                                            h->conf.parentid);
                                        errors++;
                                } else
-                                       TAILQ_INSERT_TAIL(&ph->children,
+                                       SLIST_INSERT_HEAD(&ph->children,
                                            h, child);
                        }
                }
@@ -2167,7 +2167,7 @@ table_inherit(struct table *tb)
                }
                h->conf.tableid = tb->conf.id;
                h->tablename = tb->conf.name;
-               TAILQ_INIT(&h->children);
+               SLIST_INIT(&h->children);
                TAILQ_INSERT_TAIL(&tb->hosts, h, entry);
        }
 
index f06432a..9b07926 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: pfe.c,v 1.49 2008/07/19 10:52:32 reyk Exp $   */
+/*     $OpenBSD: pfe.c,v 1.50 2008/07/19 11:38:54 reyk Exp $   */
 
 /*
  * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -791,12 +791,12 @@ disable_host(struct ctl_conn *c, struct ctl_id *id, struct host *host)
                    &host->conf.id, sizeof(host->conf.id));
        log_debug("disable_host: disabled host %d", host->conf.id);
 
-       /* Disable all children */
-       TAILQ_FOREACH(h, &host->children, child)
-               disable_host(c, id, h);
-
-       if (!host->conf.parentid)
+       if (!host->conf.parentid) {
+               /* Disable all children */
+               SLIST_FOREACH(h, &host->children, child)
+                       disable_host(c, id, h);
                pfe_sync();
+       }
        return (0);
 }
 
@@ -833,12 +833,12 @@ enable_host(struct ctl_conn *c, struct ctl_id *id, struct host *host)
                    &host->conf.id, sizeof(host->conf.id));
        log_debug("enable_host: enabled host %d", host->conf.id);
 
-       /* Enable all children */
-       TAILQ_FOREACH(h, &host->children, child)
-               enable_host(c, id, h);
-
-       if (!host->conf.parentid)
+       if (!host->conf.parentid) {
+               /* Enable all children */
+               SLIST_FOREACH(h, &host->children, child)
+                       enable_host(c, id, h);
                pfe_sync();
+       }
        return (0);
 }
 
index 763a4f5..c6ebf8e 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: relayd.h,v 1.107 2008/07/19 10:52:32 reyk Exp $       */
+/*     $OpenBSD: relayd.h,v 1.108 2008/07/19 11:38:54 reyk Exp $       */
 
 /*
  * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -354,8 +354,8 @@ struct host_config {
 
 struct host {
        TAILQ_ENTRY(host)        entry;
-       TAILQ_ENTRY(host)        child;
-       TAILQ_HEAD(,host)        children;
+       SLIST_ENTRY(host)        child;
+       SLIST_HEAD(,host)        children;
        struct host_config       conf;
        u_int32_t                flags;
        char                    *tablename;