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.56 by root, Sun Nov 4 15:58:49 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 */ 118static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */
119static ev_tstamp rt_now;
120static int method;
121 119
122static int have_monotonic; /* runtime */ 120/*****************************************************************************/
123 121
124static ev_tstamp method_fudge; /* stupid epoll-returns-early bug */ 122typedef struct
125static void (*method_modify)(EV_P_ int fd, int oev, int nev); 123{
126static void (*method_poll)(EV_P_ ev_tstamp timeout); 124 struct ev_watcher_list *head;
125 unsigned char events;
126 unsigned char reify;
127} ANFD;
127 128
128static int activecnt; /* number of active events */ 129typedef struct
130{
131 W w;
132 int events;
133} ANPENDING;
129 134
130#if EV_USE_SELECT 135#if EV_MULTIPLICITY
131static unsigned char *vec_ri, *vec_ro, *vec_wi, *vec_wo;
132static int vec_max;
133#endif
134 136
135#if EV_USEV_POLL 137struct ev_loop
136static struct pollfd *polls; 138{
137static int pollmax, pollcnt; 139# define VAR(name,decl) decl;
138static int *pollidxs; /* maps fds into structure indices */ 140# include "ev_vars.h"
139static int pollidxmax; 141};
140#endif 142# undef VAR
143# include "ev_wrap.h"
141 144
142#if EV_USE_EPOLL 145#else
143static int epoll_fd = -1;
144 146
145static struct epoll_event *events; 147# define VAR(name,decl) static decl;
146static int eventmax; 148# include "ev_vars.h"
147#endif 149# undef VAR
148 150
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 151#endif
156 152
157/*****************************************************************************/ 153/*****************************************************************************/
158 154
159inline ev_tstamp 155inline ev_tstamp
208 cur = newcnt; \ 204 cur = newcnt; \
209 } 205 }
210 206
211/*****************************************************************************/ 207/*****************************************************************************/
212 208
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 209static void
224anfds_init (ANFD *base, int count) 210anfds_init (ANFD *base, int count)
225{ 211{
226 while (count--) 212 while (count--)
227 { 213 {
230 base->reify = 0; 216 base->reify = 0;
231 217
232 ++base; 218 ++base;
233 } 219 }
234} 220}
235
236typedef struct
237{
238 W w;
239 int events;
240} ANPENDING;
241
242static ANPENDING *pendings [NUMPRI];
243static int pendingmax [NUMPRI], pendingcnt [NUMPRI];
244 221
245static void 222static void
246event (EV_P_ W w, int events) 223event (EV_P_ W w, int events)
247{ 224{
248 if (w->pending) 225 if (w->pending)
280 event (EV_A_ (W)w, ev); 257 event (EV_A_ (W)w, ev);
281 } 258 }
282} 259}
283 260
284/*****************************************************************************/ 261/*****************************************************************************/
285
286static int *fdchanges;
287static int fdchangemax, fdchangecnt;
288 262
289static void 263static void
290fd_reify (EV_P) 264fd_reify (EV_P)
291{ 265{
292 int i; 266 int i;
364 fd_kill (EV_A_ fd); 338 fd_kill (EV_A_ fd);
365 return; 339 return;
366 } 340 }
367} 341}
368 342
343/* susually called after fork if method needs to re-arm all fds from scratch */
344static void
345fd_rearm_all (EV_P)
346{
347 int fd;
348
349 /* this should be highly optimised to not do anything but set a flag */
350 for (fd = 0; fd < anfdmax; ++fd)
351 if (anfds [fd].events)
352 {
353 anfds [fd].events = 0;
354 fd_change (fd);
355 }
356}
357
369/*****************************************************************************/ 358/*****************************************************************************/
370 359
371static struct ev_timer **timers;
372static int timermax, timercnt;
373
374static struct ev_periodic **periodics;
375static int periodicmax, periodiccnt;
376
377static void 360static void
378upheap (WT *timers, int k) 361upheap (WT *heap, int k)
379{ 362{
380 WT w = timers [k]; 363 WT w = heap [k];
381 364
382 while (k && timers [k >> 1]->at > w->at) 365 while (k && heap [k >> 1]->at > w->at)
383 { 366 {
384 timers [k] = timers [k >> 1]; 367 heap [k] = heap [k >> 1];
385 timers [k]->active = k + 1; 368 heap [k]->active = k + 1;
386 k >>= 1; 369 k >>= 1;
387 } 370 }
388 371
389 timers [k] = w; 372 heap [k] = w;
390 timers [k]->active = k + 1; 373 heap [k]->active = k + 1;
391 374
392} 375}
393 376
394static void 377static void
395downheap (WT *timers, int N, int k) 378downheap (WT *heap, int N, int k)
396{ 379{
397 WT w = timers [k]; 380 WT w = heap [k];
398 381
399 while (k < (N >> 1)) 382 while (k < (N >> 1))
400 { 383 {
401 int j = k << 1; 384 int j = k << 1;
402 385
403 if (j + 1 < N && timers [j]->at > timers [j + 1]->at) 386 if (j + 1 < N && heap [j]->at > heap [j + 1]->at)
404 ++j; 387 ++j;
405 388
406 if (w->at <= timers [j]->at) 389 if (w->at <= heap [j]->at)
407 break; 390 break;
408 391
409 timers [k] = timers [j]; 392 heap [k] = heap [j];
410 timers [k]->active = k + 1; 393 heap [k]->active = k + 1;
411 k = j; 394 k = j;
412 } 395 }
413 396
414 timers [k] = w; 397 heap [k] = w;
415 timers [k]->active = k + 1; 398 heap [k]->active = k + 1;
416} 399}
417 400
418/*****************************************************************************/ 401/*****************************************************************************/
419 402
420typedef struct 403typedef struct
426static ANSIG *signals; 409static ANSIG *signals;
427static int signalmax; 410static int signalmax;
428 411
429static int sigpipe [2]; 412static int sigpipe [2];
430static sig_atomic_t volatile gotsig; 413static sig_atomic_t volatile gotsig;
431static struct ev_io sigev;
432 414
433static void 415static void
434signals_init (ANSIG *base, int count) 416signals_init (ANSIG *base, int count)
435{ 417{
436 while (count--) 418 while (count--)
486 fcntl (sigpipe [0], F_SETFL, O_NONBLOCK); 468 fcntl (sigpipe [0], F_SETFL, O_NONBLOCK);
487 fcntl (sigpipe [1], F_SETFL, O_NONBLOCK); 469 fcntl (sigpipe [1], F_SETFL, O_NONBLOCK);
488#endif 470#endif
489 471
490 ev_io_set (&sigev, sigpipe [0], EV_READ); 472 ev_io_set (&sigev, sigpipe [0], EV_READ);
491 ev_io_start (&sigev); 473 ev_io_start (EV_A_ &sigev);
492 ev_unref (EV_A); /* child watcher should not keep loop alive */ 474 ev_unref (EV_A); /* child watcher should not keep loop alive */
493} 475}
494 476
495/*****************************************************************************/ 477/*****************************************************************************/
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 478
511#ifndef WIN32 479#ifndef WIN32
512 480
513#ifndef WCONTINUED 481#ifndef WCONTINUED
514# define WCONTINUED 0 482# define WCONTINUED 0
589ev_method (EV_P) 557ev_method (EV_P)
590{ 558{
591 return method; 559 return method;
592} 560}
593 561
594int 562static void
595ev_init (EV_P_ int methods) 563loop_init (EV_P_ int methods)
596{ 564{
597 if (!method) 565 if (!method)
598 { 566 {
599#if EV_USE_MONOTONIC 567#if EV_USE_MONOTONIC
600 { 568 {
605#endif 573#endif
606 574
607 rt_now = ev_time (); 575 rt_now = ev_time ();
608 mn_now = get_clock (); 576 mn_now = get_clock ();
609 now_floor = mn_now; 577 now_floor = mn_now;
610 diff = rt_now - mn_now; 578 rtmn_diff = rt_now - mn_now;
611
612 if (pipe (sigpipe))
613 return 0;
614 579
615 if (methods == EVMETHOD_AUTO) 580 if (methods == EVMETHOD_AUTO)
616 if (!enable_secure () && getenv ("LIBmethodS")) 581 if (!enable_secure () && getenv ("LIBEV_METHODS"))
617 methods = atoi (getenv ("LIBmethodS")); 582 methods = atoi (getenv ("LIBEV_METHODS"));
618 else 583 else
619 methods = EVMETHOD_ANY; 584 methods = EVMETHOD_ANY;
620 585
621 method = 0; 586 method = 0;
622#if EV_USE_KQUEUE 587#if EV_USE_KQUEUE
629 if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods); 594 if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods);
630#endif 595#endif
631#if EV_USE_SELECT 596#if EV_USE_SELECT
632 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); 597 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods);
633#endif 598#endif
599 }
600}
634 601
602void
603loop_destroy (EV_P)
604{
605#if EV_USE_KQUEUE
606 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A);
607#endif
608#if EV_USE_EPOLL
609 if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A);
610#endif
611#if EV_USEV_POLL
612 if (method == EVMETHOD_POLL ) poll_destroy (EV_A);
613#endif
614#if EV_USE_SELECT
615 if (method == EVMETHOD_SELECT) select_destroy (EV_A);
616#endif
617
618 method = 0;
619 /*TODO*/
620}
621
622void
623loop_fork (EV_P)
624{
625 /*TODO*/
626#if EV_USE_EPOLL
627 if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A);
628#endif
629#if EV_USE_KQUEUE
630 if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A);
631#endif
632}
633
634#if EV_MULTIPLICITY
635struct ev_loop *
636ev_loop_new (int methods)
637{
638 struct ev_loop *loop = (struct ev_loop *)calloc (1, sizeof (struct ev_loop));
639
640 loop_init (EV_A_ methods);
641
642 if (ev_methods (EV_A))
643 return loop;
644
645 return 0;
646}
647
648void
649ev_loop_destroy (EV_P)
650{
651 loop_destroy (EV_A);
652 free (loop);
653}
654
655void
656ev_loop_fork (EV_P)
657{
658 loop_fork (EV_A);
659}
660
661#endif
662
663#if EV_MULTIPLICITY
664struct ev_loop default_loop_struct;
665static struct ev_loop *default_loop;
666
667struct ev_loop *
668#else
669static int default_loop;
670
671int
672#endif
673ev_default_loop (int methods)
674{
675 if (sigpipe [0] == sigpipe [1])
676 if (pipe (sigpipe))
677 return 0;
678
679 if (!default_loop)
680 {
681#if EV_MULTIPLICITY
682 struct ev_loop *loop = default_loop = &default_loop_struct;
683#else
684 default_loop = 1;
685#endif
686
687 loop_init (EV_A_ methods);
688
635 if (method) 689 if (ev_method (EV_A))
636 { 690 {
637 ev_watcher_init (&sigev, sigcb); 691 ev_watcher_init (&sigev, sigcb);
638 ev_set_priority (&sigev, EV_MAXPRI); 692 ev_set_priority (&sigev, EV_MAXPRI);
639 siginit (EV_A); 693 siginit (EV_A);
640 694
643 ev_set_priority (&childev, EV_MAXPRI); 697 ev_set_priority (&childev, EV_MAXPRI);
644 ev_signal_start (EV_A_ &childev); 698 ev_signal_start (EV_A_ &childev);
645 ev_unref (EV_A); /* child watcher should not keep loop alive */ 699 ev_unref (EV_A); /* child watcher should not keep loop alive */
646#endif 700#endif
647 } 701 }
702 else
703 default_loop = 0;
648 } 704 }
649 705
650 return method; 706 return default_loop;
651} 707}
652 708
653/*****************************************************************************/
654
655void 709void
656ev_fork_prepare (void) 710ev_default_destroy (void)
657{ 711{
658 /* nop */ 712 struct ev_loop *loop = default_loop;
659}
660 713
661void 714 ev_ref (EV_A); /* child watcher */
662ev_fork_parent (void) 715 ev_signal_stop (EV_A_ &childev);
663{
664 /* nop */
665}
666 716
667void 717 ev_ref (EV_A); /* signal watcher */
668ev_fork_child (void)
669{
670#if EV_USE_EPOLL
671 if (method == EVMETHOD_EPOLL)
672 epoll_postfork_child ();
673#endif
674
675 ev_io_stop (&sigev); 718 ev_io_stop (EV_A_ &sigev);
719
720 close (sigpipe [0]); sigpipe [0] = 0;
721 close (sigpipe [1]); sigpipe [1] = 0;
722
723 loop_destroy (EV_A);
724}
725
726void
727ev_default_fork (EV_P)
728{
729 loop_fork (EV_A);
730
731 ev_io_stop (EV_A_ &sigev);
676 close (sigpipe [0]); 732 close (sigpipe [0]);
677 close (sigpipe [1]); 733 close (sigpipe [1]);
678 pipe (sigpipe); 734 pipe (sigpipe);
735
736 ev_ref (EV_A); /* signal watcher */
679 siginit (); 737 siginit (EV_A);
680} 738}
681 739
682/*****************************************************************************/ 740/*****************************************************************************/
683 741
684static void 742static void
714 downheap ((WT *)timers, timercnt, 0); 772 downheap ((WT *)timers, timercnt, 0);
715 } 773 }
716 else 774 else
717 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ 775 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */
718 776
719 event ((W)w, EV_TIMEOUT); 777 event (EV_A_ (W)w, EV_TIMEOUT);
720 } 778 }
721} 779}
722 780
723static void 781static void
724periodics_reify (EV_P) 782periodics_reify (EV_P)
740 event (EV_A_ (W)w, EV_PERIODIC); 798 event (EV_A_ (W)w, EV_PERIODIC);
741 } 799 }
742} 800}
743 801
744static void 802static void
745periodics_reschedule (EV_P_ ev_tstamp diff) 803periodics_reschedule (EV_P)
746{ 804{
747 int i; 805 int i;
748 806
749 /* adjust periodics after time jump */ 807 /* adjust periodics after time jump */
750 for (i = 0; i < periodiccnt; ++i) 808 for (i = 0; i < periodiccnt; ++i)
771{ 829{
772 mn_now = get_clock (); 830 mn_now = get_clock ();
773 831
774 if (expect_true (mn_now - now_floor < MIN_TIMEJUMP * .5)) 832 if (expect_true (mn_now - now_floor < MIN_TIMEJUMP * .5))
775 { 833 {
776 rt_now = mn_now + diff; 834 rt_now = rtmn_diff + mn_now;
777 return 0; 835 return 0;
778 } 836 }
779 else 837 else
780 { 838 {
781 now_floor = mn_now; 839 now_floor = mn_now;
792#if EV_USE_MONOTONIC 850#if EV_USE_MONOTONIC
793 if (expect_true (have_monotonic)) 851 if (expect_true (have_monotonic))
794 { 852 {
795 if (time_update_monotonic (EV_A)) 853 if (time_update_monotonic (EV_A))
796 { 854 {
797 ev_tstamp odiff = diff; 855 ev_tstamp odiff = rtmn_diff;
798 856
799 for (i = 4; --i; ) /* loop a few times, before making important decisions */ 857 for (i = 4; --i; ) /* loop a few times, before making important decisions */
800 { 858 {
801 diff = rt_now - mn_now; 859 rtmn_diff = rt_now - mn_now;
802 860
803 if (fabs (odiff - diff) < MIN_TIMEJUMP) 861 if (fabs (odiff - rtmn_diff) < MIN_TIMEJUMP)
804 return; /* all is well */ 862 return; /* all is well */
805 863
806 rt_now = ev_time (); 864 rt_now = ev_time ();
807 mn_now = get_clock (); 865 mn_now = get_clock ();
808 now_floor = mn_now; 866 now_floor = mn_now;
809 } 867 }
810 868
811 periodics_reschedule (EV_A_ diff - odiff); 869 periodics_reschedule (EV_A);
812 /* no timer adjustment, as the monotonic clock doesn't jump */ 870 /* no timer adjustment, as the monotonic clock doesn't jump */
871 /* timers_reschedule (EV_A_ rtmn_diff - odiff) */
813 } 872 }
814 } 873 }
815 else 874 else
816#endif 875#endif
817 { 876 {
818 rt_now = ev_time (); 877 rt_now = ev_time ();
819 878
820 if (expect_false (mn_now > rt_now || mn_now < rt_now - MAX_BLOCKTIME - MIN_TIMEJUMP)) 879 if (expect_false (mn_now > rt_now || mn_now < rt_now - MAX_BLOCKTIME - MIN_TIMEJUMP))
821 { 880 {
822 periodics_reschedule (EV_A_ rt_now - mn_now); 881 periodics_reschedule (EV_A);
823 882
824 /* adjust timers. this is easy, as the offset is the same for all */ 883 /* adjust timers. this is easy, as the offset is the same for all */
825 for (i = 0; i < timercnt; ++i) 884 for (i = 0; i < timercnt; ++i)
826 timers [i]->at += diff; 885 timers [i]->at += rt_now - mn_now;
827 } 886 }
828 887
829 mn_now = rt_now; 888 mn_now = rt_now;
830 } 889 }
831} 890}
1094 } 1153 }
1095 1154
1096 ev_stop (EV_A_ (W)w); 1155 ev_stop (EV_A_ (W)w);
1097} 1156}
1098 1157
1158void
1159ev_idle_start (EV_P_ struct ev_idle *w)
1160{
1161 if (ev_is_active (w))
1162 return;
1163
1164 ev_start (EV_A_ (W)w, ++idlecnt);
1165 array_needsize (idles, idlemax, idlecnt, );
1166 idles [idlecnt - 1] = w;
1167}
1168
1169void
1170ev_idle_stop (EV_P_ struct ev_idle *w)
1171{
1172 ev_clear_pending (EV_A_ (W)w);
1173 if (ev_is_active (w))
1174 return;
1175
1176 idles [w->active - 1] = idles [--idlecnt];
1177 ev_stop (EV_A_ (W)w);
1178}
1179
1180void
1181ev_prepare_start (EV_P_ struct ev_prepare *w)
1182{
1183 if (ev_is_active (w))
1184 return;
1185
1186 ev_start (EV_A_ (W)w, ++preparecnt);
1187 array_needsize (prepares, preparemax, preparecnt, );
1188 prepares [preparecnt - 1] = w;
1189}
1190
1191void
1192ev_prepare_stop (EV_P_ struct ev_prepare *w)
1193{
1194 ev_clear_pending (EV_A_ (W)w);
1195 if (ev_is_active (w))
1196 return;
1197
1198 prepares [w->active - 1] = prepares [--preparecnt];
1199 ev_stop (EV_A_ (W)w);
1200}
1201
1202void
1203ev_check_start (EV_P_ struct ev_check *w)
1204{
1205 if (ev_is_active (w))
1206 return;
1207
1208 ev_start (EV_A_ (W)w, ++checkcnt);
1209 array_needsize (checks, checkmax, checkcnt, );
1210 checks [checkcnt - 1] = w;
1211}
1212
1213void
1214ev_check_stop (EV_P_ struct ev_check *w)
1215{
1216 ev_clear_pending (EV_A_ (W)w);
1217 if (ev_is_active (w))
1218 return;
1219
1220 checks [w->active - 1] = checks [--checkcnt];
1221 ev_stop (EV_A_ (W)w);
1222}
1223
1099#ifndef SA_RESTART 1224#ifndef SA_RESTART
1100# define SA_RESTART 0 1225# define SA_RESTART 0
1101#endif 1226#endif
1102 1227
1103void 1228void
1104ev_signal_start (EV_P_ struct ev_signal *w) 1229ev_signal_start (EV_P_ struct ev_signal *w)
1105{ 1230{
1231#if EV_MULTIPLICITY
1232 assert (("signal watchers are only supported in the default loop", loop == default_loop));
1233#endif
1106 if (ev_is_active (w)) 1234 if (ev_is_active (w))
1107 return; 1235 return;
1108 1236
1109 assert (("ev_signal_start called with illegal signal number", w->signum > 0)); 1237 assert (("ev_signal_start called with illegal signal number", w->signum > 0));
1110 1238
1135 if (!signals [w->signum - 1].head) 1263 if (!signals [w->signum - 1].head)
1136 signal (w->signum, SIG_DFL); 1264 signal (w->signum, SIG_DFL);
1137} 1265}
1138 1266
1139void 1267void
1140ev_idle_start (EV_P_ struct ev_idle *w)
1141{
1142 if (ev_is_active (w))
1143 return;
1144
1145 ev_start (EV_A_ (W)w, ++idlecnt);
1146 array_needsize (idles, idlemax, idlecnt, );
1147 idles [idlecnt - 1] = w;
1148}
1149
1150void
1151ev_idle_stop (EV_P_ struct ev_idle *w)
1152{
1153 ev_clear_pending (EV_A_ (W)w);
1154 if (ev_is_active (w))
1155 return;
1156
1157 idles [w->active - 1] = idles [--idlecnt];
1158 ev_stop (EV_A_ (W)w);
1159}
1160
1161void
1162ev_prepare_start (EV_P_ struct ev_prepare *w)
1163{
1164 if (ev_is_active (w))
1165 return;
1166
1167 ev_start (EV_A_ (W)w, ++preparecnt);
1168 array_needsize (prepares, preparemax, preparecnt, );
1169 prepares [preparecnt - 1] = w;
1170}
1171
1172void
1173ev_prepare_stop (EV_P_ struct ev_prepare *w)
1174{
1175 ev_clear_pending (EV_A_ (W)w);
1176 if (ev_is_active (w))
1177 return;
1178
1179 prepares [w->active - 1] = prepares [--preparecnt];
1180 ev_stop (EV_A_ (W)w);
1181}
1182
1183void
1184ev_check_start (EV_P_ struct ev_check *w)
1185{
1186 if (ev_is_active (w))
1187 return;
1188
1189 ev_start (EV_A_ (W)w, ++checkcnt);
1190 array_needsize (checks, checkmax, checkcnt, );
1191 checks [checkcnt - 1] = w;
1192}
1193
1194void
1195ev_check_stop (EV_P_ struct ev_check *w)
1196{
1197 ev_clear_pending (EV_A_ (W)w);
1198 if (ev_is_active (w))
1199 return;
1200
1201 checks [w->active - 1] = checks [--checkcnt];
1202 ev_stop (EV_A_ (W)w);
1203}
1204
1205void
1206ev_child_start (EV_P_ struct ev_child *w) 1268ev_child_start (EV_P_ struct ev_child *w)
1207{ 1269{
1270#if EV_MULTIPLICITY
1271 assert (("child watchers are only supported in the default loop", loop == default_loop));
1272#endif
1208 if (ev_is_active (w)) 1273 if (ev_is_active (w))
1209 return; 1274 return;
1210 1275
1211 ev_start (EV_A_ (W)w, 1); 1276 ev_start (EV_A_ (W)w, 1);
1212 wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); 1277 wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w);
1284 ev_timer_start (EV_A_ &once->to); 1349 ev_timer_start (EV_A_ &once->to);
1285 } 1350 }
1286 } 1351 }
1287} 1352}
1288 1353
1289/*****************************************************************************/
1290
1291#if 0
1292
1293struct ev_io wio;
1294
1295static void
1296sin_cb (struct ev_io *w, int revents)
1297{
1298 fprintf (stderr, "sin %d, revents %d\n", w->fd, revents);
1299}
1300
1301static void
1302ocb (struct ev_timer *w, int revents)
1303{
1304 //fprintf (stderr, "timer %f,%f (%x) (%f) d%p\n", w->at, w->repeat, revents, w->at - ev_time (), w->data);
1305 ev_timer_stop (w);
1306 ev_timer_start (w);
1307}
1308
1309static void
1310scb (struct ev_signal *w, int revents)
1311{
1312 fprintf (stderr, "signal %x,%d\n", revents, w->signum);
1313 ev_io_stop (&wio);
1314 ev_io_start (&wio);
1315}
1316
1317static void
1318gcb (struct ev_signal *w, int revents)
1319{
1320 fprintf (stderr, "generic %x\n", revents);
1321
1322}
1323
1324int main (void)
1325{
1326 ev_init (0);
1327
1328 ev_io_init (&wio, sin_cb, 0, EV_READ);
1329 ev_io_start (&wio);
1330
1331 struct ev_timer t[10000];
1332
1333#if 0
1334 int i;
1335 for (i = 0; i < 10000; ++i)
1336 {
1337 struct ev_timer *w = t + i;
1338 ev_watcher_init (w, ocb, i);
1339 ev_timer_init_abs (w, ocb, drand48 (), 0.99775533);
1340 ev_timer_start (w);
1341 if (drand48 () < 0.5)
1342 ev_timer_stop (w);
1343 }
1344#endif
1345
1346 struct ev_timer t1;
1347 ev_timer_init (&t1, ocb, 5, 10);
1348 ev_timer_start (&t1);
1349
1350 struct ev_signal sig;
1351 ev_signal_init (&sig, scb, SIGQUIT);
1352 ev_signal_start (&sig);
1353
1354 struct ev_check cw;
1355 ev_check_init (&cw, gcb);
1356 ev_check_start (&cw);
1357
1358 struct ev_idle iw;
1359 ev_idle_init (&iw, gcb);
1360 ev_idle_start (&iw);
1361
1362 ev_loop (0);
1363
1364 return 0;
1365}
1366
1367#endif
1368
1369
1370
1371

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines