ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.h
(Generate patch)

Comparing libev/ev.h (file contents):
Revision 1.143 by root, Fri Oct 22 05:57:55 2010 UTC vs.
Revision 1.146 by root, Fri Oct 22 06:14:28 2010 UTC

145# include <sys/types.h> 145# include <sys/types.h>
146# endif 146# endif
147# include <sys/stat.h> 147# include <sys/stat.h>
148#endif 148#endif
149 149
150/* in C++ we can use this to provide default arguments */
150#ifdef __cplusplus 151#ifdef __cplusplus
151# define EV_DEFARG(x) = x 152# define EV_DEFARG(x) = x
152#else 153#else
153# define EV_DEFARG(x) 154# define EV_DEFARG(x)
154#endif 155#endif
155 156
156/* support multiple event loops? */ 157/* support multiple event loops? */
157#if EV_MULTIPLICITY 158#if EV_MULTIPLICITY
158struct ev_loop; 159struct ev_loop;
159# define EV_P struct ev_loop *loop 160# define EV_P struct ev_loop *loop /* a loop as sole parameter in a declaration */
160# define EV_P_ EV_P, 161# define EV_P_ EV_P, /* a loop as first of multiple parameters */
161# define EV_A loop 162# define EV_A loop /* a loop as sole argument to a function call */
162# define EV_A_ EV_A, 163# define EV_A_ EV_A, /* a loop as first of multiple arguments */
163# define EV_DEFAULT_UC ev_default_loop_uc () 164# define EV_DEFAULT_UC ev_default_loop_uc () /* the default loop, if initialised, as sole arg */
164# define EV_DEFAULT_UC_ EV_DEFAULT_UC, 165# define EV_DEFAULT_UC_ EV_DEFAULT_UC, /* the default loop as first of multiple arguments */
165# define EV_DEFAULT ev_default_loop (0) 166# define EV_DEFAULT ev_default_loop (0) /* the default loop as sole arg */
166# define EV_DEFAULT_ EV_DEFAULT, 167# define EV_DEFAULT_ EV_DEFAULT, /* the default loop as first of multiple arguments */
168# define EV_PDEF EV_P EV_DEFARG (EV_DEFAULT_UC) /* EV_P, but with default argument in C++ */
169# define EV_PDEF_ EV_P EV_DEFARG (EV_DEFAULT_UC), /* EV_P_, but with default argument in C++ */
167#else 170#else
168# define EV_P void 171# define EV_P void
169# define EV_P_ 172# define EV_P_
170# define EV_A 173# define EV_A
171# define EV_A_ 174# define EV_A_
172# define EV_DEFAULT 175# define EV_DEFAULT
173# define EV_DEFAULT_ 176# define EV_DEFAULT_
174# define EV_DEFAULT_UC 177# define EV_DEFAULT_UC
175# define EV_DEFAULT_UC_ 178# define EV_DEFAULT_UC_
179# define EV_PDEF EV_P
180# define EV_PDEF_ EV_P_
176# undef EV_EMBED_ENABLE 181# undef EV_EMBED_ENABLE
177#endif 182#endif
178 183
184/* EV_INLINE is used for functions in header files */
179#if __STDC_VERSION__ >= 199901L || __GNUC__ >= 3 185#if __STDC_VERSION__ >= 199901L || __GNUC__ >= 3
180# define EV_INLINE static inline 186# define EV_INLINE static inline
181#else 187#else
182# define EV_INLINE static 188# define EV_INLINE static
183#endif 189#endif
184 190
191/* EV_PROTOTYPES can be sued to switch of prototype declarations */
185#ifndef EV_PROTOTYPES 192#ifndef EV_PROTOTYPES
186# define EV_PROTOTYPES 1 193# define EV_PROTOTYPES 1
187#endif 194#endif
188 195
189/*****************************************************************************/ 196/*****************************************************************************/
535 return loop; 542 return loop;
536} 543}
537 544
538/* create and destroy alternative loops that don't handle signals */ 545/* create and destroy alternative loops that don't handle signals */
539struct ev_loop *ev_loop_new (unsigned int flags EV_DEFARG (0)); 546struct ev_loop *ev_loop_new (unsigned int flags EV_DEFARG (0));
540void ev_loop_destroy (EV_P); 547void ev_loop_destroy (EV_PDEF);
541void ev_loop_fork (EV_P); 548void ev_loop_fork (EV_PDEF);
542 549
543ev_tstamp ev_now (EV_P); /* time w.r.t. timers and the eventloop, updated after each poll */ 550ev_tstamp ev_now (EV_PDEF); /* time w.r.t. timers and the eventloop, updated after each poll */
544 551
545#else 552#else
546 553
547int ev_default_loop (unsigned int flags EV_DEFARG (0)); /* returns true when successful */ 554int ev_default_loop (unsigned int flags EV_DEFARG (0)); /* returns true when successful */
548 555
554 return ev_rt_now; 561 return ev_rt_now;
555} 562}
556#endif /* multiplicity */ 563#endif /* multiplicity */
557 564
558EV_INLINE int 565EV_INLINE int
559ev_is_default_loop (EV_P) 566ev_is_default_loop (EV_PDEF)
560{ 567{
561#if EV_MULTIPLICITY 568#if EV_MULTIPLICITY
562 extern struct ev_loop *ev_default_loop_ptr; 569 extern struct ev_loop *ev_default_loop_ptr;
563 570
564 return !!(EV_A == ev_default_loop_ptr); 571 return !!(EV_A == ev_default_loop_ptr);
572/* if you create alternative loops you have to call ev_loop_fork on them */ 579/* if you create alternative loops you have to call ev_loop_fork on them */
573/* you can call it in either the parent or the child */ 580/* you can call it in either the parent or the child */
574/* you can actually call it at any time, anywhere :) */ 581/* you can actually call it at any time, anywhere :) */
575void ev_default_fork (void); 582void ev_default_fork (void);
576 583
577unsigned int ev_backend (EV_P); /* backend in use by loop */ 584unsigned int ev_backend (EV_PDEF); /* backend in use by loop */
578 585
579void ev_now_update (EV_P); /* update event loop time */ 586void ev_now_update (EV_PDEF); /* update event loop time */
580 587
581#if EV_WALK_ENABLE 588#if EV_WALK_ENABLE
582/* walk (almost) all watchers in the loop of a given type, invoking the */ 589/* walk (almost) all watchers in the loop of a given type, invoking the */
583/* callback on every such watcher. The callback might stop the watcher, */ 590/* callback on every such watcher. The callback might stop the watcher, */
584/* but do nothing else with the loop */ 591/* but do nothing else with the loop */
599 EVBREAK_ONE = 1, /* unloop once */ 606 EVBREAK_ONE = 1, /* unloop once */
600 EVBREAK_ALL = 2 /* unloop all loops */ 607 EVBREAK_ALL = 2 /* unloop all loops */
601}; 608};
602 609
603#if EV_PROTOTYPES 610#if EV_PROTOTYPES
604void ev_run (EV_P_ int flags EV_DEFARG (0)); 611void ev_run (EV_PDEF_ int flags EV_DEFARG (0));
605void ev_break (EV_P_ int how EV_DEFARG (EVBREAK_ONE)); /* break out of the loop */ 612void ev_break (EV_PDEF_ int how EV_DEFARG (EVBREAK_ONE)); /* break out of the loop */
606 613
607/* 614/*
608 * ref/unref can be used to add or remove a refcount on the mainloop. every watcher 615 * ref/unref can be used to add or remove a refcount on the mainloop. every watcher
609 * keeps one reference. if you have a long-running watcher you never unregister that 616 * keeps one reference. if you have a long-running watcher you never unregister that
610 * should not keep ev_loop from running, unref() after starting, and ref() before stopping. 617 * should not keep ev_loop from running, unref() after starting, and ref() before stopping.
611 */ 618 */
612void ev_ref (EV_P); 619void ev_ref (EV_PDEF);
613void ev_unref (EV_P); 620void ev_unref (EV_PDEF);
614 621
615/* 622/*
616 * convenience function, wait for a single event, without registering an event watcher 623 * convenience function, wait for a single event, without registering an event watcher
617 * if timeout is < 0, do wait indefinitely 624 * if timeout is < 0, do wait indefinitely
618 */ 625 */
619void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg); 626void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg);
620 627
621# if EV_FEATURE_API 628# if EV_FEATURE_API
622unsigned int ev_iteration (EV_P); /* number of loop iterations */ 629unsigned int ev_iteration (EV_PDEF); /* number of loop iterations */
623unsigned int ev_depth (EV_P); /* #ev_loop enters - #ev_loop leaves */ 630unsigned int ev_depth (EV_PDEF); /* #ev_loop enters - #ev_loop leaves */
624void ev_verify (EV_P); /* abort if loop data corrupted */ 631void ev_verify (EV_PDEF); /* abort if loop data corrupted */
625 632
626void ev_set_io_collect_interval (EV_P_ ev_tstamp interval); /* sleep at least this time, default 0 */ 633void ev_set_io_collect_interval (EV_P_ ev_tstamp interval); /* sleep at least this time, default 0 */
627void ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval); /* sleep at least this time, default 0 */ 634void ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval); /* sleep at least this time, default 0 */
628 635
629/* advanced stuff for threading etc. support, see docs */ 636/* advanced stuff for threading etc. support, see docs */
630void ev_set_userdata (EV_P_ void *data); 637void ev_set_userdata (EV_P_ void *data);
631void *ev_userdata (EV_P); 638void *ev_userdata (EV_PDEF);
632void ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)); 639void ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P));
633void ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P)); 640void ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P));
634 641
635unsigned int ev_pending_count (EV_P); /* number of pending events, if any */ 642unsigned int ev_pending_count (EV_PDEF); /* number of pending events, if any */
636void ev_invoke_pending (EV_P); /* invoke all pending watchers */ 643void ev_invoke_pending (EV_PDEF); /* invoke all pending watchers */
637 644
638/* 645/*
639 * stop/start the timer handling. 646 * stop/start the timer handling.
640 */ 647 */
641void ev_suspend (EV_P); 648void ev_suspend (EV_PDEF);
642void ev_resume (EV_P); 649void ev_resume (EV_PDEF);
643#endif 650#endif
644 651
645#endif 652#endif
646 653
647/* these may evaluate ev multiple times, and the other arguments at most once */ 654/* these may evaluate ev multiple times, and the other arguments at most once */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines