chiark / gitweb /
Tidying and bugfixing. 2.0.0
authormdw <mdw>
Sat, 17 May 2003 10:34:04 +0000 (10:34 +0000)
committermdw <mdw>
Sat, 17 May 2003 10:34:04 +0000 (10:34 +0000)
sel.c
sel.h

diff --git a/sel.c b/sel.c
index 1e3cdaca40921c42e0663a634ad46c5f85d7a666..474e820060035e4444237187bcb846f92b3433f6 100644 (file)
--- a/sel.c
+++ b/sel.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: sel.c,v 1.10 2001/06/22 19:35:58 mdw Exp $
+ * $Id: sel.c,v 1.11 2003/05/17 10:34:04 mdw Exp $
  *
  * I/O multiplexing support
  *
@@ -30,6 +30,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: sel.c,v $
+ * Revision 1.11  2003/05/17 10:34:04  mdw
+ *  Tidying and bugfixing.
+ *
  * Revision 1.10  2001/06/22 19:35:58  mdw
  * Fix a large number of bugs.
  *
@@ -161,9 +164,9 @@ void sel_addfile(sel_file *f)
   while (*ff && (*ff)->fd > f->fd)
     ff = &(*ff)->next;
   f->next = *ff;
-  f->prev = (sel_file *)ff;
+  f->prev = ff;
   if (*ff)
-    (*ff)->prev = f;
+    (*ff)->prev = &f->next;
   *ff = f;
   FD_SET(f->fd, f->s->fd + f->mode);
 }
@@ -197,7 +200,7 @@ void sel_force(sel_file *f)
 
 void sel_rmfile(sel_file *f)
 {
-  f->prev->next = f->next;
+  *f->prev = f->next;
   if (f->next)
     f->next->prev = f->prev;
   FD_CLR(f->fd, f->s->fd + f->mode);
@@ -240,9 +243,9 @@ void sel_addtimer(sel_state *s, sel_timer *t,
   while (*tt && TV_CMP(&(*tt)->tv, <, tv))
     tt = &(*tt)->next;
   t->next = *tt;
-  t->prev = (sel_timer *)tt;
+  t->prev = tt;
   if (*tt)
-    (*tt)->prev = t;
+    (*tt)->prev = &t->next;
   *tt = t;
 }
 
@@ -257,12 +260,13 @@ void sel_addtimer(sel_state *s, sel_timer *t,
 
 void sel_rmtimer(sel_timer *t)
 {
-  t->prev->next = t->next;
-  if (t->next)
-    t->next->prev = t->prev;
   if (t->pend) {
     t->pend->t = 0;
     t->pend = 0;
+  } else {
+    *t->prev = t->next;
+    if (t->next)
+      t->next->prev = t->prev;
   }
 }
 
@@ -286,9 +290,9 @@ void sel_addhook(sel_state *s, sel_hook *h,
   h->after = after;
   h->p = p;
   h->next = s->hooks;
-  h->prev = (sel_hook *)&s->hooks;
+  h->prev = &s->hooks;
   if (s->hooks)
-    s->hooks->prev = h;
+    s->hooks->prev = &h->next;
   s->hooks = h;
 }
 
@@ -305,7 +309,7 @@ void sel_rmhook(sel_hook *h)
 {
   if (h->next)
     h->next->prev = h->prev;
-  h->prev->next = h->next;
+  *h->prev = h->next;
 }
 
 /* --- @sel_fdmerge@ --- *
@@ -426,8 +430,8 @@ int sel_select(sel_state *s)
     }
     *ptt = 0;
     if (t) {
-      t->prev->next = 0;
-      t->prev = (sel_timer *)&s->timers;
+      *t->prev = 0;
+      t->prev = &s->timers;
     }
     s->timers = t;
     while (pthead) {
@@ -435,8 +439,10 @@ int sel_select(sel_state *s)
       pthead = pt->next;
       t = pt->t;
       if (t) {
-       t->func(&a.now, t->p);
        t->pend = 0;
+       t->next = 0;
+       t->prev = &t->next;
+       t->func(&a.now, t->p);
       }
       DESTROY(pt);
     }
@@ -471,8 +477,8 @@ int sel_select(sel_state *s)
        pfhead = pf->next;
        f = pf->f;
        if (f) {
-         f->func(f->fd, i, f->p);
          f->pend = 0;
+         f->func(f->fd, i, f->p);
        }
       }
     }
diff --git a/sel.h b/sel.h
index 338ea20255f44688a4f5d2a2715a169c1f1f09c0..bd767d648935cde9148f26022608931b567f95ba 100644 (file)
--- a/sel.h
+++ b/sel.h
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: sel.h,v 1.8 2001/06/22 19:35:58 mdw Exp $
+ * $Id: sel.h,v 1.9 2003/05/17 10:34:04 mdw Exp $
  *
  * I/O multiplexing support
  *
@@ -30,6 +30,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: sel.h,v $
+ * Revision 1.9  2003/05/17 10:34:04  mdw
+ *  Tidying and bugfixing.
+ *
  * Revision 1.8  2001/06/22 19:35:58  mdw
  * Fix a large number of bugs.
  *
@@ -134,7 +137,7 @@ typedef struct sel_state {
 
 typedef struct sel_file {
   struct sel_file *next;               /* Next file in the list */
-  struct sel_file *prev;               /* Previous file in the list */
+  struct sel_file **prev;              /* Previous file in the list */
   struct sel_state *s;                 /* Pointer to select multiplexor */
   int fd;                              /* File descriptor */
   unsigned mode;                       /* Interesting event for file */
@@ -147,7 +150,7 @@ typedef struct sel_file {
 
 typedef struct sel_timer {
   struct sel_timer *next;              /* Next timer in the list */
-  struct sel_timer *prev;              /* Previous timer in the list */
+  struct sel_timer **prev;             /* Previous timer in the list */
   struct timeval tv;                   /* Real time when timer should go */
   void (*func)(struct timeval */*tv*/, void */*p*/); /* Handler function */
   void *p;                             /* Argument for the handler */
@@ -174,7 +177,7 @@ typedef void (*sel_hookfn)(sel_state */*s*/,
 
 typedef struct sel_hook {
   struct sel_hook *next;               /* Next hook in the list */
-  struct sel_hook *prev;               /* Previous hook in the list */
+  struct sel_hook **prev;              /* Previous hook in the list */
   sel_hookfn before, after;            /* Hook functions */
   void *p;                             /* Argument for the hook functions */
 } sel_hook;