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.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
148#endif 152#endif
149 153
150/* support multiple event loops? */ 154/* support multiple event loops? */
151#if EV_MULTIPLICITY 155#if EV_MULTIPLICITY
152struct ev_loop; 156struct ev_loop;
153# define EV_P struct ev_loop *loop 157# define EV_P struct ev_loop *loop /* a loop as sole parameter in a declaration */
154# define EV_P_ EV_P, 158# define EV_P_ EV_P, /* a loop as first of multiple parameters */
155# define EV_A loop 159# define EV_A loop /* a loop as sole argument to a function call */
156# define EV_A_ EV_A, 160# define EV_A_ EV_A, /* a loop as first of multiple arguments */
157# 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 */
158# define EV_DEFAULT_UC_ EV_DEFAULT_UC, 162# define EV_DEFAULT_UC_ EV_DEFAULT_UC, /* the default loop as first of multiple arguments */
159# define EV_DEFAULT ev_default_loop (0) 163# define EV_DEFAULT ev_default_loop (0) /* the default loop as sole arg */
160# define EV_DEFAULT_ EV_DEFAULT, 164# define EV_DEFAULT_ EV_DEFAULT, /* the default loop as first of multiple arguments */
161#else 165#else
162# define EV_P void 166# define EV_P void
163# define EV_P_ 167# define EV_P_
164# define EV_A 168# define EV_A
165# define EV_A_ 169# define EV_A_
168# define EV_DEFAULT_UC 172# define EV_DEFAULT_UC
169# define EV_DEFAULT_UC_ 173# define EV_DEFAULT_UC_
170# undef EV_EMBED_ENABLE 174# undef EV_EMBED_ENABLE
171#endif 175#endif
172 176
177/* EV_INLINE is used for functions in header files */
173#if __STDC_VERSION__ >= 199901L || __GNUC__ >= 3 178#if __STDC_VERSION__ >= 199901L || __GNUC__ >= 3
174# define EV_INLINE static inline 179# define EV_INLINE static inline
175#else 180#else
176# define EV_INLINE static 181# define EV_INLINE static
177#endif 182#endif
178 183
184/* EV_PROTOTYPES can be sued to switch of prototype declarations */
179#ifndef EV_PROTOTYPES 185#ifndef EV_PROTOTYPES
180# define EV_PROTOTYPES 1 186# define EV_PROTOTYPES 1
181#endif 187#endif
182 188
183/*****************************************************************************/ 189/*****************************************************************************/
192 EV_READ = 0x01, /* ev_io detected read will not block */ 198 EV_READ = 0x01, /* ev_io detected read will not block */
193 EV_WRITE = 0x02, /* ev_io detected write will not block */ 199 EV_WRITE = 0x02, /* ev_io detected write will not block */
194 EV__IOFDSET = 0x80, /* internal use only */ 200 EV__IOFDSET = 0x80, /* internal use only */
195 EV_IO = EV_READ, /* alias for type-detection */ 201 EV_IO = EV_READ, /* alias for type-detection */
196 EV_TIMER = 0x00000100, /* timer timed out */ 202 EV_TIMER = 0x00000100, /* timer timed out */
203#if EV_COMPAT3
197 EV_TIMEOUT = EV_TIMER, /* pre 4.0 API compatibility */ 204 EV_TIMEOUT = EV_TIMER, /* pre 4.0 API compatibility */
205#endif
198 EV_PERIODIC = 0x00000200, /* periodic timer timed out */ 206 EV_PERIODIC = 0x00000200, /* periodic timer timed out */
199 EV_SIGNAL = 0x00000400, /* signal was received */ 207 EV_SIGNAL = 0x00000400, /* signal was received */
200 EV_CHILD = 0x00000800, /* child/pid had status change */ 208 EV_CHILD = 0x00000800, /* child/pid had status change */
201 EV_STAT = 0x00001000, /* stat data changed */ 209 EV_STAT = 0x00001000, /* stat data changed */
202 EV_IDLE = 0x00002000, /* event loop is idling */ 210 EV_IDLE = 0x00002000, /* event loop is idling */
500 * (such as failed select, poll, epoll_wait) 508 * (such as failed select, poll, epoll_wait)
501 */ 509 */
502void ev_set_syserr_cb (void (*cb)(const char *msg)); 510void ev_set_syserr_cb (void (*cb)(const char *msg));
503 511
504#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
505EV_INLINE struct ev_loop * 518EV_INLINE struct ev_loop *
506ev_default_loop_uc (void) 519ev_default_loop_uc_ (void)
507{ 520{
508 extern struct ev_loop *ev_default_loop_ptr; 521 extern struct ev_loop *ev_default_loop_ptr;
509 522
510 return ev_default_loop_ptr; 523 return ev_default_loop_ptr;
511} 524}
512 525
513/* the default loop is the only one that handles signals and child watchers */ 526EV_INLINE int
514/* you can call this as often as you like */ 527ev_is_default_loop (EV_P)
515EV_INLINE struct ev_loop *
516ev_default_loop (unsigned int flags)
517{ 528{
518 struct ev_loop *loop = ev_default_loop_uc (); 529 return EV_A == EV_DEFAULT_UC;
519
520 if (!loop)
521 {
522 extern struct ev_loop *ev_default_loop_init (unsigned int flags);
523
524 loop = ev_default_loop_init (flags);
525 }
526
527 return loop;
528} 530}
529 531
530/* create and destroy alternative loops that don't handle signals */ 532/* create and destroy alternative loops that don't handle signals */
531struct ev_loop *ev_loop_new (unsigned int flags); 533struct ev_loop *ev_loop_new (unsigned int flags EV_CPP (= 0));
534/* destroy event loops, also works for the default loop */
532void ev_loop_destroy (EV_P); 535void ev_loop_destroy (EV_P);
533void ev_loop_fork (EV_P);
534 536
535ev_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 */
536 538
537#else 539#else
538 540
539int ev_default_loop (unsigned int flags); /* returns true when successful */ 541int ev_default_loop (unsigned int flags EV_CPP (= 0)); /* returns true when successful */
540 542
541EV_INLINE ev_tstamp 543EV_INLINE ev_tstamp
542ev_now (void) 544ev_now (void)
543{ 545{
544 extern ev_tstamp ev_rt_now; 546 extern ev_tstamp ev_rt_now;
545 547
546 return ev_rt_now; 548 return ev_rt_now;
547} 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
548#endif /* multiplicity */ 558#endif /* multiplicity */
549 559
550EV_INLINE int
551ev_is_default_loop (EV_P)
552{
553#if EV_MULTIPLICITY
554 extern struct ev_loop *ev_default_loop_ptr;
555
556 return !!(EV_A == ev_default_loop_ptr);
557#else
558 return 1;
559#endif
560}
561
562void ev_default_destroy (void); /* destroy the default loop */
563/* this needs to be called after fork, to duplicate the default loop */ 560/* this needs to be called after fork, to duplicate the loop */
564/* 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 */
565/* you can call it in either the parent or the child */ 562/* you can call it in either the parent or the child */
566/* you can actually call it at any time, anywhere :) */ 563/* you can actually call it at any time, anywhere :) */
567void ev_default_fork (void); 564void ev_loop_fork (EV_P);
568 565
569unsigned int ev_backend (EV_P); /* backend in use by loop */ 566unsigned int ev_backend (EV_P); /* backend in use by loop */
570 567
571void ev_now_update (EV_P); /* update event loop time */ 568void ev_now_update (EV_P); /* update event loop time */
572 569
591 EVBREAK_ONE = 1, /* unloop once */ 588 EVBREAK_ONE = 1, /* unloop once */
592 EVBREAK_ALL = 2 /* unloop all loops */ 589 EVBREAK_ALL = 2 /* unloop all loops */
593}; 590};
594 591
595#if EV_PROTOTYPES 592#if EV_PROTOTYPES
596void ev_run (EV_P_ int flags); 593void ev_run (EV_P_ int flags EV_CPP (= 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 */ 594void ev_break (EV_P_ int how EV_CPP (= EVBREAK_ONE)); /* break out of the loop */
598 595
599/* 596/*
600 * 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
601 * 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
602 * 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.
778 #define EVUNLOOP_ONE EVBREAK_ONE 775 #define EVUNLOOP_ONE EVBREAK_ONE
779 #define EVUNLOOP_ALL EVBREAK_ALL 776 #define EVUNLOOP_ALL EVBREAK_ALL
780 #if EV_PROTOTYPES 777 #if EV_PROTOTYPES
781 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); }
782 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); }
783 #if EV_FEATURE_API 782 #if EV_FEATURE_API
784 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); }
785 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); }
786 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); }
787 #endif 786 #endif
790 typedef struct ev_loop ev_loop; 789 typedef struct ev_loop ev_loop;
791#endif 790#endif
792 791
793#endif 792#endif
794 793
795#ifdef __cplusplus 794EV_CPP(})
796}
797#endif
798 795
799#endif 796#endif
800 797

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines