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

Comparing libev/ev.c (file contents):
Revision 1.52 by root, Sat Nov 3 22:10:39 2007 UTC vs.
Revision 1.53 by root, Sat Nov 3 22:31:11 2007 UTC

113 113
114typedef struct ev_watcher *W; 114typedef struct ev_watcher *W;
115typedef struct ev_watcher_list *WL; 115typedef struct ev_watcher_list *WL;
116typedef struct ev_watcher_time *WT; 116typedef struct ev_watcher_time *WT;
117 117
118static ev_tstamp now_floor, mn_now, diff; /* monotonic clock */ 118/*****************************************************************************/
119static ev_tstamp rt_now;
120static int method;
121 119
122static int have_monotonic; /* runtime */ 120typedef struct
121{
122 struct ev_watcher_list *head;
123 unsigned char events;
124 unsigned char reify;
125} ANFD;
123 126
124static ev_tstamp method_fudge; /* stupid epoll-returns-early bug */ 127typedef struct
125static void (*method_modify)(EV_P_ int fd, int oev, int nev); 128{
126static void (*method_poll)(EV_P_ ev_tstamp timeout); 129 W w;
130 int events;
131} ANPENDING;
127 132
128static int activecnt; /* number of active events */ 133#ifdef EV_MULTIPLICITY
129 134struct ev_loop
130#if EV_USE_SELECT 135{
131static unsigned char *vec_ri, *vec_ro, *vec_wi, *vec_wo; 136# define VAR(name,decl) decl
132static int vec_max; 137# include "ev_vars.h"
138};
139#else
140# define VAR(name,decl) static decl
141# include "ev_vars.h"
133#endif 142#endif
134 143#undef VAR
135#if EV_USEV_POLL
136static struct pollfd *polls;
137static int pollmax, pollcnt;
138static int *pollidxs; /* maps fds into structure indices */
139static int pollidxmax;
140#endif
141
142#if EV_USE_EPOLL
143static int epoll_fd = -1;
144
145static struct epoll_event *events;
146static int eventmax;
147#endif
148
149#if EV_USE_KQUEUE
150static int kqueue_fd;
151static struct kevent *kqueue_changes;
152static int kqueue_changemax, kqueue_changecnt;
153static struct kevent *kqueue_events;
154static int kqueue_eventmax;
155#endif
156 144
157/*****************************************************************************/ 145/*****************************************************************************/
158 146
159inline ev_tstamp 147inline ev_tstamp
160ev_time (void) 148ev_time (void)
208 cur = newcnt; \ 196 cur = newcnt; \
209 } 197 }
210 198
211/*****************************************************************************/ 199/*****************************************************************************/
212 200
213typedef struct
214{
215 struct ev_watcher_list *head;
216 unsigned char events;
217 unsigned char reify;
218} ANFD;
219
220static ANFD *anfds;
221static int anfdmax;
222
223static void 201static void
224anfds_init (ANFD *base, int count) 202anfds_init (ANFD *base, int count)
225{ 203{
226 while (count--) 204 while (count--)
227 { 205 {
230 base->reify = 0; 208 base->reify = 0;
231 209
232 ++base; 210 ++base;
233 } 211 }
234} 212}
235
236typedef struct
237{
238 W w;
239 int events;
240} ANPENDING;
241
242static ANPENDING *pendings [NUMPRI];
243static int pendingmax [NUMPRI], pendingcnt [NUMPRI];
244 213
245static void 214static void
246event (EV_P_ W w, int events) 215event (EV_P_ W w, int events)
247{ 216{
248 if (w->pending) 217 if (w->pending)
280 event (EV_A_ (W)w, ev); 249 event (EV_A_ (W)w, ev);
281 } 250 }
282} 251}
283 252
284/*****************************************************************************/ 253/*****************************************************************************/
285
286static int *fdchanges;
287static int fdchangemax, fdchangecnt;
288 254
289static void 255static void
290fd_reify (EV_P) 256fd_reify (EV_P)
291{ 257{
292 int i; 258 int i;
366 } 332 }
367} 333}
368 334
369/*****************************************************************************/ 335/*****************************************************************************/
370 336
371static struct ev_timer **timers;
372static int timermax, timercnt;
373
374static struct ev_periodic **periodics;
375static int periodicmax, periodiccnt;
376
377static void 337static void
378upheap (WT *timers, int k) 338upheap (WT *timers, int k)
379{ 339{
380 WT w = timers [k]; 340 WT w = timers [k];
381 341
426static ANSIG *signals; 386static ANSIG *signals;
427static int signalmax; 387static int signalmax;
428 388
429static int sigpipe [2]; 389static int sigpipe [2];
430static sig_atomic_t volatile gotsig; 390static sig_atomic_t volatile gotsig;
431static struct ev_io sigev;
432 391
433static void 392static void
434signals_init (ANSIG *base, int count) 393signals_init (ANSIG *base, int count)
435{ 394{
436 while (count--) 395 while (count--)
491 ev_io_start (&sigev); 450 ev_io_start (&sigev);
492 ev_unref (EV_A); /* child watcher should not keep loop alive */ 451 ev_unref (EV_A); /* child watcher should not keep loop alive */
493} 452}
494 453
495/*****************************************************************************/ 454/*****************************************************************************/
496
497static struct ev_idle **idles;
498static int idlemax, idlecnt;
499
500static struct ev_prepare **prepares;
501static int preparemax, preparecnt;
502
503static struct ev_check **checks;
504static int checkmax, checkcnt;
505
506/*****************************************************************************/
507
508static struct ev_child *childs [PID_HASHSIZE];
509static struct ev_signal childev;
510 455
511#ifndef WIN32 456#ifndef WIN32
512 457
513#ifndef WCONTINUED 458#ifndef WCONTINUED
514# define WCONTINUED 0 459# define WCONTINUED 0
592} 537}
593 538
594int 539int
595ev_init (EV_P_ int methods) 540ev_init (EV_P_ int methods)
596{ 541{
542#ifdef EV_MULTIPLICITY
543 memset (loop, 0, sizeof (struct ev_loop));
544#endif
545
597 if (!method) 546 if (!method)
598 { 547 {
599#if EV_USE_MONOTONIC 548#if EV_USE_MONOTONIC
600 { 549 {
601 struct timespec ts; 550 struct timespec ts;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines