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

Comparing libev/ev.c (file contents):
Revision 1.9 by root, Wed Oct 31 07:24:17 2007 UTC vs.
Revision 1.13 by root, Wed Oct 31 10:50:05 2007 UTC

9#include <assert.h> 9#include <assert.h>
10#include <errno.h> 10#include <errno.h>
11#include <sys/time.h> 11#include <sys/time.h>
12#include <time.h> 12#include <time.h>
13 13
14#ifdef CLOCK_MONOTONIC
15# define HAVE_MONOTONIC 1
16#endif
17
18#define HAVE_REALTIME 1
19#define HAVE_EPOLL 1 14#define HAVE_EPOLL 1
15
16#ifndef HAVE_MONOTONIC
17# ifdef CLOCK_MONOTONIC
18# define HAVE_MONOTONIC 1
19# endif
20#endif
21
22#ifndef HAVE_SELECT
20#define HAVE_SELECT 1 23# define HAVE_SELECT 1
24#endif
25
26#ifndef HAVE_EPOLL
27# define HAVE_EPOLL 0
28#endif
29
30#ifndef HAVE_REALTIME
31# define HAVE_REALTIME 1 /* posix requirement, but might be slower */
32#endif
21 33
22#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ 34#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */
23#define MAX_BLOCKTIME 60. 35#define MAX_BLOCKTIME 60.
24 36
25#include "ev.h" 37#include "ev.h"
26 38
27struct ev_watcher { 39typedef struct ev_watcher *W;
28 EV_WATCHER (ev_watcher);
29};
30
31struct ev_watcher_list { 40typedef struct ev_watcher_list *WL;
32 EV_WATCHER_LIST (ev_watcher_list); 41typedef struct ev_watcher_time *WT;
33};
34 42
35static ev_tstamp now, diff; /* monotonic clock */ 43static ev_tstamp now, diff; /* monotonic clock */
36ev_tstamp ev_now; 44ev_tstamp ev_now;
37int ev_method; 45int ev_method;
38 46
108 } 116 }
109} 117}
110 118
111typedef struct 119typedef struct
112{ 120{
113 struct ev_watcher *w; 121 W w;
114 int events; 122 int events;
115} ANPENDING; 123} ANPENDING;
116 124
117static ANPENDING *pendings; 125static ANPENDING *pendings;
118static int pendingmax, pendingcnt; 126static int pendingmax, pendingcnt;
119 127
120static void 128static void
121event (struct ev_watcher *w, int events) 129event (W w, int events)
122{ 130{
123 w->pending = ++pendingcnt; 131 w->pending = ++pendingcnt;
124 array_needsize (pendings, pendingmax, pendingcnt, ); 132 array_needsize (pendings, pendingmax, pendingcnt, );
125 pendings [pendingcnt - 1].w = w; 133 pendings [pendingcnt - 1].w = w;
126 pendings [pendingcnt - 1].events = events; 134 pendings [pendingcnt - 1].events = events;
135 for (w = anfd->head; w; w = w->next) 143 for (w = anfd->head; w; w = w->next)
136 { 144 {
137 int ev = w->events & events; 145 int ev = w->events & events;
138 146
139 if (ev) 147 if (ev)
140 event ((struct ev_watcher *)w, ev); 148 event ((W)w, ev);
141 } 149 }
142} 150}
143 151
144static void 152static void
145queue_events (struct ev_watcher **events, int eventcnt, int type) 153queue_events (W *events, int eventcnt, int type)
146{ 154{
147 int i; 155 int i;
148 156
149 for (i = 0; i < eventcnt; ++i) 157 for (i = 0; i < eventcnt; ++i)
150 event (events [i], type); 158 event (events [i], type);
151} 159}
152 160
153/*****************************************************************************/ 161/*****************************************************************************/
154 162
155static struct ev_timer **atimers; 163static struct ev_timer **timers;
156static int atimermax, atimercnt; 164static int timermax, timercnt;
157 165
158static struct ev_timer **rtimers; 166static struct ev_periodic **periodics;
159static int rtimermax, rtimercnt; 167static int periodicmax, periodiccnt;
160 168
161static void 169static void
162upheap (struct ev_timer **timers, int k) 170upheap (WT *timers, int k)
163{ 171{
164 struct ev_timer *w = timers [k]; 172 WT w = timers [k];
165 173
166 while (k && timers [k >> 1]->at > w->at) 174 while (k && timers [k >> 1]->at > w->at)
167 { 175 {
168 timers [k] = timers [k >> 1]; 176 timers [k] = timers [k >> 1];
169 timers [k]->active = k + 1; 177 timers [k]->active = k + 1;
174 timers [k]->active = k + 1; 182 timers [k]->active = k + 1;
175 183
176} 184}
177 185
178static void 186static void
179downheap (struct ev_timer **timers, int N, int k) 187downheap (WT *timers, int N, int k)
180{ 188{
181 struct ev_timer *w = timers [k]; 189 WT w = timers [k];
182 190
183 while (k < (N >> 1)) 191 while (k < (N >> 1))
184 { 192 {
185 int j = k << 1; 193 int j = k << 1;
186 194
250 if (signals [sig].gotsig) 258 if (signals [sig].gotsig)
251 { 259 {
252 signals [sig].gotsig = 0; 260 signals [sig].gotsig = 0;
253 261
254 for (w = signals [sig].head; w; w = w->next) 262 for (w = signals [sig].head; w; w = w->next)
255 event ((struct ev_watcher *)w, EV_SIGNAL); 263 event ((W)w, EV_SIGNAL);
256 } 264 }
257} 265}
258 266
259static void 267static void
260siginit (void) 268siginit (void)
312 if (ev_method == EVMETHOD_NONE) select_init (flags); 320 if (ev_method == EVMETHOD_NONE) select_init (flags);
313#endif 321#endif
314 322
315 if (ev_method) 323 if (ev_method)
316 { 324 {
317 evw_init (&sigev, sigcb, 0); 325 evw_init (&sigev, sigcb);
318 siginit (); 326 siginit ();
319 } 327 }
320 328
321 return ev_method; 329 return ev_method;
322} 330}
323 331
324/*****************************************************************************/ 332/*****************************************************************************/
325 333
326void ev_prefork (void) 334void ev_prefork (void)
327{ 335{
336 /* nop */
328} 337}
329 338
330void ev_postfork_parent (void) 339void ev_postfork_parent (void)
331{ 340{
341 /* nop */
332} 342}
333 343
334void ev_postfork_child (void) 344void ev_postfork_child (void)
335{ 345{
336#if HAVE_EPOLL 346#if HAVE_EPOLL
391 401
392 pendingcnt = 0; 402 pendingcnt = 0;
393} 403}
394 404
395static void 405static void
396timers_reify (struct ev_timer **timers, int timercnt, ev_tstamp now) 406timers_reify ()
397{ 407{
398 while (timercnt && timers [0]->at <= now) 408 while (timercnt && timers [0]->at <= now)
399 { 409 {
400 struct ev_timer *w = timers [0]; 410 struct ev_timer *w = timers [0];
401 411
402 /* first reschedule or stop timer */ 412 /* first reschedule or stop timer */
403 if (w->repeat) 413 if (w->repeat)
404 { 414 {
405 if (w->is_abs)
406 w->at += floor ((now - w->at) / w->repeat + 1.) * w->repeat;
407 else
408 w->at = now + w->repeat; 415 w->at = now + w->repeat;
409 416 assert (("timer timeout in the past, negative repeat?", w->at > now));
410 assert (w->at > now);
411
412 downheap (timers, timercnt, 0); 417 downheap ((WT *)timers, timercnt, 0);
413 } 418 }
414 else 419 else
420 evtimer_stop (w); /* nonrepeating: stop timer */
421
422 event ((W)w, EV_TIMEOUT);
423 }
424}
425
426static void
427periodics_reify ()
428{
429 while (periodiccnt && periodics [0]->at <= ev_now)
430 {
431 struct ev_periodic *w = periodics [0];
432
433 /* first reschedule or stop timer */
434 if (w->interval)
415 { 435 {
416 evtimer_stop (w); /* nonrepeating: stop timer */ 436 w->at += floor ((ev_now - w->at) / w->interval + 1.) * w->interval;
417 --timercnt; /* maybe pass by reference instead? */ 437 assert (("periodic timeout in the past, negative interval?", w->at > ev_now));
438 downheap ((WT *)periodics, periodiccnt, 0);
418 } 439 }
440 else
441 evperiodic_stop (w); /* nonrepeating: stop timer */
419 442
420 event ((struct ev_watcher *)w, EV_TIMEOUT); 443 event ((W)w, EV_TIMEOUT);
444 }
445}
446
447static void
448periodics_reschedule (ev_tstamp diff)
449{
450 int i;
451
452 /* adjust periodics after time jump */
453 for (i = 0; i < periodiccnt; ++i)
454 {
455 struct ev_periodic *w = periodics [i];
456
457 if (w->interval)
458 {
459 ev_tstamp diff = ceil ((ev_now - w->at) / w->interval) * w->interval;
460
461 if (fabs (diff) >= 1e-4)
462 {
463 evperiodic_stop (w);
464 evperiodic_start (w);
465
466 i = 0; /* restart loop, inefficient, but time jumps should be rare */
467 }
468 }
421 } 469 }
422} 470}
423 471
424static void 472static void
425time_update () 473time_update ()
426{ 474{
427 int i; 475 int i;
476
428 ev_now = ev_time (); 477 ev_now = ev_time ();
429 478
430 if (have_monotonic) 479 if (have_monotonic)
431 { 480 {
432 ev_tstamp odiff = diff; 481 ev_tstamp odiff = diff;
433 482
434 /* detecting time jumps is much more difficult */
435 for (i = 2; --i; ) /* loop a few times, before making important decisions */ 483 for (i = 4; --i; ) /* loop a few times, before making important decisions */
436 { 484 {
437 now = get_clock (); 485 now = get_clock ();
438 diff = ev_now - now; 486 diff = ev_now - now;
439 487
440 if (fabs (odiff - diff) < MIN_TIMEJUMP) 488 if (fabs (odiff - diff) < MIN_TIMEJUMP)
441 return; /* all is well */ 489 return; /* all is well */
442 490
443 ev_now = ev_time (); 491 ev_now = ev_time ();
444 } 492 }
445 493
446 /* time jump detected, reschedule atimers */ 494 periodics_reschedule (diff - odiff);
447 for (i = 0; i < atimercnt; ++i) 495 /* no timer adjustment, as the monotonic clock doesn't jump */
496 }
497 else
498 {
499 if (now > ev_now || now < ev_now - MAX_BLOCKTIME - MIN_TIMEJUMP)
448 { 500 {
449 struct ev_timer *w = atimers [i]; 501 periodics_reschedule (ev_now - now);
450 w->at += ceil ((ev_now - w->at) / w->repeat + 1.) * w->repeat; 502
503 /* adjust timers. this is easy, as the offset is the same for all */
504 for (i = 0; i < timercnt; ++i)
505 timers [i]->at += diff;
451 } 506 }
452 }
453 else
454 {
455 if (now > ev_now || now < ev_now - MAX_BLOCKTIME - MIN_TIMEJUMP)
456 /* time jump detected, adjust rtimers */
457 for (i = 0; i < rtimercnt; ++i)
458 rtimers [i]->at += ev_now - now;
459 507
460 now = ev_now; 508 now = ev_now;
461 } 509 }
462} 510}
463 511
464int ev_loop_done; 512int ev_loop_done;
465 513
466void ev_loop (int flags) 514void ev_loop (int flags)
467{ 515{
468 double block; 516 double block;
469 ev_loop_done = flags & EVLOOP_ONESHOT; 517 ev_loop_done = flags & EVLOOP_ONESHOT ? 1 : 0;
470 518
471 if (checkcnt) 519 if (checkcnt)
472 { 520 {
473 queue_events (checks, checkcnt, EV_CHECK); 521 queue_events ((W *)checks, checkcnt, EV_CHECK);
474 call_pending (); 522 call_pending ();
475 } 523 }
476 524
477 do 525 do
478 { 526 {
479 /* update fd-related kernel structures */ 527 /* update fd-related kernel structures */
480 fd_reify (); 528 fd_reify ();
481 529
482 /* calculate blocking time */ 530 /* calculate blocking time */
531
532 /* we only need this for !monotonic clock, but as we always have timers, we just calculate it every time */
533 ev_now = ev_time ();
534
483 if (flags & EVLOOP_NONBLOCK || idlecnt) 535 if (flags & EVLOOP_NONBLOCK || idlecnt)
484 block = 0.; 536 block = 0.;
485 else 537 else
486 { 538 {
487 block = MAX_BLOCKTIME; 539 block = MAX_BLOCKTIME;
488 540
489 if (rtimercnt) 541 if (timercnt)
490 { 542 {
491 ev_tstamp to = rtimers [0]->at - get_clock () + method_fudge; 543 ev_tstamp to = timers [0]->at - get_clock () + method_fudge;
492 if (block > to) block = to; 544 if (block > to) block = to;
493 } 545 }
494 546
495 if (atimercnt) 547 if (periodiccnt)
496 { 548 {
497 ev_tstamp to = atimers [0]->at - ev_time () + method_fudge; 549 ev_tstamp to = periodics [0]->at - ev_now + method_fudge;
498 if (block > to) block = to; 550 if (block > to) block = to;
499 } 551 }
500 552
501 if (block < 0.) block = 0.; 553 if (block < 0.) block = 0.;
502 } 554 }
505 557
506 /* update ev_now, do magic */ 558 /* update ev_now, do magic */
507 time_update (); 559 time_update ();
508 560
509 /* queue pending timers and reschedule them */ 561 /* queue pending timers and reschedule them */
510 /* absolute timers first */ 562 periodics_reify (); /* absolute timers first */
511 timers_reify (atimers, atimercnt, ev_now);
512 /* relative timers second */ 563 timers_reify (); /* relative timers second */
513 timers_reify (rtimers, rtimercnt, now);
514 564
515 /* queue idle watchers unless io or timers are pending */ 565 /* queue idle watchers unless io or timers are pending */
516 if (!pendingcnt) 566 if (!pendingcnt)
517 queue_events (idles, idlecnt, EV_IDLE); 567 queue_events ((W *)idles, idlecnt, EV_IDLE);
518 568
519 /* queue check and possibly idle watchers */ 569 /* queue check and possibly idle watchers */
520 queue_events (checks, checkcnt, EV_CHECK); 570 queue_events ((W *)checks, checkcnt, EV_CHECK);
521 571
522 call_pending (); 572 call_pending ();
523 } 573 }
524 while (!ev_loop_done); 574 while (!ev_loop_done);
525}
526 575
527/*****************************************************************************/ 576 if (ev_loop_done != 2)
577 ev_loop_done = 0;
578}
528 579
580/*****************************************************************************/
581
529static void 582static void
530wlist_add (struct ev_watcher_list **head, struct ev_watcher_list *elem) 583wlist_add (WL *head, WL elem)
531{ 584{
532 elem->next = *head; 585 elem->next = *head;
533 *head = elem; 586 *head = elem;
534} 587}
535 588
536static void 589static void
537wlist_del (struct ev_watcher_list **head, struct ev_watcher_list *elem) 590wlist_del (WL *head, WL elem)
538{ 591{
539 while (*head) 592 while (*head)
540 { 593 {
541 if (*head == elem) 594 if (*head == elem)
542 { 595 {
547 head = &(*head)->next; 600 head = &(*head)->next;
548 } 601 }
549} 602}
550 603
551static void 604static void
552ev_start (struct ev_watcher *w, int active) 605ev_start (W w, int active)
553{ 606{
554 w->pending = 0; 607 w->pending = 0;
555 w->active = active; 608 w->active = active;
556} 609}
557 610
558static void 611static void
559ev_stop (struct ev_watcher *w) 612ev_stop (W w)
560{ 613{
561 if (w->pending) 614 if (w->pending)
562 pendings [w->pending - 1].w = 0; 615 pendings [w->pending - 1].w = 0;
563 616
564 w->active = 0; 617 w->active = 0;
565 /* nop */
566} 618}
567 619
568/*****************************************************************************/ 620/*****************************************************************************/
569 621
570void 622void
573 if (ev_is_active (w)) 625 if (ev_is_active (w))
574 return; 626 return;
575 627
576 int fd = w->fd; 628 int fd = w->fd;
577 629
578 ev_start ((struct ev_watcher *)w, 1); 630 ev_start ((W)w, 1);
579 array_needsize (anfds, anfdmax, fd + 1, anfds_init); 631 array_needsize (anfds, anfdmax, fd + 1, anfds_init);
580 wlist_add ((struct ev_watcher_list **)&anfds[fd].head, (struct ev_watcher_list *)w); 632 wlist_add ((WL *)&anfds[fd].head, (WL)w);
581 633
582 ++fdchangecnt; 634 ++fdchangecnt;
583 array_needsize (fdchanges, fdchangemax, fdchangecnt, ); 635 array_needsize (fdchanges, fdchangemax, fdchangecnt, );
584 fdchanges [fdchangecnt - 1] = fd; 636 fdchanges [fdchangecnt - 1] = fd;
585} 637}
588evio_stop (struct ev_io *w) 640evio_stop (struct ev_io *w)
589{ 641{
590 if (!ev_is_active (w)) 642 if (!ev_is_active (w))
591 return; 643 return;
592 644
593 wlist_del ((struct ev_watcher_list **)&anfds[w->fd].head, (struct ev_watcher_list *)w); 645 wlist_del ((WL *)&anfds[w->fd].head, (WL)w);
594 ev_stop ((struct ev_watcher *)w); 646 ev_stop ((W)w);
595 647
596 ++fdchangecnt; 648 ++fdchangecnt;
597 array_needsize (fdchanges, fdchangemax, fdchangecnt, ); 649 array_needsize (fdchanges, fdchangemax, fdchangecnt, );
598 fdchanges [fdchangecnt - 1] = w->fd; 650 fdchanges [fdchangecnt - 1] = w->fd;
599} 651}
600 652
653
601void 654void
602evtimer_start (struct ev_timer *w) 655evtimer_start (struct ev_timer *w)
603{ 656{
604 if (ev_is_active (w)) 657 if (ev_is_active (w))
605 return; 658 return;
606 659
607 if (w->is_abs) 660 w->at += now;
608 {
609 /* this formula differs from the one in timer_reify becuse we do not round up */
610 if (w->repeat)
611 w->at += ceil ((ev_now - w->at) / w->repeat) * w->repeat;
612 661
613 ev_start ((struct ev_watcher *)w, ++atimercnt); 662 assert (("timer repeat value less than zero not allowed", w->repeat >= 0.));
663
664 ev_start ((W)w, ++timercnt);
614 array_needsize (atimers, atimermax, atimercnt, ); 665 array_needsize (timers, timermax, timercnt, );
615 atimers [atimercnt - 1] = w; 666 timers [timercnt - 1] = w;
616 upheap (atimers, atimercnt - 1); 667 upheap ((WT *)timers, timercnt - 1);
617 }
618 else
619 {
620 w->at += now;
621
622 ev_start ((struct ev_watcher *)w, ++rtimercnt);
623 array_needsize (rtimers, rtimermax, rtimercnt, );
624 rtimers [rtimercnt - 1] = w;
625 upheap (rtimers, rtimercnt - 1);
626 }
627
628} 668}
629 669
630void 670void
631evtimer_stop (struct ev_timer *w) 671evtimer_stop (struct ev_timer *w)
632{ 672{
633 if (!ev_is_active (w)) 673 if (!ev_is_active (w))
634 return; 674 return;
635 675
636 if (w->is_abs)
637 {
638 if (w->active < atimercnt--) 676 if (w->active < timercnt--)
639 { 677 {
640 atimers [w->active - 1] = atimers [atimercnt]; 678 timers [w->active - 1] = timers [timercnt];
641 downheap (atimers, atimercnt, w->active - 1); 679 downheap ((WT *)timers, timercnt, w->active - 1);
642 }
643 }
644 else
645 { 680 }
681
682 ev_stop ((W)w);
683}
684
685void
686evperiodic_start (struct ev_periodic *w)
687{
688 if (ev_is_active (w))
689 return;
690
691 assert (("periodic interval value less than zero not allowed", w->interval >= 0.));
692
693 /* this formula differs from the one in periodic_reify because we do not always round up */
694 if (w->interval)
695 w->at += ceil ((ev_now - w->at) / w->interval) * w->interval;
696
697 ev_start ((W)w, ++periodiccnt);
698 array_needsize (periodics, periodicmax, periodiccnt, );
699 periodics [periodiccnt - 1] = w;
700 upheap ((WT *)periodics, periodiccnt - 1);
701}
702
703void
704evperiodic_stop (struct ev_periodic *w)
705{
706 if (!ev_is_active (w))
707 return;
708
646 if (w->active < rtimercnt--) 709 if (w->active < periodiccnt--)
647 {
648 rtimers [w->active - 1] = rtimers [rtimercnt];
649 downheap (rtimers, rtimercnt, w->active - 1);
650 }
651 } 710 {
711 periodics [w->active - 1] = periodics [periodiccnt];
712 downheap ((WT *)periodics, periodiccnt, w->active - 1);
713 }
652 714
653 ev_stop ((struct ev_watcher *)w); 715 ev_stop ((W)w);
654} 716}
655 717
656void 718void
657evsignal_start (struct ev_signal *w) 719evsignal_start (struct ev_signal *w)
658{ 720{
659 if (ev_is_active (w)) 721 if (ev_is_active (w))
660 return; 722 return;
661 723
662 ev_start ((struct ev_watcher *)w, 1); 724 ev_start ((W)w, 1);
663 array_needsize (signals, signalmax, w->signum, signals_init); 725 array_needsize (signals, signalmax, w->signum, signals_init);
664 wlist_add ((struct ev_watcher_list **)&signals [w->signum - 1].head, (struct ev_watcher_list *)w); 726 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w);
665 727
666 if (!w->next) 728 if (!w->next)
667 { 729 {
668 struct sigaction sa; 730 struct sigaction sa;
669 sa.sa_handler = sighandler; 731 sa.sa_handler = sighandler;
677evsignal_stop (struct ev_signal *w) 739evsignal_stop (struct ev_signal *w)
678{ 740{
679 if (!ev_is_active (w)) 741 if (!ev_is_active (w))
680 return; 742 return;
681 743
682 wlist_del ((struct ev_watcher_list **)&signals [w->signum - 1].head, (struct ev_watcher_list *)w); 744 wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w);
683 ev_stop ((struct ev_watcher *)w); 745 ev_stop ((W)w);
684 746
685 if (!signals [w->signum - 1].head) 747 if (!signals [w->signum - 1].head)
686 signal (w->signum, SIG_DFL); 748 signal (w->signum, SIG_DFL);
687} 749}
688 750
689void evidle_start (struct ev_idle *w) 751void evidle_start (struct ev_idle *w)
690{ 752{
691 if (ev_is_active (w)) 753 if (ev_is_active (w))
692 return; 754 return;
693 755
694 ev_start ((struct ev_watcher *)w, ++idlecnt); 756 ev_start ((W)w, ++idlecnt);
695 array_needsize (idles, idlemax, idlecnt, ); 757 array_needsize (idles, idlemax, idlecnt, );
696 idles [idlecnt - 1] = w; 758 idles [idlecnt - 1] = w;
697} 759}
698 760
699void evidle_stop (struct ev_idle *w) 761void evidle_stop (struct ev_idle *w)
700{ 762{
701 idles [w->active - 1] = idles [--idlecnt]; 763 idles [w->active - 1] = idles [--idlecnt];
702 ev_stop ((struct ev_watcher *)w); 764 ev_stop ((W)w);
703} 765}
704 766
705void evcheck_start (struct ev_check *w) 767void evcheck_start (struct ev_check *w)
706{ 768{
707 if (ev_is_active (w)) 769 if (ev_is_active (w))
708 return; 770 return;
709 771
710 ev_start ((struct ev_watcher *)w, ++checkcnt); 772 ev_start ((W)w, ++checkcnt);
711 array_needsize (checks, checkmax, checkcnt, ); 773 array_needsize (checks, checkmax, checkcnt, );
712 checks [checkcnt - 1] = w; 774 checks [checkcnt - 1] = w;
713} 775}
714 776
715void evcheck_stop (struct ev_check *w) 777void evcheck_stop (struct ev_check *w)
716{ 778{
717 checks [w->active - 1] = checks [--checkcnt]; 779 checks [w->active - 1] = checks [--checkcnt];
718 ev_stop ((struct ev_watcher *)w); 780 ev_stop ((W)w);
719} 781}
720 782
721/*****************************************************************************/ 783/*****************************************************************************/
784
722#if 1 785#if 0
786
787struct ev_io wio;
723 788
724static void 789static void
725sin_cb (struct ev_io *w, int revents) 790sin_cb (struct ev_io *w, int revents)
726{ 791{
727 fprintf (stderr, "sin %d, revents %d\n", w->fd, revents); 792 fprintf (stderr, "sin %d, revents %d\n", w->fd, revents);
737 802
738static void 803static void
739scb (struct ev_signal *w, int revents) 804scb (struct ev_signal *w, int revents)
740{ 805{
741 fprintf (stderr, "signal %x,%d\n", revents, w->signum); 806 fprintf (stderr, "signal %x,%d\n", revents, w->signum);
807 evio_stop (&wio);
808 evio_start (&wio);
742} 809}
743 810
744static void 811static void
745gcb (struct ev_signal *w, int revents) 812gcb (struct ev_signal *w, int revents)
746{ 813{
747 fprintf (stderr, "generic %x\n", revents); 814 fprintf (stderr, "generic %x\n", revents);
815
748} 816}
749 817
750int main (void) 818int main (void)
751{ 819{
752 struct ev_io sin;
753
754 ev_init (0); 820 ev_init (0);
755 821
756 evw_init (&sin, sin_cb, 55);
757 evio_set (&sin, 0, EV_READ); 822 evio_init (&wio, sin_cb, 0, EV_READ);
758 evio_start (&sin); 823 evio_start (&wio);
759 824
760 struct ev_timer t[10000]; 825 struct ev_timer t[10000];
761 826
762#if 0 827#if 0
763 int i; 828 int i;
764 for (i = 0; i < 10000; ++i) 829 for (i = 0; i < 10000; ++i)
765 { 830 {
766 struct ev_timer *w = t + i; 831 struct ev_timer *w = t + i;
767 evw_init (w, ocb, i); 832 evw_init (w, ocb, i);
768 evtimer_set_abs (w, drand48 (), 0.99775533); 833 evtimer_init_abs (w, ocb, drand48 (), 0.99775533);
769 evtimer_start (w); 834 evtimer_start (w);
770 if (drand48 () < 0.5) 835 if (drand48 () < 0.5)
771 evtimer_stop (w); 836 evtimer_stop (w);
772 } 837 }
773#endif 838#endif
774 839
775 struct ev_timer t1; 840 struct ev_timer t1;
776 evw_init (&t1, ocb, 0); 841 evtimer_init (&t1, ocb, 5, 10);
777 evtimer_set_abs (&t1, 5, 10);
778 evtimer_start (&t1); 842 evtimer_start (&t1);
779 843
780 struct ev_signal sig; 844 struct ev_signal sig;
781 evw_init (&sig, scb, 65535);
782 evsignal_set (&sig, SIGQUIT); 845 evsignal_init (&sig, scb, SIGQUIT);
783 evsignal_start (&sig); 846 evsignal_start (&sig);
784 847
785 struct ev_check cw; 848 struct ev_check cw;
786 evw_init (&cw, gcb, 0); 849 evcheck_init (&cw, gcb);
787 evcheck_start (&cw); 850 evcheck_start (&cw);
788 851
789 struct ev_idle iw; 852 struct ev_idle iw;
790 evw_init (&iw, gcb, 0); 853 evidle_init (&iw, gcb);
791 evidle_start (&iw); 854 evidle_start (&iw);
792 855
793 ev_loop (0); 856 ev_loop (0);
794 857
795 return 0; 858 return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines