--- libev/ev.h 2010/10/22 05:57:55 1.143 +++ libev/ev.h 2010/10/24 14:44:40 1.148 @@ -41,9 +41,13 @@ #define EV_H_ #ifdef __cplusplus -extern "C" { +# define EV_CPP(x) x +#else +# define EV_CPP(x) #endif +EV_CPP(extern "C" {) + /*****************************************************************************/ /* pre-4.0 compatibility */ @@ -147,23 +151,17 @@ # include #endif -#ifdef __cplusplus -# define EV_DEFARG(x) = x -#else -# define EV_DEFARG(x) -#endif - /* support multiple event loops? */ #if EV_MULTIPLICITY struct ev_loop; -# define EV_P struct ev_loop *loop -# define EV_P_ EV_P, -# define EV_A loop -# define EV_A_ EV_A, -# define EV_DEFAULT_UC ev_default_loop_uc () -# define EV_DEFAULT_UC_ EV_DEFAULT_UC, -# define EV_DEFAULT ev_default_loop (0) -# define EV_DEFAULT_ EV_DEFAULT, +# define EV_P struct ev_loop *loop /* a loop as sole parameter in a declaration */ +# define EV_P_ EV_P, /* a loop as first of multiple parameters */ +# define EV_A loop /* a loop as sole argument to a function call */ +# define EV_A_ EV_A, /* a loop as first of multiple arguments */ +# define EV_DEFAULT_UC ev_default_loop_uc () /* the default loop, if initialised, as sole arg */ +# define EV_DEFAULT_UC_ EV_DEFAULT_UC, /* the default loop as first of multiple arguments */ +# define EV_DEFAULT ev_default_loop (0) /* the default loop as sole arg */ +# define EV_DEFAULT_ EV_DEFAULT, /* the default loop as first of multiple arguments */ #else # define EV_P void # define EV_P_ @@ -176,12 +174,14 @@ # undef EV_EMBED_ENABLE #endif +/* EV_INLINE is used for functions in header files */ #if __STDC_VERSION__ >= 199901L || __GNUC__ >= 3 # define EV_INLINE static inline #else # define EV_INLINE static #endif +/* EV_PROTOTYPES can be sued to switch of prototype declarations */ #ifndef EV_PROTOTYPES # define EV_PROTOTYPES 1 #endif @@ -510,6 +510,11 @@ void ev_set_syserr_cb (void (*cb)(const char *msg)); #if EV_MULTIPLICITY + +/* the default loop is the only one that handles signals and child watchers */ +/* you can call this as often as you like */ +struct ev_loop *ev_default_loop (unsigned int flags EV_CPP (= 0)); + EV_INLINE struct ev_loop * ev_default_loop_uc (void) { @@ -518,25 +523,14 @@ return ev_default_loop_ptr; } -/* the default loop is the only one that handles signals and child watchers */ -/* you can call this as often as you like */ -EV_INLINE struct ev_loop * -ev_default_loop (unsigned int flags EV_DEFARG (0)) +EV_INLINE int +ev_is_default_loop (EV_P) { - struct ev_loop *loop = ev_default_loop_uc (); - - if (!loop) - { - extern struct ev_loop *ev_default_loop_init (unsigned int flags); - - loop = ev_default_loop_init (flags); - } - - return loop; + return EV_A == ev_default_loop_uc (); } /* create and destroy alternative loops that don't handle signals */ -struct ev_loop *ev_loop_new (unsigned int flags EV_DEFARG (0)); +struct ev_loop *ev_loop_new (unsigned int flags EV_CPP (= 0)); void ev_loop_destroy (EV_P); void ev_loop_fork (EV_P); @@ -544,7 +538,7 @@ #else -int ev_default_loop (unsigned int flags EV_DEFARG (0)); /* returns true when successful */ +int ev_default_loop (unsigned int flags EV_CPP (= 0)); /* returns true when successful */ EV_INLINE ev_tstamp ev_now (void) @@ -553,20 +547,16 @@ return ev_rt_now; } -#endif /* multiplicity */ +/* looks weird, but ev_is_default_loop (EV_A) still works if this exists */ EV_INLINE int -ev_is_default_loop (EV_P) +ev_is_default_loop (void) { -#if EV_MULTIPLICITY - extern struct ev_loop *ev_default_loop_ptr; - - return !!(EV_A == ev_default_loop_ptr); -#else return 1; -#endif } +#endif /* multiplicity */ + void ev_default_destroy (void); /* destroy the default loop */ /* this needs to be called after fork, to duplicate the default loop */ /* if you create alternative loops you have to call ev_loop_fork on them */ @@ -601,8 +591,8 @@ }; #if EV_PROTOTYPES -void ev_run (EV_P_ int flags EV_DEFARG (0)); -void ev_break (EV_P_ int how EV_DEFARG (EVBREAK_ONE)); /* break out of the loop */ +void ev_run (EV_P_ int flags EV_CPP (= 0)); +void ev_break (EV_P_ int how EV_CPP (= EVBREAK_ONE)); /* break out of the loop */ /* * ref/unref can be used to add or remove a refcount on the mainloop. every watcher @@ -800,9 +790,7 @@ #endif -#ifdef __cplusplus -} -#endif +EV_CPP(}) #endif