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

Comparing libev/ev.c (file contents):
Revision 1.53 by root, Sat Nov 3 22:31:11 2007 UTC vs.
Revision 1.58 by root, Sun Nov 4 16:52:52 2007 UTC

26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31#ifndef EV_STANDALONE 31#ifndef EV_EMBED
32# include "config.h" 32# include "config.h"
33#endif 33#endif
34 34
35#include <math.h> 35#include <math.h>
36#include <stdlib.h> 36#include <stdlib.h>
93#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ 93#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */
94#define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detect time jumps) */ 94#define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detect time jumps) */
95#define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */ 95#define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */
96/*#define CLEANUP_INTERVAL 300. /* how often to try to free memory and re-check fds */ 96/*#define CLEANUP_INTERVAL 300. /* how often to try to free memory and re-check fds */
97 97
98#ifndef EV_EMBED
98#include "ev.h" 99# include "ev.h"
100#endif
99 101
100#if __GNUC__ >= 3 102#if __GNUC__ >= 3
101# define expect(expr,value) __builtin_expect ((expr),(value)) 103# define expect(expr,value) __builtin_expect ((expr),(value))
102# define inline inline 104# define inline inline
103#else 105#else
113 115
114typedef struct ev_watcher *W; 116typedef struct ev_watcher *W;
115typedef struct ev_watcher_list *WL; 117typedef struct ev_watcher_list *WL;
116typedef struct ev_watcher_time *WT; 118typedef struct ev_watcher_time *WT;
117 119
120static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */
121
118/*****************************************************************************/ 122/*****************************************************************************/
119 123
120typedef struct 124typedef struct
121{ 125{
122 struct ev_watcher_list *head; 126 struct ev_watcher_list *head;
128{ 132{
129 W w; 133 W w;
130 int events; 134 int events;
131} ANPENDING; 135} ANPENDING;
132 136
133#ifdef EV_MULTIPLICITY 137#if EV_MULTIPLICITY
138
134struct ev_loop 139struct ev_loop
135{ 140{
136# define VAR(name,decl) decl 141# define VAR(name,decl) decl;
137# include "ev_vars.h" 142# include "ev_vars.h"
138}; 143};
144# undef VAR
145# include "ev_wrap.h"
146
139#else 147#else
148
140# define VAR(name,decl) static decl 149# define VAR(name,decl) static decl;
141# include "ev_vars.h" 150# include "ev_vars.h"
142#endif
143#undef VAR 151# undef VAR
152
153#endif
144 154
145/*****************************************************************************/ 155/*****************************************************************************/
146 156
147inline ev_tstamp 157inline ev_tstamp
148ev_time (void) 158ev_time (void)
330 fd_kill (EV_A_ fd); 340 fd_kill (EV_A_ fd);
331 return; 341 return;
332 } 342 }
333} 343}
334 344
345/* susually called after fork if method needs to re-arm all fds from scratch */
346static void
347fd_rearm_all (EV_P)
348{
349 int fd;
350
351 /* this should be highly optimised to not do anything but set a flag */
352 for (fd = 0; fd < anfdmax; ++fd)
353 if (anfds [fd].events)
354 {
355 anfds [fd].events = 0;
356 fd_change (fd);
357 }
358}
359
335/*****************************************************************************/ 360/*****************************************************************************/
336 361
337static void 362static void
338upheap (WT *timers, int k) 363upheap (WT *heap, int k)
339{ 364{
340 WT w = timers [k]; 365 WT w = heap [k];
341 366
342 while (k && timers [k >> 1]->at > w->at) 367 while (k && heap [k >> 1]->at > w->at)
343 { 368 {
344 timers [k] = timers [k >> 1]; 369 heap [k] = heap [k >> 1];
345 timers [k]->active = k + 1; 370 heap [k]->active = k + 1;
346 k >>= 1; 371 k >>= 1;
347 } 372 }
348 373
349 timers [k] = w; 374 heap [k] = w;
350 timers [k]->active = k + 1; 375 heap [k]->active = k + 1;
351 376
352} 377}
353 378
354static void 379static void
355downheap (WT *timers, int N, int k) 380downheap (WT *heap, int N, int k)
356{ 381{
357 WT w = timers [k]; 382 WT w = heap [k];
358 383
359 while (k < (N >> 1)) 384 while (k < (N >> 1))
360 { 385 {
361 int j = k << 1; 386 int j = k << 1;
362 387
363 if (j + 1 < N && timers [j]->at > timers [j + 1]->at) 388 if (j + 1 < N && heap [j]->at > heap [j + 1]->at)
364 ++j; 389 ++j;
365 390
366 if (w->at <= timers [j]->at) 391 if (w->at <= heap [j]->at)
367 break; 392 break;
368 393
369 timers [k] = timers [j]; 394 heap [k] = heap [j];
370 timers [k]->active = k + 1; 395 heap [k]->active = k + 1;
371 k = j; 396 k = j;
372 } 397 }
373 398
374 timers [k] = w; 399 heap [k] = w;
375 timers [k]->active = k + 1; 400 heap [k]->active = k + 1;
376} 401}
377 402
378/*****************************************************************************/ 403/*****************************************************************************/
379 404
380typedef struct 405typedef struct
445 fcntl (sigpipe [0], F_SETFL, O_NONBLOCK); 470 fcntl (sigpipe [0], F_SETFL, O_NONBLOCK);
446 fcntl (sigpipe [1], F_SETFL, O_NONBLOCK); 471 fcntl (sigpipe [1], F_SETFL, O_NONBLOCK);
447#endif 472#endif
448 473
449 ev_io_set (&sigev, sigpipe [0], EV_READ); 474 ev_io_set (&sigev, sigpipe [0], EV_READ);
450 ev_io_start (&sigev); 475 ev_io_start (EV_A_ &sigev);
451 ev_unref (EV_A); /* child watcher should not keep loop alive */ 476 ev_unref (EV_A); /* child watcher should not keep loop alive */
452} 477}
453 478
454/*****************************************************************************/ 479/*****************************************************************************/
455 480
534ev_method (EV_P) 559ev_method (EV_P)
535{ 560{
536 return method; 561 return method;
537} 562}
538 563
539int 564static void
540ev_init (EV_P_ int methods) 565loop_init (EV_P_ int methods)
541{ 566{
542#ifdef EV_MULTIPLICITY
543 memset (loop, 0, sizeof (struct ev_loop));
544#endif
545
546 if (!method) 567 if (!method)
547 { 568 {
548#if EV_USE_MONOTONIC 569#if EV_USE_MONOTONIC
549 { 570 {
550 struct timespec ts; 571 struct timespec ts;
554#endif 575#endif
555 576
556 rt_now = ev_time (); 577 rt_now = ev_time ();
557 mn_now = get_clock (); 578 mn_now = get_clock ();
558 now_floor = mn_now; 579 now_floor = mn_now;
559 diff = rt_now - mn_now; 580 rtmn_diff = rt_now - mn_now;
560
561 if (pipe (sigpipe))
562 return 0;
563 581
564 if (methods == EVMETHOD_AUTO) 582 if (methods == EVMETHOD_AUTO)
565 if (!enable_secure () && getenv ("LIBmethodS")) 583 if (!enable_secure () && getenv ("LIBEV_METHODS"))
566 methods = atoi (getenv ("LIBmethodS")); 584 methods = atoi (getenv ("LIBEV_METHODS"));
567 else 585 else
568 methods = EVMETHOD_ANY; 586 methods = EVMETHOD_ANY;
569 587
570 method = 0; 588 method = 0;
571#if EV_USE_KQUEUE 589#if EV_USE_KQUEUE
578 if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods); 596 if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods);
579#endif 597#endif
580#if EV_USE_SELECT 598#if EV_USE_SELECT
581 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); 599 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods);
582#endif 600#endif
601 }
602}
583 603
604void
605loop_destroy (EV_P)
606{
607#if EV_USE_KQUEUE
608 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A);
609#endif
610#if EV_USE_EPOLL
611 if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A);
612#endif
613#if EV_USEV_POLL
614 if (method == EVMETHOD_POLL ) poll_destroy (EV_A);
615#endif
616#if EV_USE_SELECT
617 if (method == EVMETHOD_SELECT) select_destroy (EV_A);
618#endif
619
620 method = 0;
621 /*TODO*/
622}
623
624void
625loop_fork (EV_P)
626{
627 /*TODO*/
628#if EV_USE_EPOLL
629 if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A);
630#endif
631#if EV_USE_KQUEUE
632 if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A);
633#endif
634}
635
636#if EV_MULTIPLICITY
637struct ev_loop *
638ev_loop_new (int methods)
639{
640 struct ev_loop *loop = (struct ev_loop *)calloc (1, sizeof (struct ev_loop));
641
642 loop_init (EV_A_ methods);
643
644 if (ev_methods (EV_A))
645 return loop;
646
647 return 0;
648}
649
650void
651ev_loop_destroy (EV_P)
652{
653 loop_destroy (EV_A);
654 free (loop);
655}
656
657void
658ev_loop_fork (EV_P)
659{
660 loop_fork (EV_A);
661}
662
663#endif
664
665#if EV_MULTIPLICITY
666struct ev_loop default_loop_struct;
667static struct ev_loop *default_loop;
668
669struct ev_loop *
670#else
671static int default_loop;
672
673int
674#endif
675ev_default_loop (int methods)
676{
677 if (sigpipe [0] == sigpipe [1])
678 if (pipe (sigpipe))
679 return 0;
680
681 if (!default_loop)
682 {
683#if EV_MULTIPLICITY
684 struct ev_loop *loop = default_loop = &default_loop_struct;
685#else
686 default_loop = 1;
687#endif
688
689 loop_init (EV_A_ methods);
690
584 if (method) 691 if (ev_method (EV_A))
585 { 692 {
586 ev_watcher_init (&sigev, sigcb); 693 ev_watcher_init (&sigev, sigcb);
587 ev_set_priority (&sigev, EV_MAXPRI); 694 ev_set_priority (&sigev, EV_MAXPRI);
588 siginit (EV_A); 695 siginit (EV_A);
589 696
592 ev_set_priority (&childev, EV_MAXPRI); 699 ev_set_priority (&childev, EV_MAXPRI);
593 ev_signal_start (EV_A_ &childev); 700 ev_signal_start (EV_A_ &childev);
594 ev_unref (EV_A); /* child watcher should not keep loop alive */ 701 ev_unref (EV_A); /* child watcher should not keep loop alive */
595#endif 702#endif
596 } 703 }
704 else
705 default_loop = 0;
597 } 706 }
598 707
599 return method; 708 return default_loop;
600} 709}
601 710
602/*****************************************************************************/
603
604void 711void
605ev_fork_prepare (void) 712ev_default_destroy (void)
606{ 713{
607 /* nop */ 714#if EV_MULTIPLICITY
608} 715 struct ev_loop *loop = default_loop;
609
610void
611ev_fork_parent (void)
612{
613 /* nop */
614}
615
616void
617ev_fork_child (void)
618{
619#if EV_USE_EPOLL
620 if (method == EVMETHOD_EPOLL)
621 epoll_postfork_child ();
622#endif 716#endif
623 717
718 ev_ref (EV_A); /* child watcher */
719 ev_signal_stop (EV_A_ &childev);
720
721 ev_ref (EV_A); /* signal watcher */
624 ev_io_stop (&sigev); 722 ev_io_stop (EV_A_ &sigev);
723
724 close (sigpipe [0]); sigpipe [0] = 0;
725 close (sigpipe [1]); sigpipe [1] = 0;
726
727 loop_destroy (EV_A);
728}
729
730void
731ev_default_fork (EV_P)
732{
733 loop_fork (EV_A);
734
735 ev_io_stop (EV_A_ &sigev);
625 close (sigpipe [0]); 736 close (sigpipe [0]);
626 close (sigpipe [1]); 737 close (sigpipe [1]);
627 pipe (sigpipe); 738 pipe (sigpipe);
739
740 ev_ref (EV_A); /* signal watcher */
628 siginit (); 741 siginit (EV_A);
629} 742}
630 743
631/*****************************************************************************/ 744/*****************************************************************************/
632 745
633static void 746static void
663 downheap ((WT *)timers, timercnt, 0); 776 downheap ((WT *)timers, timercnt, 0);
664 } 777 }
665 else 778 else
666 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ 779 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */
667 780
668 event ((W)w, EV_TIMEOUT); 781 event (EV_A_ (W)w, EV_TIMEOUT);
669 } 782 }
670} 783}
671 784
672static void 785static void
673periodics_reify (EV_P) 786periodics_reify (EV_P)
689 event (EV_A_ (W)w, EV_PERIODIC); 802 event (EV_A_ (W)w, EV_PERIODIC);
690 } 803 }
691} 804}
692 805
693static void 806static void
694periodics_reschedule (EV_P_ ev_tstamp diff) 807periodics_reschedule (EV_P)
695{ 808{
696 int i; 809 int i;
697 810
698 /* adjust periodics after time jump */ 811 /* adjust periodics after time jump */
699 for (i = 0; i < periodiccnt; ++i) 812 for (i = 0; i < periodiccnt; ++i)
720{ 833{
721 mn_now = get_clock (); 834 mn_now = get_clock ();
722 835
723 if (expect_true (mn_now - now_floor < MIN_TIMEJUMP * .5)) 836 if (expect_true (mn_now - now_floor < MIN_TIMEJUMP * .5))
724 { 837 {
725 rt_now = mn_now + diff; 838 rt_now = rtmn_diff + mn_now;
726 return 0; 839 return 0;
727 } 840 }
728 else 841 else
729 { 842 {
730 now_floor = mn_now; 843 now_floor = mn_now;
741#if EV_USE_MONOTONIC 854#if EV_USE_MONOTONIC
742 if (expect_true (have_monotonic)) 855 if (expect_true (have_monotonic))
743 { 856 {
744 if (time_update_monotonic (EV_A)) 857 if (time_update_monotonic (EV_A))
745 { 858 {
746 ev_tstamp odiff = diff; 859 ev_tstamp odiff = rtmn_diff;
747 860
748 for (i = 4; --i; ) /* loop a few times, before making important decisions */ 861 for (i = 4; --i; ) /* loop a few times, before making important decisions */
749 { 862 {
750 diff = rt_now - mn_now; 863 rtmn_diff = rt_now - mn_now;
751 864
752 if (fabs (odiff - diff) < MIN_TIMEJUMP) 865 if (fabs (odiff - rtmn_diff) < MIN_TIMEJUMP)
753 return; /* all is well */ 866 return; /* all is well */
754 867
755 rt_now = ev_time (); 868 rt_now = ev_time ();
756 mn_now = get_clock (); 869 mn_now = get_clock ();
757 now_floor = mn_now; 870 now_floor = mn_now;
758 } 871 }
759 872
760 periodics_reschedule (EV_A_ diff - odiff); 873 periodics_reschedule (EV_A);
761 /* no timer adjustment, as the monotonic clock doesn't jump */ 874 /* no timer adjustment, as the monotonic clock doesn't jump */
875 /* timers_reschedule (EV_A_ rtmn_diff - odiff) */
762 } 876 }
763 } 877 }
764 else 878 else
765#endif 879#endif
766 { 880 {
767 rt_now = ev_time (); 881 rt_now = ev_time ();
768 882
769 if (expect_false (mn_now > rt_now || mn_now < rt_now - MAX_BLOCKTIME - MIN_TIMEJUMP)) 883 if (expect_false (mn_now > rt_now || mn_now < rt_now - MAX_BLOCKTIME - MIN_TIMEJUMP))
770 { 884 {
771 periodics_reschedule (EV_A_ rt_now - mn_now); 885 periodics_reschedule (EV_A);
772 886
773 /* adjust timers. this is easy, as the offset is the same for all */ 887 /* adjust timers. this is easy, as the offset is the same for all */
774 for (i = 0; i < timercnt; ++i) 888 for (i = 0; i < timercnt; ++i)
775 timers [i]->at += diff; 889 timers [i]->at += rt_now - mn_now;
776 } 890 }
777 891
778 mn_now = rt_now; 892 mn_now = rt_now;
779 } 893 }
780} 894}
1043 } 1157 }
1044 1158
1045 ev_stop (EV_A_ (W)w); 1159 ev_stop (EV_A_ (W)w);
1046} 1160}
1047 1161
1162void
1163ev_idle_start (EV_P_ struct ev_idle *w)
1164{
1165 if (ev_is_active (w))
1166 return;
1167
1168 ev_start (EV_A_ (W)w, ++idlecnt);
1169 array_needsize (idles, idlemax, idlecnt, );
1170 idles [idlecnt - 1] = w;
1171}
1172
1173void
1174ev_idle_stop (EV_P_ struct ev_idle *w)
1175{
1176 ev_clear_pending (EV_A_ (W)w);
1177 if (ev_is_active (w))
1178 return;
1179
1180 idles [w->active - 1] = idles [--idlecnt];
1181 ev_stop (EV_A_ (W)w);
1182}
1183
1184void
1185ev_prepare_start (EV_P_ struct ev_prepare *w)
1186{
1187 if (ev_is_active (w))
1188 return;
1189
1190 ev_start (EV_A_ (W)w, ++preparecnt);
1191 array_needsize (prepares, preparemax, preparecnt, );
1192 prepares [preparecnt - 1] = w;
1193}
1194
1195void
1196ev_prepare_stop (EV_P_ struct ev_prepare *w)
1197{
1198 ev_clear_pending (EV_A_ (W)w);
1199 if (ev_is_active (w))
1200 return;
1201
1202 prepares [w->active - 1] = prepares [--preparecnt];
1203 ev_stop (EV_A_ (W)w);
1204}
1205
1206void
1207ev_check_start (EV_P_ struct ev_check *w)
1208{
1209 if (ev_is_active (w))
1210 return;
1211
1212 ev_start (EV_A_ (W)w, ++checkcnt);
1213 array_needsize (checks, checkmax, checkcnt, );
1214 checks [checkcnt - 1] = w;
1215}
1216
1217void
1218ev_check_stop (EV_P_ struct ev_check *w)
1219{
1220 ev_clear_pending (EV_A_ (W)w);
1221 if (ev_is_active (w))
1222 return;
1223
1224 checks [w->active - 1] = checks [--checkcnt];
1225 ev_stop (EV_A_ (W)w);
1226}
1227
1048#ifndef SA_RESTART 1228#ifndef SA_RESTART
1049# define SA_RESTART 0 1229# define SA_RESTART 0
1050#endif 1230#endif
1051 1231
1052void 1232void
1053ev_signal_start (EV_P_ struct ev_signal *w) 1233ev_signal_start (EV_P_ struct ev_signal *w)
1054{ 1234{
1235#if EV_MULTIPLICITY
1236 assert (("signal watchers are only supported in the default loop", loop == default_loop));
1237#endif
1055 if (ev_is_active (w)) 1238 if (ev_is_active (w))
1056 return; 1239 return;
1057 1240
1058 assert (("ev_signal_start called with illegal signal number", w->signum > 0)); 1241 assert (("ev_signal_start called with illegal signal number", w->signum > 0));
1059 1242
1084 if (!signals [w->signum - 1].head) 1267 if (!signals [w->signum - 1].head)
1085 signal (w->signum, SIG_DFL); 1268 signal (w->signum, SIG_DFL);
1086} 1269}
1087 1270
1088void 1271void
1089ev_idle_start (EV_P_ struct ev_idle *w)
1090{
1091 if (ev_is_active (w))
1092 return;
1093
1094 ev_start (EV_A_ (W)w, ++idlecnt);
1095 array_needsize (idles, idlemax, idlecnt, );
1096 idles [idlecnt - 1] = w;
1097}
1098
1099void
1100ev_idle_stop (EV_P_ struct ev_idle *w)
1101{
1102 ev_clear_pending (EV_A_ (W)w);
1103 if (ev_is_active (w))
1104 return;
1105
1106 idles [w->active - 1] = idles [--idlecnt];
1107 ev_stop (EV_A_ (W)w);
1108}
1109
1110void
1111ev_prepare_start (EV_P_ struct ev_prepare *w)
1112{
1113 if (ev_is_active (w))
1114 return;
1115
1116 ev_start (EV_A_ (W)w, ++preparecnt);
1117 array_needsize (prepares, preparemax, preparecnt, );
1118 prepares [preparecnt - 1] = w;
1119}
1120
1121void
1122ev_prepare_stop (EV_P_ struct ev_prepare *w)
1123{
1124 ev_clear_pending (EV_A_ (W)w);
1125 if (ev_is_active (w))
1126 return;
1127
1128 prepares [w->active - 1] = prepares [--preparecnt];
1129 ev_stop (EV_A_ (W)w);
1130}
1131
1132void
1133ev_check_start (EV_P_ struct ev_check *w)
1134{
1135 if (ev_is_active (w))
1136 return;
1137
1138 ev_start (EV_A_ (W)w, ++checkcnt);
1139 array_needsize (checks, checkmax, checkcnt, );
1140 checks [checkcnt - 1] = w;
1141}
1142
1143void
1144ev_check_stop (EV_P_ struct ev_check *w)
1145{
1146 ev_clear_pending (EV_A_ (W)w);
1147 if (ev_is_active (w))
1148 return;
1149
1150 checks [w->active - 1] = checks [--checkcnt];
1151 ev_stop (EV_A_ (W)w);
1152}
1153
1154void
1155ev_child_start (EV_P_ struct ev_child *w) 1272ev_child_start (EV_P_ struct ev_child *w)
1156{ 1273{
1274#if EV_MULTIPLICITY
1275 assert (("child watchers are only supported in the default loop", loop == default_loop));
1276#endif
1157 if (ev_is_active (w)) 1277 if (ev_is_active (w))
1158 return; 1278 return;
1159 1279
1160 ev_start (EV_A_ (W)w, 1); 1280 ev_start (EV_A_ (W)w, 1);
1161 wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); 1281 wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w);
1233 ev_timer_start (EV_A_ &once->to); 1353 ev_timer_start (EV_A_ &once->to);
1234 } 1354 }
1235 } 1355 }
1236} 1356}
1237 1357
1238/*****************************************************************************/
1239
1240#if 0
1241
1242struct ev_io wio;
1243
1244static void
1245sin_cb (struct ev_io *w, int revents)
1246{
1247 fprintf (stderr, "sin %d, revents %d\n", w->fd, revents);
1248}
1249
1250static void
1251ocb (struct ev_timer *w, int revents)
1252{
1253 //fprintf (stderr, "timer %f,%f (%x) (%f) d%p\n", w->at, w->repeat, revents, w->at - ev_time (), w->data);
1254 ev_timer_stop (w);
1255 ev_timer_start (w);
1256}
1257
1258static void
1259scb (struct ev_signal *w, int revents)
1260{
1261 fprintf (stderr, "signal %x,%d\n", revents, w->signum);
1262 ev_io_stop (&wio);
1263 ev_io_start (&wio);
1264}
1265
1266static void
1267gcb (struct ev_signal *w, int revents)
1268{
1269 fprintf (stderr, "generic %x\n", revents);
1270
1271}
1272
1273int main (void)
1274{
1275 ev_init (0);
1276
1277 ev_io_init (&wio, sin_cb, 0, EV_READ);
1278 ev_io_start (&wio);
1279
1280 struct ev_timer t[10000];
1281
1282#if 0
1283 int i;
1284 for (i = 0; i < 10000; ++i)
1285 {
1286 struct ev_timer *w = t + i;
1287 ev_watcher_init (w, ocb, i);
1288 ev_timer_init_abs (w, ocb, drand48 (), 0.99775533);
1289 ev_timer_start (w);
1290 if (drand48 () < 0.5)
1291 ev_timer_stop (w);
1292 }
1293#endif
1294
1295 struct ev_timer t1;
1296 ev_timer_init (&t1, ocb, 5, 10);
1297 ev_timer_start (&t1);
1298
1299 struct ev_signal sig;
1300 ev_signal_init (&sig, scb, SIGQUIT);
1301 ev_signal_start (&sig);
1302
1303 struct ev_check cw;
1304 ev_check_init (&cw, gcb);
1305 ev_check_start (&cw);
1306
1307 struct ev_idle iw;
1308 ev_idle_init (&iw, gcb);
1309 ev_idle_start (&iw);
1310
1311 ev_loop (0);
1312
1313 return 0;
1314}
1315
1316#endif
1317
1318
1319
1320

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines