diff options
-rw-r--r-- | ev++.h | 14 | ||||
-rw-r--r-- | ev.c | 32 | ||||
-rw-r--r-- | ev.h | 12 | ||||
-rw-r--r-- | ev.pod | 60 |
4 files changed, 65 insertions, 53 deletions
@@ -1,7 +1,7 @@ /* * libev simple C++ wrapper classes * - * Copyright (c) 2007,2008 Marc Alexander Lehmann <libev@schmorp.de> + * Copyright (c) 2007,2008,2010 Marc Alexander Lehmann <libev@schmorp.de> * All rights reserved. * * Redistribution and use in source and binary forms, with or without modifica- @@ -674,6 +674,7 @@ namespace ev { EV_END_WATCHER (periodic, periodic) #endif + #if EV_SIGNAL_ENABLE EV_BEGIN_WATCHER (sig, signal) void set (int signum) throw () { @@ -689,7 +690,9 @@ namespace ev { start (); } EV_END_WATCHER (sig, signal) + #endif + #if EV_CHILD_ENABLE EV_BEGIN_WATCHER (child, child) void set (int pid, int trace = 0) throw () { @@ -705,6 +708,7 @@ namespace ev { start (); } EV_END_WATCHER (child, child) + #endif #if EV_STAT_ENABLE EV_BEGIN_WATCHER (stat, stat) @@ -730,19 +734,23 @@ namespace ev { EV_END_WATCHER (stat, stat) #endif -#if EV_IDLE_ENABLE + #if EV_IDLE_ENABLE EV_BEGIN_WATCHER (idle, idle) void set () throw () { } EV_END_WATCHER (idle, idle) -#endif + #endif + #if EV_PREPARE_ENABLE EV_BEGIN_WATCHER (prepare, prepare) void set () throw () { } EV_END_WATCHER (prepare, prepare) + #endif + #if EV_CHECK_ENABLE EV_BEGIN_WATCHER (check, check) void set () throw () { } EV_END_WATCHER (check, check) + #endif #if EV_EMBED_ENABLE EV_BEGIN_WATCHER (embed, embed) @@ -893,7 +893,7 @@ queue_events (EV_P_ W *events, int eventcnt, int type) /*****************************************************************************/ inline_speed void -fd_event_nc (EV_P_ int fd, int revents) +fd_event_nocheck (EV_P_ int fd, int revents) { ANFD *anfd = anfds + fd; ev_io *w; @@ -915,14 +915,14 @@ fd_event (EV_P_ int fd, int revents) ANFD *anfd = anfds + fd; if (expect_true (!anfd->reify)) - fd_event_nc (EV_A_ fd, revents); + fd_event_nocheck (EV_A_ fd, revents); } void ev_feed_fd_event (EV_P_ int fd, int revents) { if (fd >= 0 && fd < anfdmax) - fd_event_nc (EV_A_ fd, revents); + fd_event_nocheck (EV_A_ fd, revents); } /* make sure the external fd watch events are in-sync */ @@ -1800,9 +1800,11 @@ loop_fork (EV_P) EV_WIN32_CLOSE_FD (evpipe [1]); } +#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE evpipe_init (EV_A); /* now iterate over everything, in case we missed something */ pipecb (EV_A_ &pipe_w, EV_READ); +#endif } postfork = 0; @@ -1925,11 +1927,15 @@ ev_loop_verify (EV_P) array_verify (EV_A_ (W *)asyncs, asynccnt); #endif +#if EV_PREPARE_ENABLE assert (preparemax >= preparecnt); array_verify (EV_A_ (W *)prepares, preparecnt); +#endif +#if EV_CHECK_ENABLE assert (checkmax >= checkcnt); array_verify (EV_A_ (W *)checks, checkcnt); +#endif # if 0 #if EV_CHILD_ENABLE @@ -2306,12 +2312,14 @@ ev_loop (EV_P_ int flags) } #endif +#if EV_PREPARE_ENABLE /* queue prepare watchers (and execute them) */ if (expect_false (preparecnt)) { queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); EV_INVOKE_PENDING; } +#endif if (expect_false (loop_done)) break; @@ -2394,9 +2402,11 @@ ev_loop (EV_P_ int flags) idle_reify (EV_A); #endif +#if EV_CHECK_ENABLE /* queue check watchers, to be executed first */ if (expect_false (checkcnt)) queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); +#endif EV_INVOKE_PENDING; } @@ -3320,6 +3330,7 @@ ev_idle_stop (EV_P_ ev_idle *w) } #endif +#if EV_PREPARE_ENABLE void ev_prepare_start (EV_P_ ev_prepare *w) { @@ -3355,7 +3366,9 @@ ev_prepare_stop (EV_P_ ev_prepare *w) EV_FREQUENT_CHECK; } +#endif +#if EV_CHECK_ENABLE void ev_check_start (EV_P_ ev_check *w) { @@ -3391,6 +3404,7 @@ ev_check_stop (EV_P_ ev_check *w) EV_FREQUENT_CHECK; } +#endif #if EV_EMBED_ENABLE void noinline @@ -3729,17 +3743,22 @@ ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) cb (EV_A_ EV_ASYNC, asyncs [i]); #endif +#if EV_PREPARE_ENABLE if (types & EV_PREPARE) for (i = preparecnt; i--; ) -#if EV_EMBED_ENABLE +# if EV_EMBED_ENABLE if (ev_cb (prepares [i]) != embed_prepare_cb) -#endif +# endif cb (EV_A_ EV_PREPARE, prepares [i]); +#endif +#if EV_CHECK_ENABLE if (types & EV_CHECK) for (i = checkcnt; i--; ) cb (EV_A_ EV_CHECK, checks [i]); +#endif +#if EV_SIGNAL_ENABLE if (types & EV_SIGNAL) for (i = 0; i < EV_NSIG - 1; ++i) for (wl = signals [i].head; wl; ) @@ -3748,7 +3767,9 @@ ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) cb (EV_A_ EV_SIGNAL, wl); wl = wn; } +#endif +#if EV_CHILD_ENABLE if (types & EV_CHILD) for (i = EV_PID_HASHSIZE; i--; ) for (wl = childs [i]; wl; ) @@ -3757,6 +3778,7 @@ ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) cb (EV_A_ EV_CHILD, wl); wl = wn; } +#endif /* EV_STAT 0x00001000 /* stat data changed */ /* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ } @@ -66,6 +66,14 @@ typedef double ev_tstamp; # define EV_STAT_ENABLE 1 #endif +#ifndef EV_PREPARE_ENABLE +# define EV_PREPARE_ENABLE 1 +#endif + +#ifndef EV_CHECK_ENABLE +# define EV_CHECK_ENABLE 1 +#endif + #ifndef EV_IDLE_ENABLE # define EV_IDLE_ENABLE 1 #endif @@ -694,11 +702,15 @@ void ev_idle_start (EV_P_ ev_idle *w); void ev_idle_stop (EV_P_ ev_idle *w); # endif +#if EV_PREPARE_ENABLE void ev_prepare_start (EV_P_ ev_prepare *w); void ev_prepare_stop (EV_P_ ev_prepare *w); +#endif +#if EV_CHECK_ENABLE void ev_check_start (EV_P_ ev_check *w); void ev_check_stop (EV_P_ ev_check *w); +#endif # if EV_FORK_ENABLE void ev_fork_start (EV_P_ ev_fork *w); @@ -3840,48 +3840,13 @@ fine. If your embedding application does not need any priorities, defining these both to C<0> will save some memory and CPU. -=item EV_PERIODIC_ENABLE +=item EV_PERIODIC_ENABLE, EV_IDLE_ENABLE, EV_EMBED_ENABLE, EV_STAT_ENABLE, +EV_PREPARE_ENABLE, EV_CHECK_ENABLE, EV_FORK_ENABLE, EV_SIGNAL_ENABLE, +EV_ASYNC_ENABLE, EV_CHILD_ENABLE. -If undefined or defined to be C<1>, then periodic timers are supported. If -defined to be C<0>, then they are not. Disabling them saves a few kB of -code. - -=item EV_IDLE_ENABLE - -If undefined or defined to be C<1>, then idle watchers are supported. If -defined to be C<0>, then they are not. Disabling them saves a few kB of -code. - -=item EV_EMBED_ENABLE - -If undefined or defined to be C<1>, then embed watchers are supported. If -defined to be C<0>, then they are not. Embed watchers rely on most other -watcher types, which therefore must not be disabled. - -=item EV_STAT_ENABLE - -If undefined or defined to be C<1>, then stat watchers are supported. If -defined to be C<0>, then they are not. - -=item EV_FORK_ENABLE - -If undefined or defined to be C<1>, then fork watchers are supported. If -defined to be C<0>, then they are not. - -=item EV_SIGNAL_ENABLE - -If undefined or defined to be C<1>, then signal watchers are supported. If -defined to be C<0>, then they are not. - -=item EV_ASYNC_ENABLE - -If undefined or defined to be C<1>, then async watchers are supported. If -defined to be C<0>, then they are not. - -=item EV_CHILD_ENABLE - -If undefined or defined to be C<1> (and C<_WIN32> is not defined), then -child watchers are supported. If defined to be C<0>, then they are not. +If undefined or defined to be C<1> (and the platform supports it), then +the respective watcher type is supported. If defined to be C<0>, then it +is not. Disabling watcher types mainly saves codesize. =item EV_MINIMAL @@ -3902,10 +3867,13 @@ provide a bare-bones event library. See C<ev.h> for details on what parts of the API are still available, and do not complain if this subset changes over time. -This example set of settings reduces the compiled size of libev from 24Kb -to 8Kb on my GNU/Linux amd64 system (and leaves little in - there is also -an effect on the amount of memory used). With an intelligent-enough linker -further unused functions might be left out as well automatically. +This example set of settings reduces the compiled size of libev from +23.9Kb to 7.7Kb on my GNU/Linux amd64 system (and leaves little +in - there is also an effect on the amount of memory used). With +an intelligent-enough linker (gcc+binutils do this when you use +C<-Wl,--gc-sections -ffunction-sections>) further unused functions might +be left out as well automatically - a binary starting a timer and an I/O +watcher then might come out at only 5Kb. // tuning and API changes #define EV_MINIMAL 2 @@ -3931,6 +3899,8 @@ further unused functions might be left out as well automatically. #define EV_STAT_ENABLE 0 #define EV_PERIODIC_ENABLE 0 #define EV_IDLE_ENABLE 0 + #define EV_CHECK_ENABLE 0 + #define EV_PREPARE_ENABLE 0 #define EV_FORK_ENABLE 0 #define EV_SIGNAL_ENABLE 0 #define EV_CHILD_ENABLE 0 |