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

Comparing libev/ev.c (file contents):
Revision 1.22 by root, Wed Oct 31 19:07:43 2007 UTC vs.
Revision 1.26 by root, Wed Oct 31 21:50:15 2007 UTC

113} 113}
114 114
115#define array_needsize(base,cur,cnt,init) \ 115#define array_needsize(base,cur,cnt,init) \
116 if ((cnt) > cur) \ 116 if ((cnt) > cur) \
117 { \ 117 { \
118 int newcnt = cur ? cur << 1 : 16; \ 118 int newcnt = cur; \
119 do \
120 { \
121 newcnt = (newcnt << 1) | 4 & ~3; \
122 } \
123 while ((cnt) > newcnt); \
124 \
119 base = realloc (base, sizeof (*base) * (newcnt)); \ 125 base = realloc (base, sizeof (*base) * (newcnt)); \
120 init (base + cur, newcnt - cur); \ 126 init (base + cur, newcnt - cur); \
121 cur = newcnt; \ 127 cur = newcnt; \
122 } 128 }
123 129
191 event (events [i], type); 197 event (events [i], type);
192} 198}
193 199
194/* called on EBADF to verify fds */ 200/* called on EBADF to verify fds */
195static void 201static void
196fd_recheck () 202fd_recheck (void)
197{ 203{
198 int fd; 204 int fd;
199 205
200 for (fd = 0; fd < anfdmax; ++fd) 206 for (fd = 0; fd < anfdmax; ++fd)
201 if (anfds [fd].wev) 207 if (anfds [fd].wev)
202 if (fcntl (fd, F_GETFD) == -1 && errno == EBADF) 208 if (fcntl (fd, F_GETFD) == -1 && errno == EBADF)
203 while (anfds [fd].head) 209 while (anfds [fd].head)
210 {
211 event ((W)anfds [fd].head, EV_ERROR);
204 evio_stop (anfds [fd].head); 212 evio_stop (anfds [fd].head);
213 }
205} 214}
206 215
207/*****************************************************************************/ 216/*****************************************************************************/
208 217
209static struct ev_timer **timers; 218static struct ev_timer **timers;
366#endif 375#endif
367#if HAVE_SELECT 376#if HAVE_SELECT
368# include "ev_select.c" 377# include "ev_select.c"
369#endif 378#endif
370 379
380int
381ev_version_major (void)
382{
383 return EV_VERSION_MAJOR;
384}
385
386int
387ev_version_minor (void)
388{
389 return EV_VERSION_MINOR;
390}
391
371int ev_init (int flags) 392int ev_init (int flags)
372{ 393{
394 if (!ev_method)
395 {
373#if HAVE_MONOTONIC 396#if HAVE_MONOTONIC
374 { 397 {
375 struct timespec ts; 398 struct timespec ts;
376 if (!clock_gettime (CLOCK_MONOTONIC, &ts)) 399 if (!clock_gettime (CLOCK_MONOTONIC, &ts))
377 have_monotonic = 1; 400 have_monotonic = 1;
378 } 401 }
379#endif 402#endif
380 403
381 ev_now = ev_time (); 404 ev_now = ev_time ();
382 now = get_clock (); 405 now = get_clock ();
383 diff = ev_now - now; 406 diff = ev_now - now;
384 407
385 if (pipe (sigpipe)) 408 if (pipe (sigpipe))
386 return 0; 409 return 0;
387 410
388 ev_method = EVMETHOD_NONE; 411 ev_method = EVMETHOD_NONE;
389#if HAVE_EPOLL 412#if HAVE_EPOLL
390 if (ev_method == EVMETHOD_NONE) epoll_init (flags); 413 if (ev_method == EVMETHOD_NONE) epoll_init (flags);
391#endif 414#endif
392#if HAVE_SELECT 415#if HAVE_SELECT
393 if (ev_method == EVMETHOD_NONE) select_init (flags); 416 if (ev_method == EVMETHOD_NONE) select_init (flags);
394#endif 417#endif
395 418
396 if (ev_method) 419 if (ev_method)
397 { 420 {
398 evw_init (&sigev, sigcb); 421 evw_init (&sigev, sigcb);
399 siginit (); 422 siginit ();
400 423
401 evsignal_init (&childev, childcb, SIGCHLD); 424 evsignal_init (&childev, childcb, SIGCHLD);
402 evsignal_start (&childev); 425 evsignal_start (&childev);
426 }
403 } 427 }
404 428
405 return ev_method; 429 return ev_method;
406} 430}
407 431
408/*****************************************************************************/ 432/*****************************************************************************/
409 433
434void
410void ev_prefork (void) 435ev_prefork (void)
411{ 436{
412 /* nop */ 437 /* nop */
413} 438}
414 439
440void
415void ev_postfork_parent (void) 441ev_postfork_parent (void)
416{ 442{
417 /* nop */ 443 /* nop */
418} 444}
419 445
446void
420void ev_postfork_child (void) 447ev_postfork_child (void)
421{ 448{
422#if HAVE_EPOLL 449#if HAVE_EPOLL
423 if (ev_method == EVMETHOD_EPOLL) 450 if (ev_method == EVMETHOD_EPOLL)
424 epoll_postfork_child (); 451 epoll_postfork_child ();
425#endif 452#endif
458 485
459 fdchangecnt = 0; 486 fdchangecnt = 0;
460} 487}
461 488
462static void 489static void
463call_pending () 490call_pending (void)
464{ 491{
465 while (pendingcnt) 492 while (pendingcnt)
466 { 493 {
467 ANPENDING *p = pendings + --pendingcnt; 494 ANPENDING *p = pendings + --pendingcnt;
468 495
473 } 500 }
474 } 501 }
475} 502}
476 503
477static void 504static void
478timers_reify () 505timers_reify (void)
479{ 506{
480 while (timercnt && timers [0]->at <= now) 507 while (timercnt && timers [0]->at <= now)
481 { 508 {
482 struct ev_timer *w = timers [0]; 509 struct ev_timer *w = timers [0];
483 510
494 evtimer_stop (w); /* nonrepeating: stop timer */ 521 evtimer_stop (w); /* nonrepeating: stop timer */
495 } 522 }
496} 523}
497 524
498static void 525static void
499periodics_reify () 526periodics_reify (void)
500{ 527{
501 while (periodiccnt && periodics [0]->at <= ev_now) 528 while (periodiccnt && periodics [0]->at <= ev_now)
502 { 529 {
503 struct ev_periodic *w = periodics [0]; 530 struct ev_periodic *w = periodics [0];
504 531
540 } 567 }
541 } 568 }
542} 569}
543 570
544static void 571static void
545time_update () 572time_update (void)
546{ 573{
547 int i; 574 int i;
548 575
549 ev_now = ev_time (); 576 ev_now = ev_time ();
550 577
584int ev_loop_done; 611int ev_loop_done;
585 612
586void ev_loop (int flags) 613void ev_loop (int flags)
587{ 614{
588 double block; 615 double block;
589 ev_loop_done = flags & EVLOOP_ONESHOT ? 1 : 0; 616 ev_loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) ? 1 : 0;
590 617
591 do 618 do
592 { 619 {
593 /* queue check watchers (and execute them) */ 620 /* queue check watchers (and execute them) */
594 if (preparecnt) 621 if (preparecnt)
713 wlist_add ((WL *)&anfds[fd].head, (WL)w); 740 wlist_add ((WL *)&anfds[fd].head, (WL)w);
714 741
715 ++fdchangecnt; 742 ++fdchangecnt;
716 array_needsize (fdchanges, fdchangemax, fdchangecnt, ); 743 array_needsize (fdchanges, fdchangemax, fdchangecnt, );
717 fdchanges [fdchangecnt - 1] = fd; 744 fdchanges [fdchangecnt - 1] = fd;
745
746 if (w->fd == 9)
747 printf ("start %p:%x\n", w, w->events);//D
718} 748}
719 749
720void 750void
721evio_stop (struct ev_io *w) 751evio_stop (struct ev_io *w)
722{ 752{
753 if (w->fd == 9)
754 printf ("stop %p:%x\n", w, w->events);//D
723 ev_clear ((W)w); 755 ev_clear ((W)w);
724 if (!ev_is_active (w)) 756 if (!ev_is_active (w))
725 return; 757 return;
726 758
727 wlist_del ((WL *)&anfds[w->fd].head, (WL)w); 759 wlist_del ((WL *)&anfds[w->fd].head, (WL)w);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines