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

Comparing libev/ev.h (file contents):
Revision 1.93 by root, Fri Feb 1 13:08:54 2008 UTC vs.
Revision 1.99 by root, Wed Apr 16 01:37:14 2008 UTC

98struct ev_loop; 98struct ev_loop;
99# define EV_P struct ev_loop *loop 99# define EV_P struct ev_loop *loop
100# define EV_P_ EV_P, 100# define EV_P_ EV_P,
101# define EV_A loop 101# define EV_A loop
102# define EV_A_ EV_A, 102# define EV_A_ EV_A,
103# define EV_DEFAULT_UC ev_default_loop_uc ()
104# define EV_DEFAULT_UC_ EV_DEFAULT_UC,
103# define EV_DEFAULT ev_default_loop (0) 105# define EV_DEFAULT ev_default_loop (0)
104# define EV_DEFAULT_ EV_DEFAULT, 106# define EV_DEFAULT_ EV_DEFAULT,
105#else 107#else
106# define EV_P void 108# define EV_P void
107# define EV_P_ 109# define EV_P_
108# define EV_A 110# define EV_A
109# define EV_A_ 111# define EV_A_
110# define EV_DEFAULT 112# define EV_DEFAULT
111# define EV_DEFAULT_ 113# define EV_DEFAULT_
112 114# define EV_DEFAULT_UC
115# define EV_DEFAULT_UC_
113# undef EV_EMBED_ENABLE 116# undef EV_EMBED_ENABLE
114#endif 117#endif
115 118
119#if __STDC_VERSION__ >= 199901L || __GNUC__ >= 3
120# define EV_INLINE static inline
121#else
122# define EV_INLINE static
123#endif
124
125/*****************************************************************************/
126
116/* eventmask, revents, events... */ 127/* eventmask, revents, events... */
117#define EV_UNDEF -1L /* guaranteed to be invalid */ 128#define EV_UNDEF -1 /* guaranteed to be invalid */
118#define EV_NONE 0x00L /* no events */ 129#define EV_NONE 0x00 /* no events */
119#define EV_READ 0x01L /* ev_io detected read will not block */ 130#define EV_READ 0x01 /* ev_io detected read will not block */
120#define EV_WRITE 0x02L /* ev_io detected write will not block */ 131#define EV_WRITE 0x02 /* ev_io detected write will not block */
121#define EV_IOFDSET 0x80L /* internal use only */ 132#define EV_IOFDSET 0x80 /* internal use only */
122#define EV_TIMEOUT 0x00000100L /* timer timed out */ 133#define EV_TIMEOUT 0x00000100 /* timer timed out */
123#define EV_PERIODIC 0x00000200L /* periodic timer timed out */ 134#define EV_PERIODIC 0x00000200 /* periodic timer timed out */
124#define EV_SIGNAL 0x00000400L /* signal was received */ 135#define EV_SIGNAL 0x00000400 /* signal was received */
125#define EV_CHILD 0x00000800L /* child/pid had status change */ 136#define EV_CHILD 0x00000800 /* child/pid had status change */
126#define EV_STAT 0x00001000L /* stat data changed */ 137#define EV_STAT 0x00001000 /* stat data changed */
127#define EV_IDLE 0x00002000L /* event loop is idling */ 138#define EV_IDLE 0x00002000 /* event loop is idling */
128#define EV_PREPARE 0x00004000L /* event loop about to poll */ 139#define EV_PREPARE 0x00004000 /* event loop about to poll */
129#define EV_CHECK 0x00008000L /* event loop finished poll */ 140#define EV_CHECK 0x00008000 /* event loop finished poll */
130#define EV_EMBED 0x00010000L /* embedded event loop needs sweep */ 141#define EV_EMBED 0x00010000 /* embedded event loop needs sweep */
131#define EV_FORK 0x00020000L /* event loop resumed in child */ 142#define EV_FORK 0x00020000 /* event loop resumed in child */
132#define EV_ASYNC 0x00040000L /* async intra-loop signal */ 143#define EV_ASYNC 0x00040000 /* async intra-loop signal */
133#define EV_ERROR 0x80000000L /* sent when an error occurs */ 144#define EV_ERROR 0x80000000 /* sent when an error occurs */
134 145
135/* can be used to add custom fields to all watchers, while losing binary compatibility */ 146/* can be used to add custom fields to all watchers, while losing binary compatibility */
136#ifndef EV_COMMON 147#ifndef EV_COMMON
137# define EV_COMMON void *data; 148# define EV_COMMON void *data;
138#endif 149#endif
324{ 335{
325 EV_WATCHER (ev_async) 336 EV_WATCHER (ev_async)
326 337
327 EV_ATOMIC_T sent; /* private */ 338 EV_ATOMIC_T sent; /* private */
328} ev_async; 339} ev_async;
340
341# define ev_async_pending(w) ((w)->sent + 0)
329#endif 342#endif
330 343
331/* the presence of this union forces similar struct layout */ 344/* the presence of this union forces similar struct layout */
332union ev_any_watcher 345union ev_any_watcher
333{ 346{
351 struct ev_fork fork; 364 struct ev_fork fork;
352#endif 365#endif
353#if EV_EMBED_ENABLE 366#if EV_EMBED_ENABLE
354 struct ev_embed embed; 367 struct ev_embed embed;
355#endif 368#endif
356#if EV_ASYND_ENABLE 369#if EV_ASYNC_ENABLE
357 struct ev_async async; 370 struct ev_async async;
358#endif 371#endif
359}; 372};
360 373
361/* bits for ev_default_loop and ev_loop_new */ 374/* bits for ev_default_loop and ev_loop_new */
362/* the default */ 375/* the default */
363#define EVFLAG_AUTO 0x00000000UL /* not quite a mask */ 376#define EVFLAG_AUTO 0x00000000U /* not quite a mask */
364/* flag bits */ 377/* flag bits */
365#define EVFLAG_NOENV 0x01000000UL /* do NOT consult environment */ 378#define EVFLAG_NOENV 0x01000000U /* do NOT consult environment */
366#define EVFLAG_FORKCHECK 0x02000000UL /* check for a fork in each iteration */ 379#define EVFLAG_FORKCHECK 0x02000000U /* check for a fork in each iteration */
367/* method bits to be ored together */ 380/* method bits to be ored together */
368#define EVBACKEND_SELECT 0x00000001UL /* about anywhere */ 381#define EVBACKEND_SELECT 0x00000001U /* about anywhere */
369#define EVBACKEND_POLL 0x00000002UL /* !win */ 382#define EVBACKEND_POLL 0x00000002U /* !win */
370#define EVBACKEND_EPOLL 0x00000004UL /* linux */ 383#define EVBACKEND_EPOLL 0x00000004U /* linux */
371#define EVBACKEND_KQUEUE 0x00000008UL /* bsd */ 384#define EVBACKEND_KQUEUE 0x00000008U /* bsd */
372#define EVBACKEND_DEVPOLL 0x00000010UL /* solaris 8 */ /* NYI */ 385#define EVBACKEND_DEVPOLL 0x00000010U /* solaris 8 */ /* NYI */
373#define EVBACKEND_PORT 0x00000020UL /* solaris 10 */ 386#define EVBACKEND_PORT 0x00000020U /* solaris 10 */
374 387
375#if EV_PROTOTYPES 388#if EV_PROTOTYPES
376int ev_version_major (void); 389int ev_version_major (void);
377int ev_version_minor (void); 390int ev_version_minor (void);
378 391
396 * (such as failed select, poll, epoll_wait) 409 * (such as failed select, poll, epoll_wait)
397 */ 410 */
398void ev_set_syserr_cb (void (*cb)(const char *msg)); 411void ev_set_syserr_cb (void (*cb)(const char *msg));
399 412
400# if EV_MULTIPLICITY 413# if EV_MULTIPLICITY
414EV_INLINE struct ev_loop *
415ev_default_loop_uc (void)
416{
417 extern struct ev_loop *ev_default_loop_ptr;
418
419 return ev_default_loop_ptr;
420}
421
401/* the default loop is the only one that handles signals and child watchers */ 422/* the default loop is the only one that handles signals and child watchers */
402/* you can call this as often as you like */ 423/* you can call this as often as you like */
403static struct ev_loop * 424EV_INLINE struct ev_loop *
404ev_default_loop (unsigned int flags) 425ev_default_loop (unsigned int flags)
405{ 426{
406 extern struct ev_loop *ev_default_loop_ptr; 427 struct ev_loop *loop = ev_default_loop_uc ();
428
429 if (!loop)
430 {
407 extern struct ev_loop *ev_default_loop_init (unsigned int flags); 431 extern struct ev_loop *ev_default_loop_init (unsigned int flags);
408 432
409 if (!ev_default_loop_ptr)
410 ev_default_loop_init (flags); 433 loop = ev_default_loop_init (flags);
434 }
411 435
412 return ev_default_loop_ptr; 436 return loop;
413} 437}
414 438
415/* create and destroy alternative loops that don't handle signals */ 439/* create and destroy alternative loops that don't handle signals */
416struct ev_loop *ev_loop_new (unsigned int flags); 440struct ev_loop *ev_loop_new (unsigned int flags);
417void ev_loop_destroy (EV_P); 441void ev_loop_destroy (EV_P);
421 445
422# else 446# else
423 447
424int ev_default_loop (unsigned int flags); /* returns true when successful */ 448int ev_default_loop (unsigned int flags); /* returns true when successful */
425 449
426static ev_tstamp 450EV_INLINE ev_tstamp
427ev_now (void) 451ev_now (void)
428{ 452{
429 extern ev_tstamp ev_rt_now; 453 extern ev_tstamp ev_rt_now;
430 454
431 return ev_rt_now; 455 return ev_rt_now;
432} 456}
433# endif 457# endif
458
459EV_INLINE int
460ev_is_default_loop (EV_P)
461{
462#if EV_MULTIPLICITY
463 extern struct ev_loop *ev_default_loop_ptr;
464
465 return !!(EV_A == ev_default_loop_ptr);
466#else
467 return 1;
468#endif
469}
434 470
435void ev_default_destroy (void); /* destroy the default loop */ 471void ev_default_destroy (void); /* destroy the default loop */
436/* this needs to be called after fork, to duplicate the default loop */ 472/* this needs to be called after fork, to duplicate the default loop */
437/* if you create alternative loops you have to call ev_loop_fork on them */ 473/* if you create alternative loops you have to call ev_loop_fork on them */
438/* you can call it in either the parent or the child */ 474/* you can call it in either the parent or the child */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines