commit 68888d83c99aac56672d4cbcfa5d95f8e9808f0b
Author: Nathaniel McCallum <npmccallum(a)redhat.com>
Date: Mon Aug 8 21:30:23 2011 -0400
[modules] use verto_ev_flag type instead of char to pass back persistence
src/verto-glib.c | 17 +++++++----------
src/verto-libev.c | 6 +++---
src/verto-libevent.c | 35 +++++++++++++++++------------------
src/verto-module.h | 2 +-
src/verto-tevent.c | 15 ++++++++-------
src/verto.c | 10 ++++++----
6 files changed, 42 insertions(+), 43 deletions(-)
---
diff --git a/src/verto-glib.c b/src/verto-glib.c
index eaf8313..c330bcf 100644
--- a/src/verto-glib.c
+++ b/src/verto-glib.c
@@ -111,13 +111,10 @@ glib_callback_child(GPid pid, gint status, gpointer data)
}
static void *
-glib_ctx_add(void *ctx, const verto_ev *ev, char *persists)
+glib_ctx_add(void *ctx, const verto_ev *ev, verto_ev_flag *flags)
{
glib_ev *gev = NULL;
verto_ev_type type = verto_get_type(ev);
- verto_ev_flag flags = verto_get_flags(ev);
-
- *persists = flags & VERTO_EV_FLAG_PERSIST;
gev = g_new0(glib_ev, 1);
if (!gev)
@@ -135,9 +132,9 @@ glib_ctx_add(void *ctx, const verto_ev *ev, char *persists)
g_io_channel_set_close_on_unref(gev->chan, FALSE);
GIOCondition cond = 0;
- if (flags & VERTO_EV_FLAG_IO_READ)
+ if (*flags & VERTO_EV_FLAG_IO_READ)
cond |= G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
- if (flags & VERTO_EV_FLAG_IO_WRITE)
+ if (*flags & VERTO_EV_FLAG_IO_WRITE)
cond |= G_IO_OUT | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
gev->src = g_io_create_watch(gev->chan, cond);
break;
@@ -149,7 +146,7 @@ glib_ctx_add(void *ctx, const verto_ev *ev, char *persists)
break;
case VERTO_EV_TYPE_CHILD:
gev->src = g_child_watch_source_new(verto_get_proc(ev));
- *persists = FALSE;
+ *flags &= ~VERTO_EV_FLAG_PERSIST; /* Child events don't persist */
break;
case VERTO_EV_TYPE_SIGNAL:
#if GLIB_MAJOR_VERSION >= 2
@@ -174,11 +171,11 @@ glib_ctx_add(void *ctx, const verto_ev *ev, char *persists)
else
g_source_set_callback(gev->src, glib_callback, (void *) ev, NULL);
- if (flags & VERTO_EV_FLAG_PRIORITY_HIGH)
+ if (*flags & VERTO_EV_FLAG_PRIORITY_HIGH)
g_source_set_priority(gev->src, G_PRIORITY_HIGH);
- else if (flags & VERTO_EV_FLAG_PRIORITY_MEDIUM)
+ else if (*flags & VERTO_EV_FLAG_PRIORITY_MEDIUM)
g_source_set_priority(gev->src, G_PRIORITY_DEFAULT_IDLE);
- else if (flags & VERTO_EV_FLAG_PRIORITY_LOW)
+ else if (*flags & VERTO_EV_FLAG_PRIORITY_LOW)
g_source_set_priority(gev->src, G_PRIORITY_LOW);
g_source_set_can_recurse(gev->src, FALSE);
diff --git a/src/verto-libev.c b/src/verto-libev.c
index a08b82c..11e3ec2 100644
--- a/src/verto-libev.c
+++ b/src/verto-libev.c
@@ -73,7 +73,7 @@ libev_callback(EV_P_ ev_watcher *w, int revents)
return type ## w
static void *
-libev_ctx_add(void *ctx, const verto_ev *ev, char *persists)
+libev_ctx_add(void *ctx, const verto_ev *ev, verto_ev_flag *flags)
{
ev_io *iow = NULL;
ev_timer *timerw = NULL;
@@ -83,7 +83,7 @@ libev_ctx_add(void *ctx, const verto_ev *ev, char *persists)
ev_tstamp interval;
int events = EV_NONE;
- *persists = 1;
+ *flags |= VERTO_EV_FLAG_PERSIST;
switch (verto_get_type(ev)) {
case VERTO_EV_TYPE_IO:
if (verto_get_flags(ev) & VERTO_EV_FLAG_IO_READ)
@@ -99,7 +99,7 @@ libev_ctx_add(void *ctx, const verto_ev *ev, char *persists)
case VERTO_EV_TYPE_SIGNAL:
setuptype(signal, ev, libev_callback, verto_get_signal(ev));
case VERTO_EV_TYPE_CHILD:
- *persists = 0;
+ *flags &= ~VERTO_EV_FLAG_PERSIST; /* Child events don't persist */
setuptype(child, ev, libev_callback, verto_get_proc(ev), 0);
default:
return NULL; /* Not supported */
diff --git a/src/verto-libevent.c b/src/verto-libevent.c
index 9754f10..87603b6 100644
--- a/src/verto-libevent.c
+++ b/src/verto-libevent.c
@@ -68,36 +68,35 @@ libevent_callback(evutil_socket_t socket, short type, void *data)
}
static void *
-libevent_ctx_add(void *ctx, const verto_ev *ev, char *persists)
+libevent_ctx_add(void *ctx, const verto_ev *ev, verto_ev_flag *flags)
{
struct event *priv = NULL;
struct timeval *timeout = NULL;
struct timeval tv;
- int flags = 0;
- verto_ev_flag evflags = verto_get_flags(ev);
+ int libeventflags = 0;
- *persists = evflags & VERTO_EV_FLAG_PERSIST;
- if (*persists)
- flags |= EV_PERSIST;
+ if (*flags & VERTO_EV_FLAG_PERSIST)
+ libeventflags |= EV_PERSIST;
switch (verto_get_type(ev)) {
case VERTO_EV_TYPE_IO:
- if (evflags & VERTO_EV_FLAG_IO_READ)
- flags |= EV_READ;
- if (evflags & VERTO_EV_FLAG_IO_WRITE)
- flags |= EV_WRITE;
- priv = event_new(ctx, verto_get_fd(ev), flags, libevent_callback,
- (void *) ev);
+ if (*flags & VERTO_EV_FLAG_IO_READ)
+ libeventflags |= EV_READ;
+ if (*flags & VERTO_EV_FLAG_IO_WRITE)
+ libeventflags |= EV_WRITE;
+ priv = event_new(ctx, verto_get_fd(ev), libeventflags,
+ libevent_callback, (void *) ev);
break;
case VERTO_EV_TYPE_TIMEOUT:
timeout = &tv;
tv.tv_sec = verto_get_interval(ev) / 1000;
tv.tv_usec = verto_get_interval(ev) % 1000 * 1000;
- priv = event_new(ctx, -1, EV_TIMEOUT | flags, libevent_callback,
- (void *) ev);
+ priv = event_new(ctx, -1, EV_TIMEOUT | libeventflags,
+ libevent_callback, (void *) ev);
break;
case VERTO_EV_TYPE_SIGNAL:
- priv = event_new(ctx, verto_get_signal(ev), EV_SIGNAL | flags,
+ priv = event_new(ctx, verto_get_signal(ev),
+ EV_SIGNAL | libeventflags,
libevent_callback, (void *) ev);
break;
case VERTO_EV_TYPE_IDLE:
@@ -109,11 +108,11 @@ libevent_ctx_add(void *ctx, const verto_ev *ev, char *persists)
if (!priv)
return NULL;
- if (evflags & VERTO_EV_FLAG_PRIORITY_HIGH)
+ if (*flags & VERTO_EV_FLAG_PRIORITY_HIGH)
event_priority_set(priv, 0);
- else if (evflags & VERTO_EV_FLAG_PRIORITY_MEDIUM)
+ else if (*flags & VERTO_EV_FLAG_PRIORITY_MEDIUM)
event_priority_set(priv, 1);
- else if (evflags & VERTO_EV_FLAG_PRIORITY_LOW)
+ else if (*flags & VERTO_EV_FLAG_PRIORITY_LOW)
event_priority_set(priv, 2);
event_add(priv, timeout);
diff --git a/src/verto-module.h b/src/verto-module.h
index 666083e..fad9042 100644
--- a/src/verto-module.h
+++ b/src/verto-module.h
@@ -63,7 +63,7 @@ typedef struct {
void (*ctx_run)(void *ctx);
void (*ctx_run_once)(void *ctx);
void (*ctx_break)(void *ctx);
- void *(*ctx_add)(void *ctx, const verto_ev *ev, char *persists);
+ void *(*ctx_add)(void *ctx, const verto_ev *ev, verto_ev_flag *flags);
void (*ctx_del)(void *ctx, const verto_ev *ev, void *evpriv);
} verto_ev_ctx_funcs;
diff --git a/src/verto-tevent.c b/src/verto-tevent.c
index 59e69bc..8500e16 100644
--- a/src/verto-tevent.c
+++ b/src/verto-tevent.c
@@ -78,23 +78,24 @@ definecb(timer, struct timeval ct)
definecb(signal, int signum, int count, void *siginfo)
static void *
-tevent_ctx_add(void *ctx, const verto_ev *ev, char *persists)
+tevent_ctx_add(void *ctx, const verto_ev *ev, verto_ev_flag *flags)
+
{
time_t interval;
struct timeval tv;
- uint16_t flags = 0;
+ uint16_t teventflags = 0;
- *persists = 1;
+ *flags |= VERTO_EV_FLAG_PERSIST;
switch (verto_get_type(ev)) {
case VERTO_EV_TYPE_IO:
if (verto_get_flags(ev) & VERTO_EV_FLAG_IO_READ)
- flags |= TEVENT_FD_READ;
+ teventflags |= TEVENT_FD_READ;
if (verto_get_flags(ev) & VERTO_EV_FLAG_IO_WRITE)
- flags |= TEVENT_FD_WRITE;
+ teventflags |= TEVENT_FD_WRITE;
return tevent_add_fd(tctx(ctx), tctx(ctx), verto_get_fd(ev),
- flags, tevent_fd_cb, (void *) ev);
+ teventflags, tevent_fd_cb, (void *) ev);
case VERTO_EV_TYPE_TIMEOUT:
- *persists = 0;
+ *flags &= ~VERTO_EV_FLAG_PERSIST; /* Timeout events don't persist */
interval = verto_get_interval(ev);
tv = tevent_timeval_current_ofs(interval / 1000, interval % 1000 * 1000);
return tevent_add_timer(tctx(ctx), tctx(ctx), tv,
diff --git a/src/verto.c b/src/verto.c
index ffbe9e3..0042095 100644
--- a/src/verto.c
+++ b/src/verto.c
@@ -171,7 +171,7 @@ struct _verto_ev {
void *priv;
void *modpriv;
verto_ev_flag flags;
- bool persists;
+ verto_ev_flag actual;
size_t depth;
bool deleted;
union {
@@ -537,7 +537,8 @@ verto_break(verto_ev_ctx *ctx)
verto_ev *ev = make_ev(ctx, callback, priv, type, flags); \
if (ev) { \
set; \
- ev->modpriv = ctx->funcs.ctx_add(ctx->modpriv, ev, &ev->persists); \
+ ev->actual = ev->flags; \
+ ev->modpriv = ctx->funcs.ctx_add(ctx->modpriv, ev, &ev->actual); \
if (!ev->modpriv) { \
free(ev); \
return NULL; \
@@ -711,8 +712,9 @@ verto_fire(verto_ev *ev)
if (ev->depth == 0) {
if (!(ev->flags & VERTO_EV_FLAG_PERSIST) || ev->deleted)
verto_del(ev);
- else if (!ev->persists) {
- priv = ev->ctx->funcs.ctx_add(ev->ctx->modpriv, ev, &ev->persists);
+ else if (!ev->actual & VERTO_EV_FLAG_PERSIST) {
+ ev->actual = ev->flags;
+ priv = ev->ctx->funcs.ctx_add(ev->ctx->modpriv, ev, &ev->actual);
assert(priv); /* TODO: create an error callback */
ev->ctx->funcs.ctx_del(ev->ctx->modpriv, ev, ev->modpriv);
ev->modpriv = priv;