Using EV_CUSTOM for custom events
Marc Lehmann
schmorp at schmorp.de
Sat Apr 28 14:08:21 CEST 2012
On Fri, Apr 27, 2012 at 10:54:58PM +0400, Konstantin Osipov <kostja at tarantool.org> wrote:
> When event loop is not blocked (sleeping) ev_async_send() does not
> have to write to a pipe, even if executed from a different thread.
> In that case, what does it use, some sort of atomic?
>
> > using. The caveat is that multiple events fed to the same watcher can
> > be collapsed to a single event. Alternately, you could create a new
> > watcher, possibly a timer with zero timeout.
>
> OK, a timer with zero timeout looks safer than a watcher on a
> signal, since in the latter case there could be spurious wake-ups.
If you are within the same thread, and you want to wake up a specific
watcher, then ev_feed_event is the way to go, and you can do that on any
watcher, running or not (as zsbán pointed out).
You can use EV_CUSTOM, but you could also feed any other event - for
libev, it's just a bitset.
From a different thread, ev_async is your only method (again, as zsbán
explained).
If you do it sometimes form the same or different thread, then you could
optimise it by using ev_feed_event form the same thread, on our async
watcher - libev has no "same thread" optimisation anywhere.
--
The choice of a Deliantra, the free code+content MORPG
-----==- _GNU_ http://www.deliantra.net
----==-- _ generation
---==---(_)__ __ ____ __ Marc Lehmann
--==---/ / _ \/ // /\ \/ / schmorp at schmorp.de
-=====/_/_//_/\_,_/ /_/\_\
More information about the libev
mailing list