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

Comparing libev/ev.h (file contents):
Revision 1.142 by root, Thu Oct 21 14:50:58 2010 UTC vs.
Revision 1.145 by root, Fri Oct 22 06:09:26 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#ifdef __cplusplus
151# define EV_DEFARG(x) = x
152#else
153# define EV_DEFARG(x)
154#endif
155
150/* support multiple event loops? */ 156/* support multiple event loops? */
151#if EV_MULTIPLICITY 157#if EV_MULTIPLICITY
152struct ev_loop; 158struct ev_loop;
153# define EV_P struct ev_loop *loop 159# define EV_P struct ev_loop *loop /* a loop as sole parameter in a declaration */
154# define EV_P_ EV_P, 160# define EV_P_ EV_P, /* a loop as first of multiple parameters */
155# define EV_A loop 161# define EV_A loop /* a loop as sole argument to a function call */
156# define EV_A_ EV_A, 162# define EV_A_ EV_A, /* a loop as first of multiple arguments */
157# define EV_DEFAULT_UC ev_default_loop_uc () 163# define EV_DEFAULT_UC ev_default_loop_uc () /* the default loop, if initialised, as sole arg */
158# define EV_DEFAULT_UC_ EV_DEFAULT_UC, 164# define EV_DEFAULT_UC_ EV_DEFAULT_UC, /* the default loop as first of multiple arguments */
159# define EV_DEFAULT ev_default_loop (0) 165# define EV_DEFAULT ev_default_loop (0) /* the default loop as sole arg */
160# define EV_DEFAULT_ EV_DEFAULT, 166# define EV_DEFAULT_ EV_DEFAULT, /* the default loop as first of multiple arguments */
167# define EV_PDEF EV_P EV_DEFARG (EV_DEFAULT_UC) /* EV_P, but with default argument in C++ */
161#else 168#else
162# define EV_P void 169# define EV_P void
163# define EV_P_ 170# define EV_P_
164# define EV_A 171# define EV_A
165# define EV_A_ 172# define EV_A_
166# define EV_DEFAULT 173# define EV_DEFAULT
167# define EV_DEFAULT_ 174# define EV_DEFAULT_
168# define EV_DEFAULT_UC 175# define EV_DEFAULT_UC
169# define EV_DEFAULT_UC_ 176# define EV_DEFAULT_UC_
177# define EV_PDEF EV_P
170# undef EV_EMBED_ENABLE 178# undef EV_EMBED_ENABLE
171#endif 179#endif
172 180
173#if __STDC_VERSION__ >= 199901L || __GNUC__ >= 3 181#if __STDC_VERSION__ >= 199901L || __GNUC__ >= 3
174# define EV_INLINE static inline 182# define EV_INLINE static inline
192 EV_READ = 0x01, /* ev_io detected read will not block */ 200 EV_READ = 0x01, /* ev_io detected read will not block */
193 EV_WRITE = 0x02, /* ev_io detected write will not block */ 201 EV_WRITE = 0x02, /* ev_io detected write will not block */
194 EV__IOFDSET = 0x80, /* internal use only */ 202 EV__IOFDSET = 0x80, /* internal use only */
195 EV_IO = EV_READ, /* alias for type-detection */ 203 EV_IO = EV_READ, /* alias for type-detection */
196 EV_TIMER = 0x00000100, /* timer timed out */ 204 EV_TIMER = 0x00000100, /* timer timed out */
205#if EV_COMPAT3
197 EV_TIMEOUT = EV_TIMER, /* pre 4.0 API compatibility */ 206 EV_TIMEOUT = EV_TIMER, /* pre 4.0 API compatibility */
207#endif
198 EV_PERIODIC = 0x00000200, /* periodic timer timed out */ 208 EV_PERIODIC = 0x00000200, /* periodic timer timed out */
199 EV_SIGNAL = 0x00000400, /* signal was received */ 209 EV_SIGNAL = 0x00000400, /* signal was received */
200 EV_CHILD = 0x00000800, /* child/pid had status change */ 210 EV_CHILD = 0x00000800, /* child/pid had status change */
201 EV_STAT = 0x00001000, /* stat data changed */ 211 EV_STAT = 0x00001000, /* stat data changed */
202 EV_IDLE = 0x00002000, /* event loop is idling */ 212 EV_IDLE = 0x00002000, /* event loop is idling */
511} 521}
512 522
513/* the default loop is the only one that handles signals and child watchers */ 523/* the default loop is the only one that handles signals and child watchers */
514/* you can call this as often as you like */ 524/* you can call this as often as you like */
515EV_INLINE struct ev_loop * 525EV_INLINE struct ev_loop *
516ev_default_loop (unsigned int flags) 526ev_default_loop (unsigned int flags EV_DEFARG (0))
517{ 527{
518 struct ev_loop *loop = ev_default_loop_uc (); 528 struct ev_loop *loop = ev_default_loop_uc ();
519 529
520 if (!loop) 530 if (!loop)
521 { 531 {
526 536
527 return loop; 537 return loop;
528} 538}
529 539
530/* create and destroy alternative loops that don't handle signals */ 540/* create and destroy alternative loops that don't handle signals */
531struct ev_loop *ev_loop_new (unsigned int flags); 541struct ev_loop *ev_loop_new (unsigned int flags EV_DEFARG (0));
532void ev_loop_destroy (EV_P); 542void ev_loop_destroy (EV_PDEF);
533void ev_loop_fork (EV_P); 543void ev_loop_fork (EV_PDEF);
534 544
535ev_tstamp ev_now (EV_P); /* time w.r.t. timers and the eventloop, updated after each poll */ 545ev_tstamp ev_now (EV_PDEF); /* time w.r.t. timers and the eventloop, updated after each poll */
536 546
537#else 547#else
538 548
539int ev_default_loop (unsigned int flags); /* returns true when successful */ 549int ev_default_loop (unsigned int flags EV_DEFARG (0)); /* returns true when successful */
540 550
541EV_INLINE ev_tstamp 551EV_INLINE ev_tstamp
542ev_now (void) 552ev_now (void)
543{ 553{
544 extern ev_tstamp ev_rt_now; 554 extern ev_tstamp ev_rt_now;
546 return ev_rt_now; 556 return ev_rt_now;
547} 557}
548#endif /* multiplicity */ 558#endif /* multiplicity */
549 559
550EV_INLINE int 560EV_INLINE int
551ev_is_default_loop (EV_P) 561ev_is_default_loop (EV_PDEF)
552{ 562{
553#if EV_MULTIPLICITY 563#if EV_MULTIPLICITY
554 extern struct ev_loop *ev_default_loop_ptr; 564 extern struct ev_loop *ev_default_loop_ptr;
555 565
556 return !!(EV_A == ev_default_loop_ptr); 566 return !!(EV_A == ev_default_loop_ptr);
564/* if you create alternative loops you have to call ev_loop_fork on them */ 574/* if you create alternative loops you have to call ev_loop_fork on them */
565/* you can call it in either the parent or the child */ 575/* you can call it in either the parent or the child */
566/* you can actually call it at any time, anywhere :) */ 576/* you can actually call it at any time, anywhere :) */
567void ev_default_fork (void); 577void ev_default_fork (void);
568 578
569unsigned int ev_backend (EV_P); /* backend in use by loop */ 579unsigned int ev_backend (EV_PDEF); /* backend in use by loop */
570 580
571void ev_now_update (EV_P); /* update event loop time */ 581void ev_now_update (EV_PDEF); /* update event loop time */
572 582
573#if EV_WALK_ENABLE 583#if EV_WALK_ENABLE
574/* walk (almost) all watchers in the loop of a given type, invoking the */ 584/* walk (almost) all watchers in the loop of a given type, invoking the */
575/* callback on every such watcher. The callback might stop the watcher, */ 585/* callback on every such watcher. The callback might stop the watcher, */
576/* but do nothing else with the loop */ 586/* but do nothing else with the loop */
591 EVBREAK_ONE = 1, /* unloop once */ 601 EVBREAK_ONE = 1, /* unloop once */
592 EVBREAK_ALL = 2 /* unloop all loops */ 602 EVBREAK_ALL = 2 /* unloop all loops */
593}; 603};
594 604
595#if EV_PROTOTYPES 605#if EV_PROTOTYPES
596void ev_run (EV_P_ int flags); 606void ev_run (EV_P_ int flags EV_DEFARG (0));
597void ev_break (EV_P_ int how); /* set to 1 to break out of event loop, set to 2 to break out of all event loops */ 607void ev_break (EV_P_ int how EV_DEFARG (EVBREAK_ONE)); /* break out of the loop */
598 608
599/* 609/*
600 * ref/unref can be used to add or remove a refcount on the mainloop. every watcher 610 * ref/unref can be used to add or remove a refcount on the mainloop. every watcher
601 * keeps one reference. if you have a long-running watcher you never unregister that 611 * keeps one reference. if you have a long-running watcher you never unregister that
602 * should not keep ev_loop from running, unref() after starting, and ref() before stopping. 612 * should not keep ev_loop from running, unref() after starting, and ref() before stopping.
603 */ 613 */
604void ev_ref (EV_P); 614void ev_ref (EV_PDEF);
605void ev_unref (EV_P); 615void ev_unref (EV_PDEF);
606 616
607/* 617/*
608 * convenience function, wait for a single event, without registering an event watcher 618 * convenience function, wait for a single event, without registering an event watcher
609 * if timeout is < 0, do wait indefinitely 619 * if timeout is < 0, do wait indefinitely
610 */ 620 */
611void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg); 621void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg);
612 622
613# if EV_FEATURE_API 623# if EV_FEATURE_API
614unsigned int ev_iteration (EV_P); /* number of loop iterations */ 624unsigned int ev_iteration (EV_PDEF); /* number of loop iterations */
615unsigned int ev_depth (EV_P); /* #ev_loop enters - #ev_loop leaves */ 625unsigned int ev_depth (EV_PDEF); /* #ev_loop enters - #ev_loop leaves */
616void ev_verify (EV_P); /* abort if loop data corrupted */ 626void ev_verify (EV_PDEF); /* abort if loop data corrupted */
617 627
618void ev_set_io_collect_interval (EV_P_ ev_tstamp interval); /* sleep at least this time, default 0 */ 628void ev_set_io_collect_interval (EV_P_ ev_tstamp interval); /* sleep at least this time, default 0 */
619void ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval); /* sleep at least this time, default 0 */ 629void ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval); /* sleep at least this time, default 0 */
620 630
621/* advanced stuff for threading etc. support, see docs */ 631/* advanced stuff for threading etc. support, see docs */
622void ev_set_userdata (EV_P_ void *data); 632void ev_set_userdata (EV_P_ void *data);
623void *ev_userdata (EV_P); 633void *ev_userdata (EV_PDEF);
624void ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)); 634void ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P));
625void ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P)); 635void ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P));
626 636
627unsigned int ev_pending_count (EV_P); /* number of pending events, if any */ 637unsigned int ev_pending_count (EV_PDEF); /* number of pending events, if any */
628void ev_invoke_pending (EV_P); /* invoke all pending watchers */ 638void ev_invoke_pending (EV_PDEF); /* invoke all pending watchers */
629 639
630/* 640/*
631 * stop/start the timer handling. 641 * stop/start the timer handling.
632 */ 642 */
633void ev_suspend (EV_P); 643void ev_suspend (EV_PDEF);
634void ev_resume (EV_P); 644void ev_resume (EV_PDEF);
635#endif 645#endif
636 646
637#endif 647#endif
638 648
639/* these may evaluate ev multiple times, and the other arguments at most once */ 649/* these may evaluate ev multiple times, and the other arguments at most once */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines