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

Comparing libev/ev.c (file contents):
Revision 1.230 by root, Fri May 2 08:13:16 2008 UTC vs.
Revision 1.234 by root, Tue May 6 23:42:16 2008 UTC

520 } 520 }
521} 521}
522 522
523/*****************************************************************************/ 523/*****************************************************************************/
524 524
525#define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */
526
525int inline_size 527int inline_size
526array_nextsize (int elem, int cur, int cnt) 528array_nextsize (int elem, int cur, int cnt)
527{ 529{
528 int ncur = cur + 1; 530 int ncur = cur + 1;
529 531
530 do 532 do
531 ncur <<= 1; 533 ncur <<= 1;
532 while (cnt > ncur); 534 while (cnt > ncur);
533 535
534 /* if size > 4096, round to 4096 - 4 * longs to accomodate malloc overhead */ 536 /* if size is large, round to MALLOC_ROUND - 4 * longs to accomodate malloc overhead */
535 if (elem * ncur > 4096) 537 if (elem * ncur > MALLOC_ROUND - sizeof (void *) * 4)
536 { 538 {
537 ncur *= elem; 539 ncur *= elem;
538 ncur = (ncur + elem + 4095 + sizeof (void *) * 4) & ~4095; 540 ncur = (ncur + elem + (MALLOC_ROUND - 1) + sizeof (void *) * 4) & ~(MALLOC_ROUND - 1);
539 ncur = ncur - sizeof (void *) * 4; 541 ncur = ncur - sizeof (void *) * 4;
540 ncur /= elem; 542 ncur /= elem;
541 } 543 }
542 544
543 return ncur; 545 return ncur;
912pipecb (EV_P_ ev_io *iow, int revents) 914pipecb (EV_P_ ev_io *iow, int revents)
913{ 915{
914#if EV_USE_EVENTFD 916#if EV_USE_EVENTFD
915 if (evfd >= 0) 917 if (evfd >= 0)
916 { 918 {
917 uint64_t counter = 1; 919 uint64_t counter;
918 read (evfd, &counter, sizeof (uint64_t)); 920 read (evfd, &counter, sizeof (uint64_t));
919 } 921 }
920 else 922 else
921#endif 923#endif
922 { 924 {
1368void 1370void
1369ev_loop_fork (EV_P) 1371ev_loop_fork (EV_P)
1370{ 1372{
1371 postfork = 1; /* must be in line with ev_default_fork */ 1373 postfork = 1; /* must be in line with ev_default_fork */
1372} 1374}
1373
1374#endif 1375#endif
1375 1376
1376#if EV_MULTIPLICITY 1377#if EV_MULTIPLICITY
1377struct ev_loop * 1378struct ev_loop *
1378ev_default_loop_init (unsigned int flags) 1379ev_default_loop_init (unsigned int flags)
1458 p->w->pending = 0; 1459 p->w->pending = 0;
1459 EV_CB_INVOKE (p->w, p->events); 1460 EV_CB_INVOKE (p->w, p->events);
1460 } 1461 }
1461 } 1462 }
1462} 1463}
1464
1465#if EV_IDLE_ENABLE
1466void inline_size
1467idle_reify (EV_P)
1468{
1469 if (expect_false (idleall))
1470 {
1471 int pri;
1472
1473 for (pri = NUMPRI; pri--; )
1474 {
1475 if (pendingcnt [pri])
1476 break;
1477
1478 if (idlecnt [pri])
1479 {
1480 queue_events (EV_A_ (W *)idles [pri], idlecnt [pri], EV_IDLE);
1481 break;
1482 }
1483 }
1484 }
1485}
1486#endif
1463 1487
1464void inline_size 1488void inline_size
1465timers_reify (EV_P) 1489timers_reify (EV_P)
1466{ 1490{
1467 while (timercnt && ev_at (timers [1]) <= mn_now) 1491 while (timercnt && ev_at (timers [1]) <= mn_now)
1523periodics_reschedule (EV_P) 1547periodics_reschedule (EV_P)
1524{ 1548{
1525 int i; 1549 int i;
1526 1550
1527 /* adjust periodics after time jump */ 1551 /* adjust periodics after time jump */
1528 for (i = 0; i < periodiccnt; ++i) 1552 for (i = 1; i <= periodiccnt; ++i)
1529 { 1553 {
1530 ev_periodic *w = (ev_periodic *)periodics [i]; 1554 ev_periodic *w = (ev_periodic *)periodics [i];
1531 1555
1532 if (w->reschedule_cb) 1556 if (w->reschedule_cb)
1533 ev_at (w) = w->reschedule_cb (w, ev_rt_now); 1557 ev_at (w) = w->reschedule_cb (w, ev_rt_now);
1536 } 1560 }
1537 1561
1538 /* now rebuild the heap */ 1562 /* now rebuild the heap */
1539 for (i = periodiccnt >> 1; i--; ) 1563 for (i = periodiccnt >> 1; i--; )
1540 downheap (periodics, periodiccnt, i); 1564 downheap (periodics, periodiccnt, i);
1541}
1542#endif
1543
1544#if EV_IDLE_ENABLE
1545void inline_size
1546idle_reify (EV_P)
1547{
1548 if (expect_false (idleall))
1549 {
1550 int pri;
1551
1552 for (pri = NUMPRI; pri--; )
1553 {
1554 if (pendingcnt [pri])
1555 break;
1556
1557 if (idlecnt [pri])
1558 {
1559 queue_events (EV_A_ (W *)idles [pri], idlecnt [pri], EV_IDLE);
1560 break;
1561 }
1562 }
1563 }
1564} 1565}
1565#endif 1566#endif
1566 1567
1567void inline_speed 1568void inline_speed
1568time_update (EV_P_ ev_tstamp max_block) 1569time_update (EV_P_ ev_tstamp max_block)
1597 */ 1598 */
1598 for (i = 4; --i; ) 1599 for (i = 4; --i; )
1599 { 1600 {
1600 rtmn_diff = ev_rt_now - mn_now; 1601 rtmn_diff = ev_rt_now - mn_now;
1601 1602
1602 if (fabs (odiff - rtmn_diff) < MIN_TIMEJUMP) 1603 if (expect_true (fabs (odiff - rtmn_diff) < MIN_TIMEJUMP))
1603 return; /* all is well */ 1604 return; /* all is well */
1604 1605
1605 ev_rt_now = ev_time (); 1606 ev_rt_now = ev_time ();
1606 mn_now = get_clock (); 1607 mn_now = get_clock ();
1607 now_floor = mn_now; 1608 now_floor = mn_now;
2114 if (w->wd < 0) 2115 if (w->wd < 0)
2115 { 2116 {
2116 ev_timer_start (EV_A_ &w->timer); /* this is not race-free, so we still need to recheck periodically */ 2117 ev_timer_start (EV_A_ &w->timer); /* this is not race-free, so we still need to recheck periodically */
2117 2118
2118 /* monitor some parent directory for speedup hints */ 2119 /* monitor some parent directory for speedup hints */
2120 /* note that exceeding the hardcoded limit is not a correctness issue, */
2121 /* but an efficiency issue only */
2119 if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096) 2122 if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096)
2120 { 2123 {
2121 char path [4096]; 2124 char path [4096];
2122 strcpy (path, w->path); 2125 strcpy (path, w->path);
2123 2126

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines