summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot <root>2007-10-31 00:32:33 +0000
committerroot <root>2007-10-31 00:32:33 +0000
commiteec85cf766fbaa1ee090c8daaf5b4a501f890f63 (patch)
tree6cd956df2aaef68a8b044a0ff16ac9d344cb9d58
parentefb07571c1a235448b70212dc46467214da4bb92 (diff)
implement primitive hook management
-rw-r--r--ev.c45
-rw-r--r--ev.h7
2 files changed, 51 insertions, 1 deletions
diff --git a/ev.c b/ev.c
index 852c779..e328df3 100644
--- a/ev.c
+++ b/ev.c
@@ -42,6 +42,8 @@ static ev_tstamp method_fudge; /* stupid epoll-returns-early bug */
static void (*method_modify)(int fd, int oev, int nev);
static void (*method_poll)(ev_tstamp timeout);
+/*****************************************************************************/
+
ev_tstamp
ev_time (void)
{
@@ -81,6 +83,8 @@ get_clock (void)
cur = newcnt; \
}
+/*****************************************************************************/
+
typedef struct
{
struct ev_io *head;
@@ -137,6 +141,8 @@ fd_event (int fd, int events)
}
}
+/*****************************************************************************/
+
static struct ev_timer **atimers;
static int atimermax, atimercnt;
@@ -184,6 +190,8 @@ downheap (struct ev_timer **timers, int N, int k)
timers [k]->active = k + 1;
}
+/*****************************************************************************/
+
typedef struct
{
struct ev_signal *head;
@@ -253,6 +261,8 @@ siginit (void)
evio_start (&sigev);
}
+/*****************************************************************************/
+
#if HAVE_EPOLL
# include "ev_epoll.c"
#endif
@@ -294,6 +304,8 @@ int ev_init (int flags)
return ev_method;
}
+/*****************************************************************************/
+
void ev_prefork (void)
{
}
@@ -316,6 +328,29 @@ void ev_postfork_child (void)
siginit ();
}
+/*****************************************************************************/
+
+static ev_hook hooks [EVHOOK_NUM];
+
+void
+ev_hook_register (int type, ev_hook hook)
+{
+ hooks [type] = hook;
+}
+
+void
+ev_hook_unregister (int type, ev_hook hook)
+{
+ hooks [type] = 0;
+}
+
+static void
+hook_call (int type)
+{
+ if (hooks [type])
+ hooks [type] ();
+}
+
static void
fd_reify (void)
{
@@ -439,6 +474,8 @@ void ev_loop (int flags)
do
{
+ hook_call (EVHOOK_PREPOLL);
+
/* update fd-related kernel structures */
fd_reify ();
@@ -469,6 +506,8 @@ void ev_loop (int flags)
/* update ev_now, do magic */
time_update ();
+ hook_call (EVHOOK_POSTPOLL);
+
/* put pending timers into pendign queue and reschedule them */
/* absolute timers first */
timers_reify (atimers, atimercnt, ev_now);
@@ -480,6 +519,8 @@ void ev_loop (int flags)
while (!ev_loop_done);
}
+/*****************************************************************************/
+
static void
wlist_add (struct ev_watcher_list **head, struct ev_watcher_list *elem)
{
@@ -519,6 +560,8 @@ ev_stop (struct ev_watcher *w)
/* nop */
}
+/*****************************************************************************/
+
void
evio_start (struct ev_io *w)
{
@@ -673,7 +716,7 @@ int main (void)
struct ev_timer t[10000];
-#if 0
+#if 1
int i;
for (i = 0; i < 10000; ++i)
{
diff --git a/ev.h b/ev.h
index 3467060..9290378 100644
--- a/ev.h
+++ b/ev.h
@@ -64,6 +64,13 @@ ev_tstamp ev_time (void);
void ev_loop (int flags);
extern int ev_loop_done; /* set to 1 to break out of event loop */
+#define EVHOOK_PREPOLL 0 /* called before updating fds, timers and blocking */
+#define EVHOOK_POSTPOLL 1 /* called after blocking */
+#define EVHOOK_NUM 2 /* just the # of hooks */
+typedef void (*ev_hook)(void);
+void ev_hook_register (int type, ev_hook hook);
+void ev_hook_unregister (int type, ev_hook hook);
+
/* these may evaluate ev multiple times, and the other arguments at most once */
#define evw_init(ev,cb_,data_) do { (ev)->active = 0; (ev)->cb = (cb_); (ev)->data = (void *)data_; } while (0)