… | |
… | |
1248 | static int loop_done; |
1248 | static int loop_done; |
1249 | |
1249 | |
1250 | void |
1250 | void |
1251 | ev_loop (EV_P_ int flags) |
1251 | ev_loop (EV_P_ int flags) |
1252 | { |
1252 | { |
1253 | double block; |
|
|
1254 | loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) ? 1 : 0; |
1253 | loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) |
|
|
1254 | ? EVUNLOOP_ONE |
|
|
1255 | : EVUNLOOP_CANCEL; |
1255 | |
1256 | |
1256 | while (activecnt) |
1257 | while (activecnt) |
1257 | { |
1258 | { |
1258 | /* queue check watchers (and execute them) */ |
1259 | /* queue check watchers (and execute them) */ |
1259 | if (expect_false (preparecnt)) |
1260 | if (expect_false (preparecnt)) |
… | |
… | |
1268 | |
1269 | |
1269 | /* update fd-related kernel structures */ |
1270 | /* update fd-related kernel structures */ |
1270 | fd_reify (EV_A); |
1271 | fd_reify (EV_A); |
1271 | |
1272 | |
1272 | /* calculate blocking time */ |
1273 | /* calculate blocking time */ |
|
|
1274 | { |
|
|
1275 | double block; |
1273 | |
1276 | |
1274 | /* we only need this for !monotonic clock or timers, but as we basically |
1277 | if (flags & EVLOOP_NONBLOCK || idlecnt) |
1275 | 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 */ |
1276 | #if EV_USE_MONOTONIC |
1282 | #if EV_USE_MONOTONIC |
1277 | if (expect_true (have_monotonic)) |
1283 | if (expect_true (have_monotonic)) |
1278 | time_update_monotonic (EV_A); |
1284 | time_update_monotonic (EV_A); |
1279 | else |
1285 | else |
1280 | #endif |
1286 | #endif |
1281 | { |
1287 | { |
1282 | ev_rt_now = ev_time (); |
1288 | ev_rt_now = ev_time (); |
1283 | mn_now = ev_rt_now; |
1289 | mn_now = ev_rt_now; |
1284 | } |
1290 | } |
1285 | |
1291 | |
1286 | if (flags & EVLOOP_NONBLOCK || idlecnt) |
|
|
1287 | block = 0.; |
|
|
1288 | else |
|
|
1289 | { |
|
|
1290 | block = MAX_BLOCKTIME; |
1292 | block = MAX_BLOCKTIME; |
1291 | |
1293 | |
1292 | if (timercnt) |
1294 | if (timercnt) |
1293 | { |
1295 | { |
1294 | ev_tstamp to = ((WT)timers [0])->at - mn_now + backend_fudge; |
1296 | ev_tstamp to = ((WT)timers [0])->at - mn_now + backend_fudge; |
1295 | if (block > to) block = to; |
1297 | if (block > to) block = to; |
1296 | } |
1298 | } |
1297 | |
1299 | |
1298 | #if EV_PERIODICS |
1300 | #if EV_PERIODICS |
1299 | if (periodiccnt) |
1301 | if (periodiccnt) |
1300 | { |
1302 | { |
1301 | 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; |
1302 | if (block > to) block = to; |
1304 | if (block > to) block = to; |
1303 | } |
1305 | } |
1304 | #endif |
1306 | #endif |
1305 | |
1307 | |
1306 | if (expect_false (block < 0.)) block = 0.; |
1308 | if (expect_false (block < 0.)) block = 0.; |
1307 | } |
1309 | } |
1308 | |
1310 | |
1309 | backend_poll (EV_A_ block); |
1311 | backend_poll (EV_A_ block); |
|
|
1312 | } |
1310 | |
1313 | |
1311 | /* update ev_rt_now, do magic */ |
1314 | /* update ev_rt_now, do magic */ |
1312 | time_update (EV_A); |
1315 | time_update (EV_A); |
1313 | |
1316 | |
1314 | /* queue pending timers and reschedule them */ |
1317 | /* queue pending timers and reschedule them */ |
… | |
… | |
1329 | |
1332 | |
1330 | if (expect_false (loop_done)) |
1333 | if (expect_false (loop_done)) |
1331 | break; |
1334 | break; |
1332 | } |
1335 | } |
1333 | |
1336 | |
1334 | if (loop_done != 2) |
1337 | if (loop_done == EVUNLOOP_ONE) |
1335 | loop_done = 0; |
1338 | loop_done = EVUNLOOP_CANCEL; |
1336 | } |
1339 | } |
1337 | |
1340 | |
1338 | void |
1341 | void |
1339 | ev_unloop (EV_P_ int how) |
1342 | ev_unloop (EV_P_ int how) |
1340 | { |
1343 | { |