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

Comparing libev/ev.c (file contents):
Revision 1.133 by root, Fri Nov 23 11:32:22 2007 UTC vs.
Revision 1.135 by root, Sat Nov 24 06:23:27 2007 UTC

397 { 397 {
398 pendings [ABSPRI (w_)][w_->pending - 1].events |= revents; 398 pendings [ABSPRI (w_)][w_->pending - 1].events |= revents;
399 return; 399 return;
400 } 400 }
401 401
402 if (expect_false (!w_->cb))
403 return;
404
402 w_->pending = ++pendingcnt [ABSPRI (w_)]; 405 w_->pending = ++pendingcnt [ABSPRI (w_)];
403 array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], EMPTY2); 406 array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], EMPTY2);
404 pendings [ABSPRI (w_)][w_->pending - 1].w = w_; 407 pendings [ABSPRI (w_)][w_->pending - 1].w = w_;
405 pendings [ABSPRI (w_)][w_->pending - 1].events = revents; 408 pendings [ABSPRI (w_)][w_->pending - 1].events = revents;
406} 409}
813 // flags &= ~EVBACKEND_KQUEUE; for documentation 816 // flags &= ~EVBACKEND_KQUEUE; for documentation
814 flags &= ~EVBACKEND_POLL; 817 flags &= ~EVBACKEND_POLL;
815#endif 818#endif
816 819
817 return flags; 820 return flags;
821}
822
823unsigned int
824ev_embeddable_backends (void)
825{
826 return EVBACKEND_EPOLL
827 | EVBACKEND_KQUEUE
828 | EVBACKEND_PORT;
818} 829}
819 830
820unsigned int 831unsigned int
821ev_backend (EV_P) 832ev_backend (EV_P)
822{ 833{
1237static int loop_done; 1248static int loop_done;
1238 1249
1239void 1250void
1240ev_loop (EV_P_ int flags) 1251ev_loop (EV_P_ int flags)
1241{ 1252{
1242 double block;
1243 loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) ? 1 : 0; 1253 loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK)
1254 ? EVUNLOOP_ONE
1255 : EVUNLOOP_CANCEL;
1244 1256
1245 while (activecnt) 1257 while (activecnt)
1246 { 1258 {
1247 /* queue check watchers (and execute them) */ 1259 /* queue check watchers (and execute them) */
1248 if (expect_false (preparecnt)) 1260 if (expect_false (preparecnt))
1257 1269
1258 /* update fd-related kernel structures */ 1270 /* update fd-related kernel structures */
1259 fd_reify (EV_A); 1271 fd_reify (EV_A);
1260 1272
1261 /* calculate blocking time */ 1273 /* calculate blocking time */
1274 {
1275 double block;
1262 1276
1263 /* we only need this for !monotonic clock or timers, but as we basically 1277 if (flags & EVLOOP_NONBLOCK || idlecnt)
1264 always have timers, we just calculate it always */ 1278 block = 0.; /* do not block at all */
1279 else
1280 {
1281 /* update time to cancel out callback processing overhead */
1265#if EV_USE_MONOTONIC 1282#if EV_USE_MONOTONIC
1266 if (expect_true (have_monotonic)) 1283 if (expect_true (have_monotonic))
1267 time_update_monotonic (EV_A); 1284 time_update_monotonic (EV_A);
1268 else 1285 else
1269#endif 1286#endif
1270 { 1287 {
1271 ev_rt_now = ev_time (); 1288 ev_rt_now = ev_time ();
1272 mn_now = ev_rt_now; 1289 mn_now = ev_rt_now;
1273 } 1290 }
1274 1291
1275 if (flags & EVLOOP_NONBLOCK || idlecnt)
1276 block = 0.;
1277 else
1278 {
1279 block = MAX_BLOCKTIME; 1292 block = MAX_BLOCKTIME;
1280 1293
1281 if (timercnt) 1294 if (timercnt)
1282 { 1295 {
1283 ev_tstamp to = ((WT)timers [0])->at - mn_now + backend_fudge; 1296 ev_tstamp to = ((WT)timers [0])->at - mn_now + backend_fudge;
1284 if (block > to) block = to; 1297 if (block > to) block = to;
1285 } 1298 }
1286 1299
1287#if EV_PERIODICS 1300#if EV_PERIODICS
1288 if (periodiccnt) 1301 if (periodiccnt)
1289 { 1302 {
1290 ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + backend_fudge; 1303 ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + backend_fudge;
1291 if (block > to) block = to; 1304 if (block > to) block = to;
1292 } 1305 }
1293#endif 1306#endif
1294 1307
1295 if (expect_false (block < 0.)) block = 0.; 1308 if (expect_false (block < 0.)) block = 0.;
1296 } 1309 }
1297 1310
1298 backend_poll (EV_A_ block); 1311 backend_poll (EV_A_ block);
1312 }
1299 1313
1300 /* update ev_rt_now, do magic */ 1314 /* update ev_rt_now, do magic */
1301 time_update (EV_A); 1315 time_update (EV_A);
1302 1316
1303 /* queue pending timers and reschedule them */ 1317 /* queue pending timers and reschedule them */
1318 1332
1319 if (expect_false (loop_done)) 1333 if (expect_false (loop_done))
1320 break; 1334 break;
1321 } 1335 }
1322 1336
1323 if (loop_done != 2) 1337 if (loop_done == EVUNLOOP_ONE)
1324 loop_done = 0; 1338 loop_done = EVUNLOOP_CANCEL;
1325} 1339}
1326 1340
1327void 1341void
1328ev_unloop (EV_P_ int how) 1342ev_unloop (EV_P_ int how)
1329{ 1343{
1659 1673
1660 wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); 1674 wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w);
1661 ev_stop (EV_A_ (W)w); 1675 ev_stop (EV_A_ (W)w);
1662} 1676}
1663 1677
1678#if EV_MULTIPLICITY
1679static void
1680embed_cb (EV_P_ struct ev_io *io, int revents)
1681{
1682 struct ev_embed *w = (struct ev_embed *)(((char *)io) - offsetof (struct ev_embed, io));
1683
1684 ev_feed_event (EV_A_ (W)w, EV_EMBED);
1685 ev_loop (w->loop, EVLOOP_NONBLOCK);
1686}
1687
1688void
1689ev_embed_start (EV_P_ struct ev_embed *w)
1690{
1691 if (expect_false (ev_is_active (w)))
1692 return;
1693
1694 {
1695 struct ev_loop *loop = w->loop;
1696 assert (("loop to be embedded is not embeddable", backend & ev_embeddable_backends ()));
1697 ev_io_init (&w->io, embed_cb, backend_fd, EV_READ);
1698 }
1699
1700 ev_io_start (EV_A_ &w->io);
1701 ev_start (EV_A_ (W)w, 1);
1702}
1703
1704void
1705ev_embed_stop (EV_P_ struct ev_embed *w)
1706{
1707 ev_clear_pending (EV_A_ (W)w);
1708 if (expect_false (!ev_is_active (w)))
1709 return;
1710
1711 ev_io_stop (EV_A_ &w->io);
1712 ev_stop (EV_A_ (W)w);
1713}
1714#endif
1715
1664/*****************************************************************************/ 1716/*****************************************************************************/
1665 1717
1666struct ev_once 1718struct ev_once
1667{ 1719{
1668 struct ev_io io; 1720 struct ev_io io;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines