From ed35fe84c2d1d72e35a7fd111834678b030f2023 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 21 Oct 2010 02:33:08 +0000 Subject: *** empty log message *** --- Changes | 4 ++++ ev++.h | 3 +-- ev.c | 2 ++ ev.h | 2 +- ev.pod | 25 ++++++++++++++++++------- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/Changes b/Changes index 28fd4ed..ca668bd 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,7 @@ Revision history for libev, a high-performance and full-featured event loop. TODO: ABI??? API????? Changes??? TODO: include ev_xyz_start in each example? TODO: section watcher states/lifetime +TODO: ALL ev_xxx_set funtions must be called from ev++ set methods, somehow. - "PORTING FROM LIBEV 3.X TO 4.X" (in ev.pod) is recommended reading. - ev_embed_stop did not correctly stop the watcher (very good testcase by Vladimir Timofeev). @@ -14,6 +15,9 @@ TODO: section watcher states/lifetime seems the former is *much* faster than the latter. - reduce the number of spurious wake-ups with the ports backend. - remove dependency on sys/queue.h on freebsd (patch by Vanilla Hsu). + - do async init within ev_async_start, not ev_async_set, which avoids + an API quirk where the set function must be called in the C++ API + even when there is nothing to set. - add (undocumented) EV_ENABLE when adding events with kqueue, this might help with OS X, which seems to need it despite documenting not to need it (helpfully pointed out by Tilghman Lesher). diff --git a/ev++.h b/ev++.h index 19d9cd2..6c844fe 100644 --- a/ev++.h +++ b/ev++.h @@ -415,6 +415,7 @@ namespace ev { #if EV_MULTIPLICITY EV_PX; + // loop set void set (EV_P) throw () { this->EV_A = EV_A; @@ -783,8 +784,6 @@ namespace ev { #if EV_ASYNC_ENABLE EV_BEGIN_WATCHER (async, async) - void set () throw () { } - void send () throw () { ev_async_send (EV_A_ static_cast(this)); diff --git a/ev.c b/ev.c index 9aed426..6bd4284 100644 --- a/ev.c +++ b/ev.c @@ -3579,6 +3579,8 @@ ev_async_start (EV_P_ ev_async *w) if (expect_false (ev_is_active (w))) return; + w->sent = 0; + evpipe_init (EV_A); EV_FREQUENT_CHECK; diff --git a/ev.h b/ev.h index 20dbc10..fb9056b 100644 --- a/ev.h +++ b/ev.h @@ -642,7 +642,7 @@ void ev_resume (EV_P); #define ev_check_set(ev) /* nop, yes, this is a serious in-joke */ #define ev_embed_set(ev,other_) do { (ev)->other = (other_); } while (0) #define ev_fork_set(ev) /* nop, yes, this is a serious in-joke */ -#define ev_async_set(ev) do { (ev)->sent = 0; } while (0) +#define ev_async_set(ev) /* nop, yes, this is a serious in-joke */ #define ev_io_init(ev,cb,fd,events) do { ev_init ((ev), (cb)); ev_io_set ((ev),(fd),(events)); } while (0) #define ev_timer_init(ev,cb,after,repeat) do { ev_init ((ev), (cb)); ev_timer_set ((ev),(after),(repeat)); } while (0) diff --git a/ev.pod b/ev.pod index b370558..2f405b5 100644 --- a/ev.pod +++ b/ev.pod @@ -3393,16 +3393,22 @@ do this when the watcher is inactive (and not pending either). =item w->set ([arguments]) -Basically the same as C, with the same arguments. Must be -called at least once. Unlike the C counterpart, an active watcher gets -automatically stopped and restarted when reconfiguring it with this -method. +Basically the same as C, with the same arguments. Either this +method or a suitable start method must be called at least once. Unlike the +C counterpart, an active watcher gets automatically stopped and restarted +when reconfiguring it with this method. =item w->start () Starts the watcher. Note that there is no C argument, as the constructor already stores the event loop. +=item w->start ([arguments]) + +Instead of calling C and C methods separately, it is often +convenient to wrap them in one call. Uses the same type of arguments as +the configure C method of the watcher. + =item w->stop () Stops the watcher if it is active. Again, no C argument. @@ -3424,20 +3430,25 @@ Invokes C. =back -Example: Define a class with an IO and idle watcher, start one of them in -the constructor. +Example: Define a class with two I/O and idle watchers, start the I/O +watchers in the constructor. class myclass { ev::io io ; void io_cb (ev::io &w, int revents); + ev::io2 io2 ; void io2_cb (ev::io &w, int revents); ev::idle idle; void idle_cb (ev::idle &w, int revents); myclass (int fd) { io .set (this); + io2 .set (this); idle.set (this); - io.start (fd, ev::READ); + io.set (fd, ev::WRITE); // configure the watcher + io.start (); // start it whenever convenient + + io2.start (fd, ev::READ); // set + start in one call } }; -- cgit v1.2.3