From 57e6fe17689de1646a53a20a46374936391db3e2 Mon Sep 17 00:00:00 2001
From: root
Date: Sat, 8 Dec 2007 14:27:38 +0000
Subject: fix c++ interface
---
ev++.h | 29 +++++++++++++----------------
ev.3 | 33 ++++++++++++++++++++++++++++-----
ev.c | 21 +++++++++++----------
ev.html | 29 +++++++++++++++++++++++++----
ev.pod | 9 ++++++++-
5 files changed, 85 insertions(+), 36 deletions(-)
diff --git a/ev++.h b/ev++.h
index fea0ac1..71a3d52 100644
--- a/ev++.h
+++ b/ev++.h
@@ -22,10 +22,10 @@ namespace ev {
ev_init (this, 0);
}
- void set_ (void *object, void (*cb)(EV_P_ ev_watcher *w, int revents))
+ void set_ (void *data, void (*cb)(EV_P_ watcher *w, int revents))
{
- this->data = object;
- ev_set_cb (static_cast(this), cb);
+ this->data = data;
+ ev_set_cb (static_cast(this), cb);
}
template
@@ -35,11 +35,10 @@ namespace ev {
}
template
- static void method_thunk (EV_P_ ev_watcher *w, int revents)
+ static void method_thunk (EV_P_ watcher *w, int revents)
{
- watcher *self = static_cast(w);
- K *obj = static_cast(self->data);
- (obj->*method) (*self, revents);
+ K *obj = static_cast(w->data);
+ (obj->*method) (*w, revents);
}
template
@@ -49,24 +48,22 @@ namespace ev {
}
template
- static void const_method_thunk (EV_P_ ev_watcher *w, int revents)
+ static void const_method_thunk (EV_P_ watcher *w, int revents)
{
- watcher *self = static_cast(w);
- K *obj = static_cast(self->data);
- (obj->*method) (*self, revents);
+ K *obj = static_cast(w->data);
+ (obj->*method) (*w, revents);
}
- template
- void set ()
+ template
+ void set (void *data = 0)
{
set_ (data, function_thunk);
}
template
- static void function_thunk (EV_P_ ev_watcher *w, int revents)
+ static void function_thunk (EV_P_ watcher *w, int revents)
{
- watcher *self = static_cast(w);
- function (*self, revents);
+ function (*w, revents);
}
void operator ()(int events = EV_UNDEF)
diff --git a/ev.3 b/ev.3
index 1f33e81..8e5a19f 100644
--- a/ev.3
+++ b/ev.3
@@ -129,7 +129,7 @@
.\" ========================================================================
.\"
.IX Title """ 1"
-.TH "" 1 "2007-12-07" "perl v5.8.8" "User Contributed Perl Documentation"
+.TH "" 1 "2007-12-08" "perl v5.8.8" "User Contributed Perl Documentation"
.SH "NAME"
libev \- a high performance full\-featured event loop written in C
.SH "SYNOPSIS"
@@ -891,8 +891,9 @@ it.
Returns a true value iff the watcher is pending, (i.e. it has outstanding
events but its callback has not yet been invoked). As long as a watcher
is pending (but not active) you must not call an init function on it (but
-\&\f(CW\*(C`ev_TYPE_set\*(C'\fR is safe) and you must make sure the watcher is available to
-libev (e.g. you cnanot \f(CW\*(C`free ()\*(C'\fR it).
+\&\f(CW\*(C`ev_TYPE_set\*(C'\fR is safe), you must not change its priority, and you must
+make sure the watcher is available to libev (e.g. you cannot \f(CW\*(C`free ()\*(C'\fR
+it).
.IP "callback ev_cb (ev_TYPE *watcher)" 4
.IX Item "callback ev_cb (ev_TYPE *watcher)"
Returns the callback currently set on the watcher.
@@ -920,12 +921,25 @@ watchers on the same event and make sure one is called first.
If you need to suppress invocation when higher priority events are pending
you need to look at \f(CW\*(C`ev_idle\*(C'\fR watchers, which provide this functionality.
.Sp
+You \fImust not\fR change the priority of a watcher as long as it is active or
+pending.
+.Sp
The default priority used by watchers when no priority has been set is
always \f(CW0\fR, which is supposed to not be too high and not be too low :).
.Sp
Setting a priority outside the range of \f(CW\*(C`EV_MINPRI\*(C'\fR to \f(CW\*(C`EV_MAXPRI\*(C'\fR is
fine, as long as you do not mind that the priority value you query might
or might not have been adjusted to be within valid range.
+.IP "ev_invoke (loop, ev_TYPE *watcher, int revents)" 4
+.IX Item "ev_invoke (loop, ev_TYPE *watcher, int revents)"
+Invoke the \f(CW\*(C`watcher\*(C'\fR with the given \f(CW\*(C`loop\*(C'\fR and \f(CW\*(C`revents\*(C'\fR. Neither
+\&\f(CW\*(C`loop\*(C'\fR nor \f(CW\*(C`revents\*(C'\fR need to be valid as long as the watcher callback
+can deal with that fact.
+.IP "int ev_clear_pending (loop, ev_TYPE *watcher)" 4
+.IX Item "int ev_clear_pending (loop, ev_TYPE *watcher)"
+If the watcher is pending, this function returns clears its pending status
+and returns its \f(CW\*(C`revents\*(C'\fR bitset (as if its callback was invoked). If the
+watcher isn't pending it does nothing and returns \f(CW0\fR.
.Sh "\s-1ASSOCIATING\s0 \s-1CUSTOM\s0 \s-1DATA\s0 \s-1WITH\s0 A \s-1WATCHER\s0"
.IX Subsection "ASSOCIATING CUSTOM DATA WITH A WATCHER"
Each watcher has, by default, a member \f(CW\*(C`void *data\*(C'\fR that you can change
@@ -1980,13 +1994,22 @@ Example: simple class declaration and watcher initialisation
\& ev::io iow;
\& iow.set (&obj);
.Ve
-.IP "w\->set (void (*function)(watcher &w, int), void *data = 0)" 4
-.IX Item "w->set (void (*function)(watcher &w, int), void *data = 0)"
+.IP "w\->set (void *data = 0)" 4
+.IX Item "w->set (void *data = 0)"
Also sets a callback, but uses a static method or plain function as
callback. The optional \f(CW\*(C`data\*(C'\fR argument will be stored in the watcher's
\&\f(CW\*(C`data\*(C'\fR member and is free for you to use.
.Sp
+The prototype of the \f(CW\*(C`function\*(C'\fR must be \f(CW\*(C`void (*)(ev::TYPE &w, int)\*(C'\fR.
+.Sp
See the method\-\f(CW\*(C`set\*(C'\fR above for more details.
+.Sp
+Example:
+.Sp
+.Vb 2
+\& static void io_cb (ev::io &w, int revents) { }
+\& iow.set ();
+.Ve
.IP "w\->set (struct ev_loop *)" 4
.IX Item "w->set (struct ev_loop *)"
Associates a different \f(CW\*(C`struct ev_loop\*(C'\fR with this watcher. You can only
diff --git a/ev.c b/ev.c
index 7e9423e..dbda0b9 100644
--- a/ev.c
+++ b/ev.c
@@ -224,23 +224,24 @@ extern "C" {
#if __GNUC__ >= 3
# define expect(expr,value) __builtin_expect ((expr),(value))
-# define inline_size static inline /* inline for codesize */
-# if EV_MINIMAL
-# define noinline __attribute__ ((noinline))
-# define inline_speed static noinline
-# else
-# define noinline
-# define inline_speed static inline
-# endif
+# define noinline __attribute__ ((noinline))
#else
# define expect(expr,value) (expr)
-# define inline_speed static
-# define inline_size static
# define noinline
+# if __STDC_VERSION__ < 199901L
+# define inline
+# endif
#endif
#define expect_false(expr) expect ((expr) != 0, 0)
#define expect_true(expr) expect ((expr) != 0, 1)
+#define inline_size static inline
+
+#if EV_MINIMAL
+# define inline_speed static noinline
+#else
+# define inline_speed static inline
+#endif
#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1)
#define ABSPRI(w) (((W)w)->priority - EV_MINPRI)
diff --git a/ev.html b/ev.html
index 738d6d0..d8909ea 100644
--- a/ev.html
+++ b/ev.html
@@ -6,7 +6,7 @@
-
+
@@ -771,8 +771,9 @@ it.
Returns a true value iff the watcher is pending, (i.e. it has outstanding
events but its callback has not yet been invoked). As long as a watcher
is pending (but not active) you must not call an init function on it (but
-ev_TYPE_set is safe) and you must make sure the watcher is available to
-libev (e.g. you cnanot free () it).
+ev_TYPE_set is safe), you must not change its priority, and you must
+make sure the watcher is available to libev (e.g. you cannot free ()
+it).
callback ev_cb (ev_TYPE *watcher)
@@ -797,12 +798,26 @@ example, to reduce latency after idling, or more often, to bind two
watchers on the same event and make sure one is called first.
If you need to suppress invocation when higher priority events are pending
you need to look at ev_idle watchers, which provide this functionality.
+
You must not change the priority of a watcher as long as it is active or
+pending.
The default priority used by watchers when no priority has been set is
always 0, which is supposed to not be too high and not be too low :).
Setting a priority outside the range of EV_MINPRI to EV_MAXPRI is
fine, as long as you do not mind that the priority value you query might
or might not have been adjusted to be within valid range.
+
ev_invoke (loop, ev_TYPE *watcher, int revents)
+
+
Invoke the watcher with the given loop and revents. Neither
+loop nor revents need to be valid as long as the watcher callback
+can deal with that fact.
+
+
int ev_clear_pending (loop, ev_TYPE *watcher)
+
+
If the watcher is pending, this function returns clears its pending status
+and returns its revents bitset (as if its callback was invoked). If the
+watcher isn't pending it does nothing and returns 0.
+
@@ -1808,12 +1823,18 @@ thunking function, making it as fast as a direct C callback.
-
Also sets a callback, but uses a static method or plain function as
callback. The optional data argument will be stored in the watcher's
data member and is free for you to use.
+
The prototype of the function must be void (*)(ev::TYPE &w, int).
diff --git a/ev.pod b/ev.pod
index ef9892e..62118f1 100644
--- a/ev.pod
+++ b/ev.pod
@@ -1846,14 +1846,21 @@ Example: simple class declaration and watcher initialisation
ev::io iow;
iow.set (&obj);
-=item w->set (void (*function)(watcher &w, int), void *data = 0)
+=item w->set (void *data = 0)
Also sets a callback, but uses a static method or plain function as
callback. The optional C argument will be stored in the watcher's
C member and is free for you to use.
+The prototype of the C must be C.
+
See the method-C above for more details.
+Example:
+
+ static void io_cb (ev::io &w, int revents) { }
+ iow.set ();
+
=item w->set (struct ev_loop *)
Associates a different C with this watcher. You can only
--
cgit v1.2.3