From: root Date: Sat, 3 Nov 2007 22:31:11 +0000 (+0000) Subject: initial support for multiplicity X-Git-Tag: rel-0_5~28 X-Git-Url: https://git.llucax.com/software/libev.git/commitdiff_plain/60a7a3c0029fc0a57c6548e3175af0a362a37a52?ds=sidebyside initial support for multiplicity --- diff --git a/ev.c b/ev.c index 1cafd9b..8c05776 100644 --- a/ev.c +++ b/ev.c @@ -115,44 +115,32 @@ typedef struct ev_watcher *W; typedef struct ev_watcher_list *WL; typedef struct ev_watcher_time *WT; -static ev_tstamp now_floor, mn_now, diff; /* monotonic clock */ -static ev_tstamp rt_now; -static int method; - -static int have_monotonic; /* runtime */ - -static ev_tstamp method_fudge; /* stupid epoll-returns-early bug */ -static void (*method_modify)(EV_P_ int fd, int oev, int nev); -static void (*method_poll)(EV_P_ ev_tstamp timeout); - -static int activecnt; /* number of active events */ - -#if EV_USE_SELECT -static unsigned char *vec_ri, *vec_ro, *vec_wi, *vec_wo; -static int vec_max; -#endif - -#if EV_USEV_POLL -static struct pollfd *polls; -static int pollmax, pollcnt; -static int *pollidxs; /* maps fds into structure indices */ -static int pollidxmax; -#endif +/*****************************************************************************/ -#if EV_USE_EPOLL -static int epoll_fd = -1; +typedef struct +{ + struct ev_watcher_list *head; + unsigned char events; + unsigned char reify; +} ANFD; -static struct epoll_event *events; -static int eventmax; -#endif +typedef struct +{ + W w; + int events; +} ANPENDING; -#if EV_USE_KQUEUE -static int kqueue_fd; -static struct kevent *kqueue_changes; -static int kqueue_changemax, kqueue_changecnt; -static struct kevent *kqueue_events; -static int kqueue_eventmax; +#ifdef EV_MULTIPLICITY +struct ev_loop +{ +# define VAR(name,decl) decl +# include "ev_vars.h" +}; +#else +# define VAR(name,decl) static decl +# include "ev_vars.h" #endif +#undef VAR /*****************************************************************************/ @@ -210,16 +198,6 @@ ev_now (EV_P) /*****************************************************************************/ -typedef struct -{ - struct ev_watcher_list *head; - unsigned char events; - unsigned char reify; -} ANFD; - -static ANFD *anfds; -static int anfdmax; - static void anfds_init (ANFD *base, int count) { @@ -233,15 +211,6 @@ anfds_init (ANFD *base, int count) } } -typedef struct -{ - W w; - int events; -} ANPENDING; - -static ANPENDING *pendings [NUMPRI]; -static int pendingmax [NUMPRI], pendingcnt [NUMPRI]; - static void event (EV_P_ W w, int events) { @@ -283,9 +252,6 @@ fd_event (EV_P_ int fd, int events) /*****************************************************************************/ -static int *fdchanges; -static int fdchangemax, fdchangecnt; - static void fd_reify (EV_P) { @@ -368,12 +334,6 @@ fd_enomem (EV_P) /*****************************************************************************/ -static struct ev_timer **timers; -static int timermax, timercnt; - -static struct ev_periodic **periodics; -static int periodicmax, periodiccnt; - static void upheap (WT *timers, int k) { @@ -428,7 +388,6 @@ static int signalmax; static int sigpipe [2]; static sig_atomic_t volatile gotsig; -static struct ev_io sigev; static void signals_init (ANSIG *base, int count) @@ -494,20 +453,6 @@ siginit (EV_P) /*****************************************************************************/ -static struct ev_idle **idles; -static int idlemax, idlecnt; - -static struct ev_prepare **prepares; -static int preparemax, preparecnt; - -static struct ev_check **checks; -static int checkmax, checkcnt; - -/*****************************************************************************/ - -static struct ev_child *childs [PID_HASHSIZE]; -static struct ev_signal childev; - #ifndef WIN32 #ifndef WCONTINUED @@ -594,6 +539,10 @@ ev_method (EV_P) int ev_init (EV_P_ int methods) { +#ifdef EV_MULTIPLICITY + memset (loop, 0, sizeof (struct ev_loop)); +#endif + if (!method) { #if EV_USE_MONOTONIC diff --git a/ev_vars.h b/ev_vars.h new file mode 100644 index 0000000..1c7505e --- /dev/null +++ b/ev_vars.h @@ -0,0 +1,86 @@ +#define VARx(type,name) VAR(name, type name) + +VARx(ev_tstamp, now_floor); /* last time we refreshed rt_time */ +VARx(ev_tstamp, mn_now); /* monotonic clock "now" */ +VARx(ev_tstamp, rt_now); +VARx(ev_tstamp, diff); /* difference realtime - monotonic time */ +VARx(int, method); + +VARx(int, have_monotonic); /* runtime */ + +VARx(ev_tstamp, method_fudge); /* assumed typical timer resolution */ +VAR (method_modify, void (*method_modify)(EV_P_ int fd, int oev, int nev)); +VAR (method_poll , void (*method_poll)(EV_P_ ev_tstamp timeout)); + +VARx(int, activecnt); /* number of active events */ + +#if EV_USE_SELECT +VARx(unsigned char *, vec_ri); +VARx(unsigned char *, vec_ro); +VARx(unsigned char *, vec_wi); +VARx(unsigned char *, vec_wo); +VARx(int, vec_max); +#endif + +#if EV_USEV_POLL +VARx(struct pollfd *, polls); +VARx(int, pollmax); +VARx(int, pollcnt); +VARx(int *, pollidxs); /* maps fds into structure indices */ +VARx(int, pollidxmax); +#endif + +#if EV_USE_EPOLL +VARx(int, epoll_fd); + +VARx(struct epoll_event *, events); +VARx(int, eventmax); +#endif + +#if EV_USE_KQUEUE +VARx(int, kqueue_fd); +VARx(struct kevent *, kqueue_changes); +VARx(int, kqueue_changemax); +VARx(int, kqueue_changecnt); +VARx(struct kevent *, kqueue_events); +VARx(int, kqueue_eventmax); +#endif + +VARx(ANFD *, anfds); +VARx(int, anfdmax); + +VAR (pendings, ANPENDING *pendings [NUMPRI]); +VAR (pendingmax, int pendingmax [NUMPRI]); +VAR (pendingcnt, int pendingcnt [NUMPRI]); + +VARx(int *, fdchanges); +VARx(int, fdchangemax); +VARx(int, fdchangecnt); + +VARx(struct ev_timer **, timers); +VARx(int, timermax); +VARx(int, timercnt); + +VARx(struct ev_periodic **, periodics); +VARx(int, periodicmax); +VARx(int, periodiccnt); + +VARx(struct ev_idle **, idles); +VARx(int, idlemax); +VARx(int, idlecnt); + +VARx(struct ev_prepare **, prepares); +VARx(int, preparemax); +VARx(int, preparecnt); + +VARx(struct ev_check **, checks); +VARx(int, checkmax); +VARx(int, checkcnt); + +VAR (childs, struct ev_child *childs [PID_HASHSIZE]); +VARx(struct ev_signal, childev); + +VARx(struct ev_io, sigev); + +#undef VARx +