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

Comparing libev/ev.h (file contents):
Revision 1.145 by root, Fri Oct 22 06:09:26 2010 UTC vs.
Revision 1.149 by root, Sun Oct 24 17:58:41 2010 UTC

39 39
40#ifndef EV_H_ 40#ifndef EV_H_
41#define EV_H_ 41#define EV_H_
42 42
43#ifdef __cplusplus 43#ifdef __cplusplus
44# define EV_CPP(x) x
45#else
46# define EV_CPP(x)
47#endif
48
44extern "C" { 49EV_CPP(extern "C" {)
45#endif
46 50
47/*****************************************************************************/ 51/*****************************************************************************/
48 52
49/* pre-4.0 compatibility */ 53/* pre-4.0 compatibility */
50#ifndef EV_COMPAT3 54#ifndef EV_COMPAT3
145# include <sys/types.h> 149# include <sys/types.h>
146# endif 150# endif
147# include <sys/stat.h> 151# include <sys/stat.h>
148#endif 152#endif
149 153
150#ifdef __cplusplus
151# define EV_DEFARG(x) = x
152#else
153# define EV_DEFARG(x)
154#endif
155
156/* support multiple event loops? */ 154/* support multiple event loops? */
157#if EV_MULTIPLICITY 155#if EV_MULTIPLICITY
158struct ev_loop; 156struct ev_loop;
159# define EV_P struct ev_loop *loop /* a loop as sole parameter in a declaration */ 157# define EV_P struct ev_loop *loop /* a loop as sole parameter in a declaration */
160# define EV_P_ EV_P, /* a loop as first of multiple parameters */ 158# define EV_P_ EV_P, /* a loop as first of multiple parameters */
161# define EV_A loop /* a loop as sole argument to a function call */ 159# define EV_A loop /* a loop as sole argument to a function call */
162# define EV_A_ EV_A, /* a loop as first of multiple arguments */ 160# define EV_A_ EV_A, /* a loop as first of multiple arguments */
163# define EV_DEFAULT_UC ev_default_loop_uc () /* the default loop, if initialised, as sole arg */ 161# define EV_DEFAULT_UC ev_default_loop_uc_ () /* the default loop, if initialised, as sole arg */
164# define EV_DEFAULT_UC_ EV_DEFAULT_UC, /* the default loop as first of multiple arguments */ 162# define EV_DEFAULT_UC_ EV_DEFAULT_UC, /* the default loop as first of multiple arguments */
165# define EV_DEFAULT ev_default_loop (0) /* the default loop as sole arg */ 163# define EV_DEFAULT ev_default_loop (0) /* the default loop as sole arg */
166# define EV_DEFAULT_ EV_DEFAULT, /* the default loop as first of multiple arguments */ 164# 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++ */
168#else 165#else
169# define EV_P void 166# define EV_P void
170# define EV_P_ 167# define EV_P_
171# define EV_A 168# define EV_A
172# define EV_A_ 169# define EV_A_
173# define EV_DEFAULT 170# define EV_DEFAULT
174# define EV_DEFAULT_ 171# define EV_DEFAULT_
175# define EV_DEFAULT_UC 172# define EV_DEFAULT_UC
176# define EV_DEFAULT_UC_ 173# define EV_DEFAULT_UC_
177# define EV_PDEF EV_P
178# undef EV_EMBED_ENABLE 174# undef EV_EMBED_ENABLE
179#endif 175#endif
180 176
177/* EV_INLINE is used for functions in header files */
181#if __STDC_VERSION__ >= 199901L || __GNUC__ >= 3 178#if __STDC_VERSION__ >= 199901L || __GNUC__ >= 3
182# define EV_INLINE static inline 179# define EV_INLINE static inline
183#else 180#else
184# define EV_INLINE static 181# define EV_INLINE static
185#endif 182#endif
186 183
184/* EV_PROTOTYPES can be sued to switch of prototype declarations */
187#ifndef EV_PROTOTYPES 185#ifndef EV_PROTOTYPES
188# define EV_PROTOTYPES 1 186# define EV_PROTOTYPES 1
189#endif 187#endif
190 188
191/*****************************************************************************/ 189/*****************************************************************************/
510 * (such as failed select, poll, epoll_wait) 508 * (such as failed select, poll, epoll_wait)
511 */ 509 */
512void ev_set_syserr_cb (void (*cb)(const char *msg)); 510void ev_set_syserr_cb (void (*cb)(const char *msg));
513 511
514#if EV_MULTIPLICITY 512#if EV_MULTIPLICITY
513
514/* the default loop is the only one that handles signals and child watchers */
515/* you can call this as often as you like */
516struct ev_loop *ev_default_loop (unsigned int flags EV_CPP (= 0));
517
515EV_INLINE struct ev_loop * 518EV_INLINE struct ev_loop *
516ev_default_loop_uc (void) 519ev_default_loop_uc_ (void)
517{ 520{
518 extern struct ev_loop *ev_default_loop_ptr; 521 extern struct ev_loop *ev_default_loop_ptr;
519 522
520 return ev_default_loop_ptr; 523 return ev_default_loop_ptr;
521} 524}
522 525
523/* the default loop is the only one that handles signals and child watchers */ 526EV_INLINE int
524/* you can call this as often as you like */ 527ev_is_default_loop (EV_P)
525EV_INLINE struct ev_loop *
526ev_default_loop (unsigned int flags EV_DEFARG (0))
527{ 528{
528 struct ev_loop *loop = ev_default_loop_uc (); 529 return EV_A == EV_DEFAULT_UC;
529
530 if (!loop)
531 {
532 extern struct ev_loop *ev_default_loop_init (unsigned int flags);
533
534 loop = ev_default_loop_init (flags);
535 }
536
537 return loop;
538} 530}
539 531
540/* create and destroy alternative loops that don't handle signals */ 532/* create and destroy alternative loops that don't handle signals */
541struct ev_loop *ev_loop_new (unsigned int flags EV_DEFARG (0)); 533struct ev_loop *ev_loop_new (unsigned int flags EV_CPP (= 0));
534/* destroy event loops, also works for the default loop */
542void ev_loop_destroy (EV_PDEF); 535void ev_loop_destroy (EV_P);
543void ev_loop_fork (EV_PDEF);
544 536
545ev_tstamp ev_now (EV_PDEF); /* time w.r.t. timers and the eventloop, updated after each poll */ 537ev_tstamp ev_now (EV_P); /* time w.r.t. timers and the eventloop, updated after each poll */
546 538
547#else 539#else
548 540
549int ev_default_loop (unsigned int flags EV_DEFARG (0)); /* returns true when successful */ 541int ev_default_loop (unsigned int flags EV_CPP (= 0)); /* returns true when successful */
550 542
551EV_INLINE ev_tstamp 543EV_INLINE ev_tstamp
552ev_now (void) 544ev_now (void)
553{ 545{
554 extern ev_tstamp ev_rt_now; 546 extern ev_tstamp ev_rt_now;
555 547
556 return ev_rt_now; 548 return ev_rt_now;
557} 549}
550
551/* looks weird, but ev_is_default_loop (EV_A) still works if this exists */
552EV_INLINE int
553ev_is_default_loop (void)
554{
555 return 1;
556}
557
558#endif /* multiplicity */ 558#endif /* multiplicity */
559 559
560EV_INLINE int
561ev_is_default_loop (EV_PDEF)
562{
563#if EV_MULTIPLICITY
564 extern struct ev_loop *ev_default_loop_ptr;
565
566 return !!(EV_A == ev_default_loop_ptr);
567#else
568 return 1;
569#endif
570}
571
572void ev_default_destroy (void); /* destroy the default loop */
573/* this needs to be called after fork, to duplicate the default loop */ 560/* this needs to be called after fork, to duplicate the loop */
574/* if you create alternative loops you have to call ev_loop_fork on them */ 561/* when you want to re-use it in the child */
575/* you can call it in either the parent or the child */ 562/* you can call it in either the parent or the child */
576/* you can actually call it at any time, anywhere :) */ 563/* you can actually call it at any time, anywhere :) */
577void ev_default_fork (void); 564void ev_loop_fork (EV_P);
578 565
579unsigned int ev_backend (EV_PDEF); /* backend in use by loop */ 566unsigned int ev_backend (EV_P); /* backend in use by loop */
580 567
581void ev_now_update (EV_PDEF); /* update event loop time */ 568void ev_now_update (EV_P); /* update event loop time */
582 569
583#if EV_WALK_ENABLE 570#if EV_WALK_ENABLE
584/* walk (almost) all watchers in the loop of a given type, invoking the */ 571/* walk (almost) all watchers in the loop of a given type, invoking the */
585/* callback on every such watcher. The callback might stop the watcher, */ 572/* callback on every such watcher. The callback might stop the watcher, */
586/* but do nothing else with the loop */ 573/* but do nothing else with the loop */
601 EVBREAK_ONE = 1, /* unloop once */ 588 EVBREAK_ONE = 1, /* unloop once */
602 EVBREAK_ALL = 2 /* unloop all loops */ 589 EVBREAK_ALL = 2 /* unloop all loops */
603}; 590};
604 591
605#if EV_PROTOTYPES 592#if EV_PROTOTYPES
606void ev_run (EV_P_ int flags EV_DEFARG (0)); 593void ev_run (EV_P_ int flags EV_CPP (= 0));
607void ev_break (EV_P_ int how EV_DEFARG (EVBREAK_ONE)); /* break out of the loop */ 594void ev_break (EV_P_ int how EV_CPP (= EVBREAK_ONE)); /* break out of the loop */
608 595
609/* 596/*
610 * ref/unref can be used to add or remove a refcount on the mainloop. every watcher 597 * ref/unref can be used to add or remove a refcount on the mainloop. every watcher
611 * keeps one reference. if you have a long-running watcher you never unregister that 598 * keeps one reference. if you have a long-running watcher you never unregister that
612 * should not keep ev_loop from running, unref() after starting, and ref() before stopping. 599 * should not keep ev_loop from running, unref() after starting, and ref() before stopping.
613 */ 600 */
614void ev_ref (EV_PDEF); 601void ev_ref (EV_P);
615void ev_unref (EV_PDEF); 602void ev_unref (EV_P);
616 603
617/* 604/*
618 * convenience function, wait for a single event, without registering an event watcher 605 * convenience function, wait for a single event, without registering an event watcher
619 * if timeout is < 0, do wait indefinitely 606 * if timeout is < 0, do wait indefinitely
620 */ 607 */
621void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg); 608void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg);
622 609
623# if EV_FEATURE_API 610# if EV_FEATURE_API
624unsigned int ev_iteration (EV_PDEF); /* number of loop iterations */ 611unsigned int ev_iteration (EV_P); /* number of loop iterations */
625unsigned int ev_depth (EV_PDEF); /* #ev_loop enters - #ev_loop leaves */ 612unsigned int ev_depth (EV_P); /* #ev_loop enters - #ev_loop leaves */
626void ev_verify (EV_PDEF); /* abort if loop data corrupted */ 613void ev_verify (EV_P); /* abort if loop data corrupted */
627 614
628void ev_set_io_collect_interval (EV_P_ ev_tstamp interval); /* sleep at least this time, default 0 */ 615void ev_set_io_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 */ 616void ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval); /* sleep at least this time, default 0 */
630 617
631/* advanced stuff for threading etc. support, see docs */ 618/* advanced stuff for threading etc. support, see docs */
632void ev_set_userdata (EV_P_ void *data); 619void ev_set_userdata (EV_P_ void *data);
633void *ev_userdata (EV_PDEF); 620void *ev_userdata (EV_P);
634void ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)); 621void ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P));
635void ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P)); 622void ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P));
636 623
637unsigned int ev_pending_count (EV_PDEF); /* number of pending events, if any */ 624unsigned int ev_pending_count (EV_P); /* number of pending events, if any */
638void ev_invoke_pending (EV_PDEF); /* invoke all pending watchers */ 625void ev_invoke_pending (EV_P); /* invoke all pending watchers */
639 626
640/* 627/*
641 * stop/start the timer handling. 628 * stop/start the timer handling.
642 */ 629 */
643void ev_suspend (EV_PDEF); 630void ev_suspend (EV_P);
644void ev_resume (EV_PDEF); 631void ev_resume (EV_P);
645#endif 632#endif
646 633
647#endif 634#endif
648 635
649/* these may evaluate ev multiple times, and the other arguments at most once */ 636/* these may evaluate ev multiple times, and the other arguments at most once */
788 #define EVUNLOOP_ONE EVBREAK_ONE 775 #define EVUNLOOP_ONE EVBREAK_ONE
789 #define EVUNLOOP_ALL EVBREAK_ALL 776 #define EVUNLOOP_ALL EVBREAK_ALL
790 #if EV_PROTOTYPES 777 #if EV_PROTOTYPES
791 EV_INLINE void ev_loop (EV_P_ int flags) { ev_run (EV_A_ flags); } 778 EV_INLINE void ev_loop (EV_P_ int flags) { ev_run (EV_A_ flags); }
792 EV_INLINE void ev_unloop (EV_P_ int how ) { ev_break (EV_A_ how ); } 779 EV_INLINE void ev_unloop (EV_P_ int how ) { ev_break (EV_A_ how ); }
780 EV_INLINE void ev_default_destroy (void) { ev_loop_destroy (EV_DEFAULT); }
781 EV_INLINE void ev_default_fork (void) { ev_loop_fork (EV_DEFAULT); }
793 #if EV_FEATURE_API 782 #if EV_FEATURE_API
794 EV_INLINE void ev_loop_count (EV_P) { ev_iteration (EV_A); } 783 EV_INLINE void ev_loop_count (EV_P) { ev_iteration (EV_A); }
795 EV_INLINE void ev_loop_depth (EV_P) { ev_depth (EV_A); } 784 EV_INLINE void ev_loop_depth (EV_P) { ev_depth (EV_A); }
796 EV_INLINE void ev_loop_verify (EV_P) { ev_verify (EV_A); } 785 EV_INLINE void ev_loop_verify (EV_P) { ev_verify (EV_A); }
797 #endif 786 #endif
800 typedef struct ev_loop ev_loop; 789 typedef struct ev_loop ev_loop;
801#endif 790#endif
802 791
803#endif 792#endif
804 793
805#ifdef __cplusplus 794EV_CPP(})
806}
807#endif
808 795
809#endif 796#endif
810 797

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines