Committer  : entrope
CVSROOT    : /cvsroot/undernet-ircu
Module     : ircu2.10
Commit time: 2006-07-23 17:58:00 UTC

Modified files:
     ChangeLog ircd/ircd_events.c

Log message:

Streamline event generation in the non-threaded case.

---------------------- diff included ----------------------
Index: ircu2.10/ChangeLog
diff -u ircu2.10/ChangeLog:1.802 ircu2.10/ChangeLog:1.803
--- ircu2.10/ChangeLog:1.802    Sun Jul 23 10:55:15 2006
+++ ircu2.10/ChangeLog  Sun Jul 23 10:57:50 2006
@@ -1,5 +1,12 @@
 2006-07-23  Michael Poole <[EMAIL PROTECTED]>
 
+       * ircd/ircd_events.c (event_generate): Separate into threaded and
+       non-threaded versions.
+       (event_execute): Move into IRCD_THREADED section.
+       (event_add): Likewise.
+
+2006-07-23  Michael Poole <[EMAIL PROTECTED]>
+
        * ircd/s_bsd.c (close_connection): Clear FREEFLAG_SOCKET when
        closing the socket.
        (client_sock_callback): Fix typo in a comment.
Index: ircu2.10/ircd/ircd_events.c
diff -u ircu2.10/ircd/ircd_events.c:1.11 ircu2.10/ircd/ircd_events.c:1.12
--- ircu2.10/ircd/ircd_events.c:1.11    Fri Jul 14 17:09:09 2006
+++ ircu2.10/ircd/ircd_events.c Sun Jul 23 10:57:50 2006
@@ -18,7 +18,7 @@
  */
 /** @file
  * @brief Implementation of event loop mid-layer.
- * @version $Id: ircd_events.c,v 1.11 2006/07/15 00:09:09 entrope Exp $
+ * @version $Id: ircd_events.c,v 1.12 2006/07/23 17:57:50 entrope Exp $
  */
 #include "config.h"
 
@@ -143,6 +143,48 @@
   }
 }
 
+#ifndef IRCD_THREADED
+
+/** Generate and execute an event.
+ * @param[in] type Type of event to generate.
+ * @param[in] arg Pointer to an event generator (GenHeader).
+ * @param[in] data Extra data for event.
+ */
+void
+event_generate(enum EventType type, void* arg, int data)
+{
+  struct Event ev;
+  struct GenHeader *gen = (struct GenHeader*) arg;
+
+  assert(0 != gen);
+  assert(gen->gh_flags & GEN_ACTIVE);
+
+  if (type == ET_DESTROY)
+  {
+    if (gen->gh_flags & GEN_DESTROY)
+      return;
+    gen->gh_flags &= ~GEN_ACTIVE;
+  }
+  else if (type == ET_ERROR)
+    gen->gh_flags |= GEN_ERROR;
+
+  Debug((DEBUG_LIST, "Generating event type %s for generator %p (%s)",
+        event_to_name(type), gen, gen_flags(gen->gh_flags)));
+
+  ev.ev_next = NULL;
+  ev.ev_prev_p = NULL;
+  ev.ev_type = type;
+  ev.ev_data = data;
+  ev.ev_gen.gen_header = gen;
+  gen->gh_ref++;
+
+  gen->gh_call(&ev);
+  if (type != ET_DESTROY)
+    gen_ref_dec(gen);
+}
+
+#else
+
 /** Execute an event.
  * Optimizations should inline this.
  * @param[in] event Event to execute.
@@ -177,17 +219,6 @@
   evInfo.events_free = event;
 }
 
-#ifndef IRCD_THREADED
-/** we synchronously execute the event when not threaded */
-#define event_add(event)       \
-do {                                                                         \
-  struct Event* _ev = (event);                                               \
-  _ev->ev_next = 0;                                                          \
-  _ev->ev_prev_p = 0;                                                        \
-  event_execute(_ev);                                                        \
-} while (0)
-
-#else
 /** Add an event to the work queue.
  * @param[in] event Event to enqueue.
  */
@@ -238,6 +269,43 @@
     /* We'd also have to signal the work crew here */
   }
 }
+
+/** Generate an event and add it to the queue (or execute it).
+ * @param[in] type Type of event to generate.
+ * @param[in] arg Pointer to an event generator (GenHeader).
+ * @param[in] data Extra data for event.
+ */
+void
+event_generate(enum EventType type, void* arg, int data)
+{
+  struct Event* ptr;
+  struct GenHeader* gen = (struct GenHeader*) arg;
+
+  assert(0 != gen);
+
+  /* don't create events (other than ET_DESTROY) for destroyed generators */
+  if (type != ET_DESTROY && (gen->gh_flags & GEN_DESTROY))
+    return;
+
+  Debug((DEBUG_LIST, "Generating event type %s for generator %p (%s)",
+        event_to_name(type), gen, gen_flags(gen->gh_flags)));
+
+  if ((ptr = evInfo.events_free))
+    evInfo.events_free = ptr->ev_next; /* pop one off the freelist */
+  else { /* allocate another structure */
+    ptr = (struct Event*) MyMalloc(sizeof(struct Event));
+    evInfo.events_alloc++; /* count of allocated events */
+  }
+
+  ptr->ev_type = type; /* Record event type */
+  ptr->ev_data = data;
+
+  ptr->ev_gen.gen_header = (struct GenHeader*) gen;
+  ptr->ev_gen.gen_header->gh_ref++;
+
+  event_add(ptr); /* add event to queue */
+}
+
 #endif /* IRCD_THREADED */
 
 /** Place a timer in the correct spot on the queue.
@@ -378,42 +446,6 @@
   (*evInfo.engine->eng_loop)(&evInfo.gens);
 }
 
-/** Generate an event and add it to the queue (or execute it).
- * @param[in] type Type of event to generate.
- * @param[in] arg Pointer to an event generator (GenHeader).
- * @param[in] data Extra data for event.
- */
-void
-event_generate(enum EventType type, void* arg, int data)
-{
-  struct Event* ptr;
-  struct GenHeader* gen = (struct GenHeader*) arg;
-
-  assert(0 != gen);
-
-  /* don't create events (other than ET_DESTROY) for destroyed generators */
-  if (type != ET_DESTROY && (gen->gh_flags & GEN_DESTROY))
-    return;
-
-  Debug((DEBUG_LIST, "Generating event type %s for generator %p (%s)",
-        event_to_name(type), gen, gen_flags(gen->gh_flags)));
-
-  if ((ptr = evInfo.events_free))
-    evInfo.events_free = ptr->ev_next; /* pop one off the freelist */
-  else { /* allocate another structure */
-    ptr = (struct Event*) MyMalloc(sizeof(struct Event));
-    evInfo.events_alloc++; /* count of allocated events */
-  }
-
-  ptr->ev_type = type; /* Record event type */
-  ptr->ev_data = data;
-
-  ptr->ev_gen.gen_header = (struct GenHeader*) gen;
-  ptr->ev_gen.gen_header->gh_ref++;
-
-  event_add(ptr); /* add event to queue */
-}
-
 #if 0
 /* Try to verify the timer list */
 void
----------------------- End of diff -----------------------
_______________________________________________
Patches mailing list
[email protected]
http://undernet.sbg.org/mailman/listinfo/patches

Reply via email to