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

Comparing libev/ev.c (file contents):
Revision 1.159 by root, Sat Dec 1 19:48:36 2007 UTC vs.
Revision 1.163 by root, Wed Dec 5 13:54:36 2007 UTC

396{ 396{
397 return ev_rt_now; 397 return ev_rt_now;
398} 398}
399#endif 399#endif
400 400
401#define array_roundsize(type,n) (((n) | 4) & ~3) 401int inline_size
402array_nextsize (int elem, int cur, int cnt)
403{
404 int ncur = cur + 1;
405
406 do
407 ncur <<= 1;
408 while (cnt > ncur);
409
410 /* if size > 4096, round to 4096 - 4 * longs to accomodate malloc overhead */
411 if (elem * ncur > 4096)
412 {
413 ncur *= elem;
414 ncur = (ncur + elem + 4095 + sizeof (void *) * 4) & ~4095;
415 ncur = ncur - sizeof (void *) * 4;
416 ncur /= elem;
417 }
418
419 return ncur;
420}
421
422inline_speed void *
423array_realloc (int elem, void *base, int *cur, int cnt)
424{
425 *cur = array_nextsize (elem, *cur, cnt);
426 return ev_realloc (base, elem * *cur);
427}
402 428
403#define array_needsize(type,base,cur,cnt,init) \ 429#define array_needsize(type,base,cur,cnt,init) \
404 if (expect_false ((cnt) > cur)) \ 430 if (expect_false ((cnt) > (cur))) \
405 { \ 431 { \
406 int newcnt = cur; \ 432 int ocur_ = (cur); \
407 do \ 433 (base) = (type *)array_realloc \
408 { \ 434 (sizeof (type), (base), &(cur), (cnt)); \
409 newcnt = array_roundsize (type, newcnt << 1); \ 435 init ((base) + (ocur_), (cur) - ocur_); \
410 } \
411 while ((cnt) > newcnt); \
412 \
413 base = (type *)ev_realloc (base, sizeof (type) * (newcnt));\
414 init (base + cur, newcnt - cur); \
415 cur = newcnt; \
416 } 436 }
417 437
438#if 0
418#define array_slim(type,stem) \ 439#define array_slim(type,stem) \
419 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ 440 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \
420 { \ 441 { \
421 stem ## max = array_roundsize (stem ## cnt >> 1); \ 442 stem ## max = array_roundsize (stem ## cnt >> 1); \
422 base = (type *)ev_realloc (base, sizeof (type) * (stem ## max));\ 443 base = (type *)ev_realloc (base, sizeof (type) * (stem ## max));\
423 fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\ 444 fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\
424 } 445 }
446#endif
425 447
426#define array_free(stem, idx) \ 448#define array_free(stem, idx) \
427 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; 449 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0;
428 450
429/*****************************************************************************/ 451/*****************************************************************************/
884 906
885unsigned int 907unsigned int
886ev_backend (EV_P) 908ev_backend (EV_P)
887{ 909{
888 return backend; 910 return backend;
911}
912
913unsigned int
914ev_loop_count (EV_P)
915{
916 return loop_count;
889} 917}
890 918
891static void noinline 919static void noinline
892loop_init (EV_P_ unsigned int flags) 920loop_init (EV_P_ unsigned int flags)
893{ 921{
1342 ? EVUNLOOP_ONE 1370 ? EVUNLOOP_ONE
1343 : EVUNLOOP_CANCEL; 1371 : EVUNLOOP_CANCEL;
1344 1372
1345 call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */ 1373 call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */
1346 1374
1347 for (;;) 1375 do
1348 { 1376 {
1349#ifndef _WIN32 1377#ifndef _WIN32
1350 if (expect_false (curpid)) /* penalise the forking check even more */ 1378 if (expect_false (curpid)) /* penalise the forking check even more */
1351 if (expect_false (getpid () != curpid)) 1379 if (expect_false (getpid () != curpid))
1352 { 1380 {
1384 1412
1385 /* calculate blocking time */ 1413 /* calculate blocking time */
1386 { 1414 {
1387 ev_tstamp block; 1415 ev_tstamp block;
1388 1416
1389 if (flags & EVLOOP_NONBLOCK || idlecnt) 1417 if (expect_false (flags & EVLOOP_NONBLOCK || idlecnt || !activecnt))
1390 block = 0.; /* do not block at all */ 1418 block = 0.; /* do not block at all */
1391 else 1419 else
1392 { 1420 {
1393 /* update time to cancel out callback processing overhead */ 1421 /* update time to cancel out callback processing overhead */
1394#if EV_USE_MONOTONIC 1422#if EV_USE_MONOTONIC
1418#endif 1446#endif
1419 1447
1420 if (expect_false (block < 0.)) block = 0.; 1448 if (expect_false (block < 0.)) block = 0.;
1421 } 1449 }
1422 1450
1451 ++loop_count;
1423 backend_poll (EV_A_ block); 1452 backend_poll (EV_A_ block);
1424 } 1453 }
1425 1454
1426 /* update ev_rt_now, do magic */ 1455 /* update ev_rt_now, do magic */
1427 time_update (EV_A); 1456 time_update (EV_A);
1440 if (expect_false (checkcnt)) 1469 if (expect_false (checkcnt))
1441 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); 1470 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK);
1442 1471
1443 call_pending (EV_A); 1472 call_pending (EV_A);
1444 1473
1445 if (expect_false (loop_done))
1446 break;
1447 } 1474 }
1475 while (expect_true (activecnt && !loop_done));
1448 1476
1449 if (loop_done == EVUNLOOP_ONE) 1477 if (loop_done == EVUNLOOP_ONE)
1450 loop_done = EVUNLOOP_CANCEL; 1478 loop_done = EVUNLOOP_CANCEL;
1451} 1479}
1452 1480

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines