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.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 157# define EV_P struct ev_loop *loop /* a loop as sole parameter in a declaration */
160# define EV_P_ EV_P, 158# define EV_P_ EV_P, /* a loop as first of multiple parameters */
161# define EV_A loop 159# define EV_A loop /* a loop as sole argument to a function call */
162# define EV_A_ EV_A, 160# define EV_A_ EV_A, /* a loop as first of multiple arguments */
163# define EV_DEFAULT_UC ev_default_loop_uc () 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, 162# define EV_DEFAULT_UC_ EV_DEFAULT_UC, /* the default loop as first of multiple arguments */
165# define EV_DEFAULT ev_default_loop (0) 163# define EV_DEFAULT ev_default_loop (0) /* the default loop as sole arg */
166# define EV_DEFAULT_ EV_DEFAULT, 164# define EV_DEFAULT_ EV_DEFAULT, /* the default loop as first of multiple arguments */
167#else 165#else
168# define EV_P void 166# define EV_P void
169# define EV_P_ 167# define EV_P_
170# define EV_A 168# define EV_A
171# define EV_A_ 169# define EV_A_
174# define EV_DEFAULT_UC 172# define EV_DEFAULT_UC
175# define EV_DEFAULT_UC_ 173# define EV_DEFAULT_UC_
176# undef EV_EMBED_ENABLE 174# undef EV_EMBED_ENABLE
177#endif 175#endif
178 176
177/* EV_INLINE is used for functions in header files */
179#if __STDC_VERSION__ >= 199901L || __GNUC__ >= 3 178#if __STDC_VERSION__ >= 199901L || __GNUC__ >= 3
180# define EV_INLINE static inline 179# define EV_INLINE static inline
181#else 180#else
182# define EV_INLINE static 181# define EV_INLINE static
183#endif 182#endif
184 183
184/* EV_PROTOTYPES can be sued to switch of prototype declarations */
185#ifndef EV_PROTOTYPES 185#ifndef EV_PROTOTYPES
186# define EV_PROTOTYPES 1 186# define EV_PROTOTYPES 1
187#endif 187#endif
188 188
189/*****************************************************************************/ 189/*****************************************************************************/
508 * (such as failed select, poll, epoll_wait) 508 * (such as failed select, poll, epoll_wait)
509 */ 509 */
510void ev_set_syserr_cb (void (*cb)(const char *msg)); 510void ev_set_syserr_cb (void (*cb)(const char *msg));
511 511
512#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
513EV_INLINE struct ev_loop * 518EV_INLINE struct ev_loop *
514ev_default_loop_uc (void) 519ev_default_loop_uc_ (void)
515{ 520{
516 extern struct ev_loop *ev_default_loop_ptr; 521 extern struct ev_loop *ev_default_loop_ptr;
517 522
518 return ev_default_loop_ptr; 523 return ev_default_loop_ptr;
519} 524}
520 525
521/* the default loop is the only one that handles signals and child watchers */ 526EV_INLINE int
522/* you can call this as often as you like */ 527ev_is_default_loop (EV_P)
523EV_INLINE struct ev_loop *
524ev_default_loop (unsigned int flags EV_DEFARG (0))
525{ 528{
526 struct ev_loop *loop = ev_default_loop_uc (); 529 return EV_A == EV_DEFAULT_UC;
527
528 if (!loop)
529 {
530 extern struct ev_loop *ev_default_loop_init (unsigned int flags);
531
532 loop = ev_default_loop_init (flags);
533 }
534
535 return loop;
536} 530}
537 531
538/* create and destroy alternative loops that don't handle signals */ 532/* create and destroy alternative loops that don't handle signals */
539struct 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 */
540void ev_loop_destroy (EV_P); 535void ev_loop_destroy (EV_P);
541void ev_loop_fork (EV_P);
542 536
543ev_tstamp ev_now (EV_P); /* 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 */
544 538
545#else 539#else
546 540
547int 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 */
548 542
549EV_INLINE ev_tstamp 543EV_INLINE ev_tstamp
550ev_now (void) 544ev_now (void)
551{ 545{
552 extern ev_tstamp ev_rt_now; 546 extern ev_tstamp ev_rt_now;
553 547
554 return ev_rt_now; 548 return ev_rt_now;
555} 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
556#endif /* multiplicity */ 558#endif /* multiplicity */
557 559
558EV_INLINE int
559ev_is_default_loop (EV_P)
560{
561#if EV_MULTIPLICITY
562 extern struct ev_loop *ev_default_loop_ptr;
563
564 return !!(EV_A == ev_default_loop_ptr);
565#else
566 return 1;
567#endif
568}
569
570void ev_default_destroy (void); /* destroy the default loop */
571/* this needs to be called after fork, to duplicate the default loop */ 560/* this needs to be called after fork, to duplicate the loop */
572/* 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 */
573/* you can call it in either the parent or the child */ 562/* you can call it in either the parent or the child */
574/* you can actually call it at any time, anywhere :) */ 563/* you can actually call it at any time, anywhere :) */
575void ev_default_fork (void); 564void ev_loop_fork (EV_P);
576 565
577unsigned int ev_backend (EV_P); /* backend in use by loop */ 566unsigned int ev_backend (EV_P); /* backend in use by loop */
578 567
579void ev_now_update (EV_P); /* update event loop time */ 568void ev_now_update (EV_P); /* update event loop time */
580 569
599 EVBREAK_ONE = 1, /* unloop once */ 588 EVBREAK_ONE = 1, /* unloop once */
600 EVBREAK_ALL = 2 /* unloop all loops */ 589 EVBREAK_ALL = 2 /* unloop all loops */
601}; 590};
602 591
603#if EV_PROTOTYPES 592#if EV_PROTOTYPES
604void ev_run (EV_P_ int flags EV_DEFARG (0)); 593void ev_run (EV_P_ int flags EV_CPP (= 0));
605void 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 */
606 595
607/* 596/*
608 * 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
609 * 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
610 * 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.
786 #define EVUNLOOP_ONE EVBREAK_ONE 775 #define EVUNLOOP_ONE EVBREAK_ONE
787 #define EVUNLOOP_ALL EVBREAK_ALL 776 #define EVUNLOOP_ALL EVBREAK_ALL
788 #if EV_PROTOTYPES 777 #if EV_PROTOTYPES
789 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); }
790 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); }
791 #if EV_FEATURE_API 782 #if EV_FEATURE_API
792 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); }
793 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); }
794 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); }
795 #endif 786 #endif
798 typedef struct ev_loop ev_loop; 789 typedef struct ev_loop ev_loop;
799#endif 790#endif
800 791
801#endif 792#endif
802 793
803#ifdef __cplusplus 794EV_CPP(})
804}
805#endif
806 795
807#endif 796#endif
808 797

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines