… | |
… | |
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 | |
44 | extern "C" { |
49 | EV_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 |
158 | struct ev_loop; |
156 | struct 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 | /*****************************************************************************/ |
… | |
… | |
519 | } |
519 | } |
520 | |
520 | |
521 | /* the default loop is the only one that handles signals and child watchers */ |
521 | /* the default loop is the only one that handles signals and child watchers */ |
522 | /* you can call this as often as you like */ |
522 | /* you can call this as often as you like */ |
523 | EV_INLINE struct ev_loop * |
523 | EV_INLINE struct ev_loop * |
524 | ev_default_loop (unsigned int flags EV_DEFARG (0)) |
524 | ev_default_loop (unsigned int flags EV_CPP (= 0)) |
525 | { |
525 | { |
526 | struct ev_loop *loop = ev_default_loop_uc (); |
526 | struct ev_loop *loop = ev_default_loop_uc (); |
527 | |
527 | |
528 | if (!loop) |
528 | if (!loop) |
529 | { |
529 | { |
… | |
… | |
534 | |
534 | |
535 | return loop; |
535 | return loop; |
536 | } |
536 | } |
537 | |
537 | |
538 | /* create and destroy alternative loops that don't handle signals */ |
538 | /* create and destroy alternative loops that don't handle signals */ |
539 | struct ev_loop *ev_loop_new (unsigned int flags EV_DEFARG (0)); |
539 | struct ev_loop *ev_loop_new (unsigned int flags EV_CPP (= 0)); |
540 | void ev_loop_destroy (EV_P); |
540 | void ev_loop_destroy (EV_P); |
541 | void ev_loop_fork (EV_P); |
541 | void ev_loop_fork (EV_P); |
542 | |
542 | |
543 | ev_tstamp ev_now (EV_P); /* time w.r.t. timers and the eventloop, updated after each poll */ |
543 | ev_tstamp ev_now (EV_P); /* time w.r.t. timers and the eventloop, updated after each poll */ |
544 | |
544 | |
545 | #else |
545 | #else |
546 | |
546 | |
547 | int ev_default_loop (unsigned int flags EV_DEFARG (0)); /* returns true when successful */ |
547 | int ev_default_loop (unsigned int flags EV_CPP (= 0)); /* returns true when successful */ |
548 | |
548 | |
549 | EV_INLINE ev_tstamp |
549 | EV_INLINE ev_tstamp |
550 | ev_now (void) |
550 | ev_now (void) |
551 | { |
551 | { |
552 | extern ev_tstamp ev_rt_now; |
552 | extern ev_tstamp ev_rt_now; |
… | |
… | |
599 | EVBREAK_ONE = 1, /* unloop once */ |
599 | EVBREAK_ONE = 1, /* unloop once */ |
600 | EVBREAK_ALL = 2 /* unloop all loops */ |
600 | EVBREAK_ALL = 2 /* unloop all loops */ |
601 | }; |
601 | }; |
602 | |
602 | |
603 | #if EV_PROTOTYPES |
603 | #if EV_PROTOTYPES |
604 | void ev_run (EV_P_ int flags EV_DEFARG (0)); |
604 | void ev_run (EV_P_ int flags EV_CPP (= 0)); |
605 | void ev_break (EV_P_ int how EV_DEFARG (EVBREAK_ONE)); /* break out of the loop */ |
605 | void ev_break (EV_P_ int how EV_CPP (= EVBREAK_ONE)); /* break out of the loop */ |
606 | |
606 | |
607 | /* |
607 | /* |
608 | * ref/unref can be used to add or remove a refcount on the mainloop. every watcher |
608 | * 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 |
609 | * 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. |
610 | * should not keep ev_loop from running, unref() after starting, and ref() before stopping. |
… | |
… | |
798 | typedef struct ev_loop ev_loop; |
798 | typedef struct ev_loop ev_loop; |
799 | #endif |
799 | #endif |
800 | |
800 | |
801 | #endif |
801 | #endif |
802 | |
802 | |
803 | #ifdef __cplusplus |
803 | EV_CPP(}) |
804 | } |
|
|
805 | #endif |
|
|
806 | |
804 | |
807 | #endif |
805 | #endif |
808 | |
806 | |