… | |
… | |
98 | struct ev_loop; |
98 | struct 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 |
… | |
… | |
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; |
329 | |
340 | |
330 | # define ev_async_pending(w) (((w)->sent + 0) |
341 | # define ev_async_pending(w) ((w)->sent + 0) |
331 | #endif |
342 | #endif |
332 | |
343 | |
333 | /* the presence of this union forces similar struct layout */ |
344 | /* the presence of this union forces similar struct layout */ |
334 | union ev_any_watcher |
345 | union ev_any_watcher |
335 | { |
346 | { |
… | |
… | |
353 | struct ev_fork fork; |
364 | struct ev_fork fork; |
354 | #endif |
365 | #endif |
355 | #if EV_EMBED_ENABLE |
366 | #if EV_EMBED_ENABLE |
356 | struct ev_embed embed; |
367 | struct ev_embed embed; |
357 | #endif |
368 | #endif |
358 | #if EV_ASYND_ENABLE |
369 | #if EV_ASYNC_ENABLE |
359 | struct ev_async async; |
370 | struct ev_async async; |
360 | #endif |
371 | #endif |
361 | }; |
372 | }; |
362 | |
373 | |
363 | /* bits for ev_default_loop and ev_loop_new */ |
374 | /* bits for ev_default_loop and ev_loop_new */ |
364 | /* the default */ |
375 | /* the default */ |
365 | #define EVFLAG_AUTO 0x00000000UL /* not quite a mask */ |
376 | #define EVFLAG_AUTO 0x00000000U /* not quite a mask */ |
366 | /* flag bits */ |
377 | /* flag bits */ |
367 | #define EVFLAG_NOENV 0x01000000UL /* do NOT consult environment */ |
378 | #define EVFLAG_NOENV 0x01000000U /* do NOT consult environment */ |
368 | #define EVFLAG_FORKCHECK 0x02000000UL /* check for a fork in each iteration */ |
379 | #define EVFLAG_FORKCHECK 0x02000000U /* check for a fork in each iteration */ |
369 | /* method bits to be ored together */ |
380 | /* method bits to be ored together */ |
370 | #define EVBACKEND_SELECT 0x00000001UL /* about anywhere */ |
381 | #define EVBACKEND_SELECT 0x00000001U /* about anywhere */ |
371 | #define EVBACKEND_POLL 0x00000002UL /* !win */ |
382 | #define EVBACKEND_POLL 0x00000002U /* !win */ |
372 | #define EVBACKEND_EPOLL 0x00000004UL /* linux */ |
383 | #define EVBACKEND_EPOLL 0x00000004U /* linux */ |
373 | #define EVBACKEND_KQUEUE 0x00000008UL /* bsd */ |
384 | #define EVBACKEND_KQUEUE 0x00000008U /* bsd */ |
374 | #define EVBACKEND_DEVPOLL 0x00000010UL /* solaris 8 */ /* NYI */ |
385 | #define EVBACKEND_DEVPOLL 0x00000010U /* solaris 8 */ /* NYI */ |
375 | #define EVBACKEND_PORT 0x00000020UL /* solaris 10 */ |
386 | #define EVBACKEND_PORT 0x00000020U /* solaris 10 */ |
376 | |
387 | |
377 | #if EV_PROTOTYPES |
388 | #if EV_PROTOTYPES |
378 | int ev_version_major (void); |
389 | int ev_version_major (void); |
379 | int ev_version_minor (void); |
390 | int ev_version_minor (void); |
380 | |
391 | |
… | |
… | |
398 | * (such as failed select, poll, epoll_wait) |
409 | * (such as failed select, poll, epoll_wait) |
399 | */ |
410 | */ |
400 | void ev_set_syserr_cb (void (*cb)(const char *msg)); |
411 | void ev_set_syserr_cb (void (*cb)(const char *msg)); |
401 | |
412 | |
402 | # if EV_MULTIPLICITY |
413 | # if EV_MULTIPLICITY |
|
|
414 | EV_INLINE struct ev_loop * |
|
|
415 | ev_default_loop_uc (void) |
|
|
416 | { |
|
|
417 | extern struct ev_loop *ev_default_loop_ptr; |
|
|
418 | |
|
|
419 | return ev_default_loop_ptr; |
|
|
420 | } |
|
|
421 | |
403 | /* 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 */ |
404 | /* you can call this as often as you like */ |
423 | /* you can call this as often as you like */ |
405 | static struct ev_loop * |
424 | EV_INLINE struct ev_loop * |
406 | ev_default_loop (unsigned int flags) |
425 | ev_default_loop (unsigned int flags) |
407 | { |
426 | { |
408 | extern struct ev_loop *ev_default_loop_ptr; |
427 | struct ev_loop *loop = ev_default_loop_uc (); |
|
|
428 | |
|
|
429 | if (!loop) |
|
|
430 | { |
409 | extern struct ev_loop *ev_default_loop_init (unsigned int flags); |
431 | extern struct ev_loop *ev_default_loop_init (unsigned int flags); |
410 | |
432 | |
411 | if (!ev_default_loop_ptr) |
|
|
412 | ev_default_loop_init (flags); |
433 | loop = ev_default_loop_init (flags); |
|
|
434 | } |
413 | |
435 | |
414 | return ev_default_loop_ptr; |
436 | return loop; |
415 | } |
437 | } |
416 | |
438 | |
417 | /* create and destroy alternative loops that don't handle signals */ |
439 | /* create and destroy alternative loops that don't handle signals */ |
418 | struct ev_loop *ev_loop_new (unsigned int flags); |
440 | struct ev_loop *ev_loop_new (unsigned int flags); |
419 | void ev_loop_destroy (EV_P); |
441 | void ev_loop_destroy (EV_P); |
… | |
… | |
423 | |
445 | |
424 | # else |
446 | # else |
425 | |
447 | |
426 | int ev_default_loop (unsigned int flags); /* returns true when successful */ |
448 | int ev_default_loop (unsigned int flags); /* returns true when successful */ |
427 | |
449 | |
428 | static ev_tstamp |
450 | EV_INLINE ev_tstamp |
429 | ev_now (void) |
451 | ev_now (void) |
430 | { |
452 | { |
431 | extern ev_tstamp ev_rt_now; |
453 | extern ev_tstamp ev_rt_now; |
432 | |
454 | |
433 | return ev_rt_now; |
455 | return ev_rt_now; |
434 | } |
456 | } |
435 | # endif |
457 | # endif |
436 | |
458 | |
437 | static int |
459 | EV_INLINE int |
438 | ev_is_default_loop (EV_P) |
460 | ev_is_default_loop (EV_P) |
439 | { |
461 | { |
440 | #if EV_MULTIPLICITY |
462 | #if EV_MULTIPLICITY |
441 | extern struct ev_loop *ev_default_loop_ptr; |
463 | extern struct ev_loop *ev_default_loop_ptr; |
442 | |
464 | |