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

Comparing libev/ev.c (file contents):
Revision 1.90 by root, Sun Nov 11 00:05:59 2007 UTC vs.
Revision 1.97 by root, Sun Nov 11 01:53:07 2007 UTC

35 35
36#ifndef EV_STANDALONE 36#ifndef EV_STANDALONE
37# include "config.h" 37# include "config.h"
38 38
39# if HAVE_CLOCK_GETTIME 39# if HAVE_CLOCK_GETTIME
40# ifndef EV_USE_MONOTONIC
40# define EV_USE_MONOTONIC 1 41# define EV_USE_MONOTONIC 1
42# endif
43# ifndef EV_USE_REALTIME
41# define EV_USE_REALTIME 1 44# define EV_USE_REALTIME 1
45# endif
42# endif 46# endif
43 47
44# if HAVE_SELECT && HAVE_SYS_SELECT_H 48# if HAVE_SELECT && HAVE_SYS_SELECT_H && !defined (EV_USE_SELECT)
45# define EV_USE_SELECT 1 49# define EV_USE_SELECT 1
46# endif 50# endif
47 51
48# if HAVE_POLL && HAVE_POLL_H 52# if HAVE_POLL && HAVE_POLL_H && !defined (EV_USE_POLL)
49# define EV_USE_POLL 1 53# define EV_USE_POLL 1
50# endif 54# endif
51 55
52# if HAVE_EPOLL && HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H 56# if HAVE_EPOLL && HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H && !defined (EV_USE_EPOLL)
53# define EV_USE_EPOLL 1 57# define EV_USE_EPOLL 1
54# endif 58# endif
55 59
56# if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H 60# if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H && !defined (EV_USE_KQUEUE)
57# define EV_USE_KQUEUE 1 61# define EV_USE_KQUEUE 1
58# endif 62# endif
59 63
60#endif 64#endif
61 65
249 253
250#endif 254#endif
251 255
252/*****************************************************************************/ 256/*****************************************************************************/
253 257
254inline ev_tstamp 258ev_tstamp
255ev_time (void) 259ev_time (void)
256{ 260{
257#if EV_USE_REALTIME 261#if EV_USE_REALTIME
258 struct timespec ts; 262 struct timespec ts;
259 clock_gettime (CLOCK_REALTIME, &ts); 263 clock_gettime (CLOCK_REALTIME, &ts);
804 array_free (pending, [i]); 808 array_free (pending, [i]);
805 809
806 /* have to use the microsoft-never-gets-it-right macro */ 810 /* have to use the microsoft-never-gets-it-right macro */
807 array_free_microshit (fdchange); 811 array_free_microshit (fdchange);
808 array_free_microshit (timer); 812 array_free_microshit (timer);
813#if EV_PERIODICS
809 array_free_microshit (periodic); 814 array_free_microshit (periodic);
815#endif
810 array_free_microshit (idle); 816 array_free_microshit (idle);
811 array_free_microshit (prepare); 817 array_free_microshit (prepare);
812 array_free_microshit (check); 818 array_free_microshit (check);
813 819
814 method = 0; 820 method = 0;
1001 1007
1002 ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); 1008 ev_feed_event (EV_A_ (W)w, EV_TIMEOUT);
1003 } 1009 }
1004} 1010}
1005 1011
1012#if EV_PERIODICS
1006static void 1013static void
1007periodics_reify (EV_P) 1014periodics_reify (EV_P)
1008{ 1015{
1009 while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now) 1016 while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now)
1010 { 1017 {
1051 1058
1052 /* now rebuild the heap */ 1059 /* now rebuild the heap */
1053 for (i = periodiccnt >> 1; i--; ) 1060 for (i = periodiccnt >> 1; i--; )
1054 downheap ((WT *)periodics, periodiccnt, i); 1061 downheap ((WT *)periodics, periodiccnt, i);
1055} 1062}
1063#endif
1056 1064
1057inline int 1065inline int
1058time_update_monotonic (EV_P) 1066time_update_monotonic (EV_P)
1059{ 1067{
1060 mn_now = get_clock (); 1068 mn_now = get_clock ();
1094 ev_rt_now = ev_time (); 1102 ev_rt_now = ev_time ();
1095 mn_now = get_clock (); 1103 mn_now = get_clock ();
1096 now_floor = mn_now; 1104 now_floor = mn_now;
1097 } 1105 }
1098 1106
1107# if EV_PERIODICS
1099 periodics_reschedule (EV_A); 1108 periodics_reschedule (EV_A);
1109# endif
1100 /* no timer adjustment, as the monotonic clock doesn't jump */ 1110 /* no timer adjustment, as the monotonic clock doesn't jump */
1101 /* timers_reschedule (EV_A_ rtmn_diff - odiff) */ 1111 /* timers_reschedule (EV_A_ rtmn_diff - odiff) */
1102 } 1112 }
1103 } 1113 }
1104 else 1114 else
1106 { 1116 {
1107 ev_rt_now = ev_time (); 1117 ev_rt_now = ev_time ();
1108 1118
1109 if (expect_false (mn_now > ev_rt_now || mn_now < ev_rt_now - MAX_BLOCKTIME - MIN_TIMEJUMP)) 1119 if (expect_false (mn_now > ev_rt_now || mn_now < ev_rt_now - MAX_BLOCKTIME - MIN_TIMEJUMP))
1110 { 1120 {
1121#if EV_PERIODICS
1111 periodics_reschedule (EV_A); 1122 periodics_reschedule (EV_A);
1123#endif
1112 1124
1113 /* adjust timers. this is easy, as the offset is the same for all */ 1125 /* adjust timers. this is easy, as the offset is the same for all */
1114 for (i = 0; i < timercnt; ++i) 1126 for (i = 0; i < timercnt; ++i)
1115 ((WT)timers [i])->at += ev_rt_now - mn_now; 1127 ((WT)timers [i])->at += ev_rt_now - mn_now;
1116 } 1128 }
1179 { 1191 {
1180 ev_tstamp to = ((WT)timers [0])->at - mn_now + method_fudge; 1192 ev_tstamp to = ((WT)timers [0])->at - mn_now + method_fudge;
1181 if (block > to) block = to; 1193 if (block > to) block = to;
1182 } 1194 }
1183 1195
1196#if EV_PERIODICS
1184 if (periodiccnt) 1197 if (periodiccnt)
1185 { 1198 {
1186 ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + method_fudge; 1199 ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + method_fudge;
1187 if (block > to) block = to; 1200 if (block > to) block = to;
1188 } 1201 }
1202#endif
1189 1203
1190 if (block < 0.) block = 0.; 1204 if (block < 0.) block = 0.;
1191 } 1205 }
1192 1206
1193 method_poll (EV_A_ block); 1207 method_poll (EV_A_ block);
1195 /* update ev_rt_now, do magic */ 1209 /* update ev_rt_now, do magic */
1196 time_update (EV_A); 1210 time_update (EV_A);
1197 1211
1198 /* queue pending timers and reschedule them */ 1212 /* queue pending timers and reschedule them */
1199 timers_reify (EV_A); /* relative timers called last */ 1213 timers_reify (EV_A); /* relative timers called last */
1214#if EV_PERIODICS
1200 periodics_reify (EV_A); /* absolute timers called first */ 1215 periodics_reify (EV_A); /* absolute timers called first */
1216#endif
1201 1217
1202 /* queue idle watchers unless io or timers are pending */ 1218 /* queue idle watchers unless io or timers are pending */
1203 if (idlecnt && !any_pending (EV_A)) 1219 if (idlecnt && !any_pending (EV_A))
1204 queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); 1220 queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE);
1205 1221
1337 { 1353 {
1338 timers [((W)w)->active - 1] = timers [timercnt]; 1354 timers [((W)w)->active - 1] = timers [timercnt];
1339 downheap ((WT *)timers, timercnt, ((W)w)->active - 1); 1355 downheap ((WT *)timers, timercnt, ((W)w)->active - 1);
1340 } 1356 }
1341 1357
1342 ((WT)w)->at = w->repeat; 1358 ((WT)w)->at -= mn_now;
1343 1359
1344 ev_stop (EV_A_ (W)w); 1360 ev_stop (EV_A_ (W)w);
1345} 1361}
1346 1362
1347void 1363void
1356 } 1372 }
1357 else if (w->repeat) 1373 else if (w->repeat)
1358 ev_timer_start (EV_A_ w); 1374 ev_timer_start (EV_A_ w);
1359} 1375}
1360 1376
1377#if EV_PERIODICS
1361void 1378void
1362ev_periodic_start (EV_P_ struct ev_periodic *w) 1379ev_periodic_start (EV_P_ struct ev_periodic *w)
1363{ 1380{
1364 if (ev_is_active (w)) 1381 if (ev_is_active (w))
1365 return; 1382 return;
1404{ 1421{
1405 /* TODO: use adjustheap and recalculation */ 1422 /* TODO: use adjustheap and recalculation */
1406 ev_periodic_stop (EV_A_ w); 1423 ev_periodic_stop (EV_A_ w);
1407 ev_periodic_start (EV_A_ w); 1424 ev_periodic_start (EV_A_ w);
1408} 1425}
1426#endif
1409 1427
1410void 1428void
1411ev_idle_start (EV_P_ struct ev_idle *w) 1429ev_idle_start (EV_P_ struct ev_idle *w)
1412{ 1430{
1413 if (ev_is_active (w)) 1431 if (ev_is_active (w))
1464 1482
1465void 1483void
1466ev_check_stop (EV_P_ struct ev_check *w) 1484ev_check_stop (EV_P_ struct ev_check *w)
1467{ 1485{
1468 ev_clear_pending (EV_A_ (W)w); 1486 ev_clear_pending (EV_A_ (W)w);
1469 if (ev_is_active (w)) 1487 if (!ev_is_active (w))
1470 return; 1488 return;
1471 1489
1472 checks [((W)w)->active - 1] = checks [--checkcnt]; 1490 checks [((W)w)->active - 1] = checks [--checkcnt];
1473 ev_stop (EV_A_ (W)w); 1491 ev_stop (EV_A_ (W)w);
1474} 1492}
1535 1553
1536void 1554void
1537ev_child_stop (EV_P_ struct ev_child *w) 1555ev_child_stop (EV_P_ struct ev_child *w)
1538{ 1556{
1539 ev_clear_pending (EV_A_ (W)w); 1557 ev_clear_pending (EV_A_ (W)w);
1540 if (ev_is_active (w)) 1558 if (!ev_is_active (w))
1541 return; 1559 return;
1542 1560
1543 wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); 1561 wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w);
1544 ev_stop (EV_A_ (W)w); 1562 ev_stop (EV_A_ (W)w);
1545} 1563}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines