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

Comparing libev/ev.c (file contents):
Revision 1.221 by root, Sun Apr 6 12:44:49 2008 UTC vs.
Revision 1.233 by root, Tue May 6 23:34:16 2008 UTC

269#endif 269#endif
270 270
271#if EV_USE_EVENTFD 271#if EV_USE_EVENTFD
272/* our minimum requirement is glibc 2.7 which has the stub, but not the header */ 272/* our minimum requirement is glibc 2.7 which has the stub, but not the header */
273# include <stdint.h> 273# include <stdint.h>
274# ifdef __cplusplus
275extern "C" {
276# endif
274int eventfd (unsigned int initval, int flags); 277int eventfd (unsigned int initval, int flags);
278# ifdef __cplusplus
279}
280# endif
275#endif 281#endif
276 282
277/**/ 283/**/
278 284
279/* 285/*
294# define expect(expr,value) __builtin_expect ((expr),(value)) 300# define expect(expr,value) __builtin_expect ((expr),(value))
295# define noinline __attribute__ ((noinline)) 301# define noinline __attribute__ ((noinline))
296#else 302#else
297# define expect(expr,value) (expr) 303# define expect(expr,value) (expr)
298# define noinline 304# define noinline
299# if __STDC_VERSION__ < 199901L 305# if __STDC_VERSION__ < 199901L && __GNUC__ < 2
300# define inline 306# define inline
301# endif 307# endif
302#endif 308#endif
303 309
304#define expect_false(expr) expect ((expr) != 0, 0) 310#define expect_false(expr) expect ((expr) != 0, 0)
319 325
320typedef ev_watcher *W; 326typedef ev_watcher *W;
321typedef ev_watcher_list *WL; 327typedef ev_watcher_list *WL;
322typedef ev_watcher_time *WT; 328typedef ev_watcher_time *WT;
323 329
330#define ev_active(w) ((W)(w))->active
331#define ev_at(w) ((WT)(w))->at
332
324#if EV_USE_MONOTONIC 333#if EV_USE_MONOTONIC
325/* sig_atomic_t is used to avoid per-thread variables or locking but still */ 334/* sig_atomic_t is used to avoid per-thread variables or locking but still */
326/* giving it a reasonably high chance of working on typical architetcures */ 335/* giving it a reasonably high chance of working on typical architetcures */
327static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ 336static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */
328#endif 337#endif
354 perror (msg); 363 perror (msg);
355 abort (); 364 abort ();
356 } 365 }
357} 366}
358 367
368static void *
369ev_realloc_emul (void *ptr, long size)
370{
371 /* some systems, notably openbsd and darwin, fail to properly
372 * implement realloc (x, 0) (as required by both ansi c-98 and
373 * the single unix specification, so work around them here.
374 */
375
376 if (size)
377 return realloc (ptr, size);
378
379 free (ptr);
380 return 0;
381}
382
359static void *(*alloc)(void *ptr, long size); 383static void *(*alloc)(void *ptr, long size) = ev_realloc_emul;
360 384
361void 385void
362ev_set_allocator (void *(*cb)(void *ptr, long size)) 386ev_set_allocator (void *(*cb)(void *ptr, long size))
363{ 387{
364 alloc = cb; 388 alloc = cb;
365} 389}
366 390
367inline_speed void * 391inline_speed void *
368ev_realloc (void *ptr, long size) 392ev_realloc (void *ptr, long size)
369{ 393{
370 ptr = alloc ? alloc (ptr, size) : realloc (ptr, size); 394 ptr = alloc (ptr, size);
371 395
372 if (!ptr && size) 396 if (!ptr && size)
373 { 397 {
374 fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); 398 fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size);
375 abort (); 399 abort ();
496 } 520 }
497} 521}
498 522
499/*****************************************************************************/ 523/*****************************************************************************/
500 524
525#define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */
526
501int inline_size 527int inline_size
502array_nextsize (int elem, int cur, int cnt) 528array_nextsize (int elem, int cur, int cnt)
503{ 529{
504 int ncur = cur + 1; 530 int ncur = cur + 1;
505 531
506 do 532 do
507 ncur <<= 1; 533 ncur <<= 1;
508 while (cnt > ncur); 534 while (cnt > ncur);
509 535
510 /* 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 */
511 if (elem * ncur > 4096) 537 if (elem * ncur > MALLOC_ROUND - sizeof (void *) * 4)
512 { 538 {
513 ncur *= elem; 539 ncur *= elem;
514 ncur = (ncur + elem + 4095 + sizeof (void *) * 4) & ~4095; 540 ncur = (ncur + elem + (MALLOC_ROUND - 1) + sizeof (void *) * 4) & ~(MALLOC_ROUND - 1);
515 ncur = ncur - sizeof (void *) * 4; 541 ncur = ncur - sizeof (void *) * 4;
516 ncur /= elem; 542 ncur /= elem;
517 } 543 }
518 544
519 return ncur; 545 return ncur;
733 } 759 }
734} 760}
735 761
736/*****************************************************************************/ 762/*****************************************************************************/
737 763
764/* towards the root */
738void inline_speed 765void inline_speed
739upheap (WT *heap, int k) 766upheap (WT *heap, int k)
740{ 767{
741 WT w = heap [k]; 768 WT w = heap [k];
742 769
743 while (k) 770 for (;;)
744 { 771 {
745 int p = (k - 1) >> 1; 772 int p = k >> 1;
746 773
774 /* maybe we could use a dummy element at heap [0]? */
747 if (heap [p]->at <= w->at) 775 if (!p || heap [p]->at <= w->at)
748 break; 776 break;
749 777
750 heap [k] = heap [p]; 778 heap [k] = heap [p];
751 ((W)heap [k])->active = k + 1; 779 ev_active (heap [k]) = k;
752 k = p; 780 k = p;
753 } 781 }
754 782
755 heap [k] = w; 783 heap [k] = w;
756 ((W)heap [k])->active = k + 1; 784 ev_active (heap [k]) = k;
757} 785}
758 786
787/* away from the root */
759void inline_speed 788void inline_speed
760downheap (WT *heap, int N, int k) 789downheap (WT *heap, int N, int k)
761{ 790{
762 WT w = heap [k]; 791 WT w = heap [k];
763 792
764 for (;;) 793 for (;;)
765 { 794 {
766 int c = (k << 1) + 1; 795 int c = k << 1;
767 796
768 if (c >= N) 797 if (c > N)
769 break; 798 break;
770 799
771 c += c + 1 < N && heap [c]->at > heap [c + 1]->at 800 c += c < N && heap [c]->at > heap [c + 1]->at
772 ? 1 : 0; 801 ? 1 : 0;
773 802
774 if (w->at <= heap [c]->at) 803 if (w->at <= heap [c]->at)
775 break; 804 break;
776 805
777 heap [k] = heap [c]; 806 heap [k] = heap [c];
778 ((W)heap [k])->active = k + 1; 807 ev_active (heap [k]) = k;
779 808
780 k = c; 809 k = c;
781 } 810 }
782 811
783 heap [k] = w; 812 heap [k] = w;
784 ((W)heap [k])->active = k + 1; 813 ev_active (heap [k]) = k;
785} 814}
786 815
787void inline_size 816void inline_size
788adjustheap (WT *heap, int N, int k) 817adjustheap (WT *heap, int N, int k)
789{ 818{
885pipecb (EV_P_ ev_io *iow, int revents) 914pipecb (EV_P_ ev_io *iow, int revents)
886{ 915{
887#if EV_USE_EVENTFD 916#if EV_USE_EVENTFD
888 if (evfd >= 0) 917 if (evfd >= 0)
889 { 918 {
890 uint64_t counter = 1; 919 uint64_t counter;
891 read (evfd, &counter, sizeof (uint64_t)); 920 read (evfd, &counter, sizeof (uint64_t));
892 } 921 }
893 else 922 else
894#endif 923#endif
895 { 924 {
1164 if (!(flags & EVFLAG_NOENV) 1193 if (!(flags & EVFLAG_NOENV)
1165 && !enable_secure () 1194 && !enable_secure ()
1166 && getenv ("LIBEV_FLAGS")) 1195 && getenv ("LIBEV_FLAGS"))
1167 flags = atoi (getenv ("LIBEV_FLAGS")); 1196 flags = atoi (getenv ("LIBEV_FLAGS"));
1168 1197
1169 if (!(flags & 0x0000ffffUL)) 1198 if (!(flags & 0x0000ffffU))
1170 flags |= ev_recommended_backends (); 1199 flags |= ev_recommended_backends ();
1171 1200
1172#if EV_USE_PORT 1201#if EV_USE_PORT
1173 if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); 1202 if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags);
1174#endif 1203#endif
1262#endif 1291#endif
1263 1292
1264 backend = 0; 1293 backend = 0;
1265} 1294}
1266 1295
1296#if EV_USE_INOTIFY
1267void inline_size infy_fork (EV_P); 1297void inline_size infy_fork (EV_P);
1298#endif
1268 1299
1269void inline_size 1300void inline_size
1270loop_fork (EV_P) 1301loop_fork (EV_P)
1271{ 1302{
1272#if EV_USE_PORT 1303#if EV_USE_PORT
1433} 1464}
1434 1465
1435void inline_size 1466void inline_size
1436timers_reify (EV_P) 1467timers_reify (EV_P)
1437{ 1468{
1438 while (timercnt && ((WT)timers [0])->at <= mn_now) 1469 while (timercnt && ev_at (timers [1]) <= mn_now)
1439 { 1470 {
1440 ev_timer *w = (ev_timer *)timers [0]; 1471 ev_timer *w = (ev_timer *)timers [1];
1441 1472
1442 /*assert (("inactive timer on timer heap detected", ev_is_active (w)));*/ 1473 /*assert (("inactive timer on timer heap detected", ev_is_active (w)));*/
1443 1474
1444 /* first reschedule or stop timer */ 1475 /* first reschedule or stop timer */
1445 if (w->repeat) 1476 if (w->repeat)
1446 { 1477 {
1447 assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.)); 1478 assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.));
1448 1479
1449 ((WT)w)->at += w->repeat; 1480 ev_at (w) += w->repeat;
1450 if (((WT)w)->at < mn_now) 1481 if (ev_at (w) < mn_now)
1451 ((WT)w)->at = mn_now; 1482 ev_at (w) = mn_now;
1452 1483
1453 downheap (timers, timercnt, 0); 1484 downheap (timers, timercnt, 1);
1454 } 1485 }
1455 else 1486 else
1456 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ 1487 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */
1457 1488
1458 ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); 1489 ev_feed_event (EV_A_ (W)w, EV_TIMEOUT);
1461 1492
1462#if EV_PERIODIC_ENABLE 1493#if EV_PERIODIC_ENABLE
1463void inline_size 1494void inline_size
1464periodics_reify (EV_P) 1495periodics_reify (EV_P)
1465{ 1496{
1466 while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now) 1497 while (periodiccnt && ev_at (periodics [1]) <= ev_rt_now)
1467 { 1498 {
1468 ev_periodic *w = (ev_periodic *)periodics [0]; 1499 ev_periodic *w = (ev_periodic *)periodics [1];
1469 1500
1470 /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/ 1501 /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/
1471 1502
1472 /* first reschedule or stop timer */ 1503 /* first reschedule or stop timer */
1473 if (w->reschedule_cb) 1504 if (w->reschedule_cb)
1474 { 1505 {
1475 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + TIME_EPSILON); 1506 ev_at (w) = w->reschedule_cb (w, ev_rt_now + TIME_EPSILON);
1476 assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now)); 1507 assert (("ev_periodic reschedule callback returned time in the past", ev_at (w) > ev_rt_now));
1477 downheap (periodics, periodiccnt, 0); 1508 downheap (periodics, periodiccnt, 1);
1478 } 1509 }
1479 else if (w->interval) 1510 else if (w->interval)
1480 { 1511 {
1481 ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; 1512 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
1482 if (((WT)w)->at - ev_rt_now <= TIME_EPSILON) ((WT)w)->at += w->interval; 1513 if (ev_at (w) - ev_rt_now <= TIME_EPSILON) ev_at (w) += w->interval;
1483 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > ev_rt_now)); 1514 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ev_at (w) > ev_rt_now));
1484 downheap (periodics, periodiccnt, 0); 1515 downheap (periodics, periodiccnt, 1);
1485 } 1516 }
1486 else 1517 else
1487 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ 1518 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */
1488 1519
1489 ev_feed_event (EV_A_ (W)w, EV_PERIODIC); 1520 ev_feed_event (EV_A_ (W)w, EV_PERIODIC);
1494periodics_reschedule (EV_P) 1525periodics_reschedule (EV_P)
1495{ 1526{
1496 int i; 1527 int i;
1497 1528
1498 /* adjust periodics after time jump */ 1529 /* adjust periodics after time jump */
1499 for (i = 0; i < periodiccnt; ++i) 1530 for (i = 1; i <= periodiccnt; ++i)
1500 { 1531 {
1501 ev_periodic *w = (ev_periodic *)periodics [i]; 1532 ev_periodic *w = (ev_periodic *)periodics [i];
1502 1533
1503 if (w->reschedule_cb) 1534 if (w->reschedule_cb)
1504 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); 1535 ev_at (w) = w->reschedule_cb (w, ev_rt_now);
1505 else if (w->interval) 1536 else if (w->interval)
1506 ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; 1537 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
1507 } 1538 }
1508 1539
1509 /* now rebuild the heap */ 1540 /* now rebuild the heap */
1510 for (i = periodiccnt >> 1; i--; ) 1541 for (i = periodiccnt >> 1; i--; )
1511 downheap (periodics, periodiccnt, i); 1542 downheap (periodics, periodiccnt, i);
1593 { 1624 {
1594#if EV_PERIODIC_ENABLE 1625#if EV_PERIODIC_ENABLE
1595 periodics_reschedule (EV_A); 1626 periodics_reschedule (EV_A);
1596#endif 1627#endif
1597 /* adjust timers. this is easy, as the offset is the same for all of them */ 1628 /* adjust timers. this is easy, as the offset is the same for all of them */
1598 for (i = 0; i < timercnt; ++i) 1629 for (i = 1; i <= timercnt; ++i)
1599 ((WT)timers [i])->at += ev_rt_now - mn_now; 1630 ev_at (timers [i]) += ev_rt_now - mn_now;
1600 } 1631 }
1601 1632
1602 mn_now = ev_rt_now; 1633 mn_now = ev_rt_now;
1603 } 1634 }
1604} 1635}
1674 1705
1675 waittime = MAX_BLOCKTIME; 1706 waittime = MAX_BLOCKTIME;
1676 1707
1677 if (timercnt) 1708 if (timercnt)
1678 { 1709 {
1679 ev_tstamp to = ((WT)timers [0])->at - mn_now + backend_fudge; 1710 ev_tstamp to = ev_at (timers [1]) - mn_now + backend_fudge;
1680 if (waittime > to) waittime = to; 1711 if (waittime > to) waittime = to;
1681 } 1712 }
1682 1713
1683#if EV_PERIODIC_ENABLE 1714#if EV_PERIODIC_ENABLE
1684 if (periodiccnt) 1715 if (periodiccnt)
1685 { 1716 {
1686 ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + backend_fudge; 1717 ev_tstamp to = ev_at (periodics [1]) - ev_rt_now + backend_fudge;
1687 if (waittime > to) waittime = to; 1718 if (waittime > to) waittime = to;
1688 } 1719 }
1689#endif 1720#endif
1690 1721
1691 if (expect_false (waittime < timeout_blocktime)) 1722 if (expect_false (waittime < timeout_blocktime))
1857ev_timer_start (EV_P_ ev_timer *w) 1888ev_timer_start (EV_P_ ev_timer *w)
1858{ 1889{
1859 if (expect_false (ev_is_active (w))) 1890 if (expect_false (ev_is_active (w)))
1860 return; 1891 return;
1861 1892
1862 ((WT)w)->at += mn_now; 1893 ev_at (w) += mn_now;
1863 1894
1864 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); 1895 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.));
1865 1896
1866 ev_start (EV_A_ (W)w, ++timercnt); 1897 ev_start (EV_A_ (W)w, ++timercnt);
1867 array_needsize (WT, timers, timermax, timercnt, EMPTY2); 1898 array_needsize (WT, timers, timermax, timercnt + 1, EMPTY2);
1868 timers [timercnt - 1] = (WT)w; 1899 timers [timercnt] = (WT)w;
1869 upheap (timers, timercnt - 1); 1900 upheap (timers, timercnt);
1870 1901
1871 /*assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));*/ 1902 /*assert (("internal timer heap corruption", timers [ev_active (w)] == w));*/
1872} 1903}
1873 1904
1874void noinline 1905void noinline
1875ev_timer_stop (EV_P_ ev_timer *w) 1906ev_timer_stop (EV_P_ ev_timer *w)
1876{ 1907{
1877 clear_pending (EV_A_ (W)w); 1908 clear_pending (EV_A_ (W)w);
1878 if (expect_false (!ev_is_active (w))) 1909 if (expect_false (!ev_is_active (w)))
1879 return; 1910 return;
1880 1911
1881 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == (WT)w));
1882
1883 { 1912 {
1884 int active = ((W)w)->active; 1913 int active = ev_active (w);
1885 1914
1915 assert (("internal timer heap corruption", timers [active] == (WT)w));
1916
1886 if (expect_true (--active < --timercnt)) 1917 if (expect_true (active < timercnt))
1887 { 1918 {
1888 timers [active] = timers [timercnt]; 1919 timers [active] = timers [timercnt];
1889 adjustheap (timers, timercnt, active); 1920 adjustheap (timers, timercnt, active);
1890 } 1921 }
1922
1923 --timercnt;
1891 } 1924 }
1892 1925
1893 ((WT)w)->at -= mn_now; 1926 ev_at (w) -= mn_now;
1894 1927
1895 ev_stop (EV_A_ (W)w); 1928 ev_stop (EV_A_ (W)w);
1896} 1929}
1897 1930
1898void noinline 1931void noinline
1900{ 1933{
1901 if (ev_is_active (w)) 1934 if (ev_is_active (w))
1902 { 1935 {
1903 if (w->repeat) 1936 if (w->repeat)
1904 { 1937 {
1905 ((WT)w)->at = mn_now + w->repeat; 1938 ev_at (w) = mn_now + w->repeat;
1906 adjustheap (timers, timercnt, ((W)w)->active - 1); 1939 adjustheap (timers, timercnt, ev_active (w));
1907 } 1940 }
1908 else 1941 else
1909 ev_timer_stop (EV_A_ w); 1942 ev_timer_stop (EV_A_ w);
1910 } 1943 }
1911 else if (w->repeat) 1944 else if (w->repeat)
1912 { 1945 {
1913 w->at = w->repeat; 1946 ev_at (w) = w->repeat;
1914 ev_timer_start (EV_A_ w); 1947 ev_timer_start (EV_A_ w);
1915 } 1948 }
1916} 1949}
1917 1950
1918#if EV_PERIODIC_ENABLE 1951#if EV_PERIODIC_ENABLE
1921{ 1954{
1922 if (expect_false (ev_is_active (w))) 1955 if (expect_false (ev_is_active (w)))
1923 return; 1956 return;
1924 1957
1925 if (w->reschedule_cb) 1958 if (w->reschedule_cb)
1926 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); 1959 ev_at (w) = w->reschedule_cb (w, ev_rt_now);
1927 else if (w->interval) 1960 else if (w->interval)
1928 { 1961 {
1929 assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); 1962 assert (("ev_periodic_start called with negative interval value", w->interval >= 0.));
1930 /* this formula differs from the one in periodic_reify because we do not always round up */ 1963 /* this formula differs from the one in periodic_reify because we do not always round up */
1931 ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; 1964 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
1932 } 1965 }
1933 else 1966 else
1934 ((WT)w)->at = w->offset; 1967 ev_at (w) = w->offset;
1935 1968
1936 ev_start (EV_A_ (W)w, ++periodiccnt); 1969 ev_start (EV_A_ (W)w, ++periodiccnt);
1937 array_needsize (WT, periodics, periodicmax, periodiccnt, EMPTY2); 1970 array_needsize (WT, periodics, periodicmax, periodiccnt + 1, EMPTY2);
1938 periodics [periodiccnt - 1] = (WT)w; 1971 periodics [periodiccnt] = (WT)w;
1939 upheap (periodics, periodiccnt - 1); 1972 upheap (periodics, periodiccnt);
1940 1973
1941 /*assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));*/ 1974 /*assert (("internal periodic heap corruption", periodics [ev_active (w)] == w));*/
1942} 1975}
1943 1976
1944void noinline 1977void noinline
1945ev_periodic_stop (EV_P_ ev_periodic *w) 1978ev_periodic_stop (EV_P_ ev_periodic *w)
1946{ 1979{
1947 clear_pending (EV_A_ (W)w); 1980 clear_pending (EV_A_ (W)w);
1948 if (expect_false (!ev_is_active (w))) 1981 if (expect_false (!ev_is_active (w)))
1949 return; 1982 return;
1950 1983
1951 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == (WT)w));
1952
1953 { 1984 {
1954 int active = ((W)w)->active; 1985 int active = ev_active (w);
1955 1986
1987 assert (("internal periodic heap corruption", periodics [active] == (WT)w));
1988
1956 if (expect_true (--active < --periodiccnt)) 1989 if (expect_true (active < periodiccnt))
1957 { 1990 {
1958 periodics [active] = periodics [periodiccnt]; 1991 periodics [active] = periodics [periodiccnt];
1959 adjustheap (periodics, periodiccnt, active); 1992 adjustheap (periodics, periodiccnt, active);
1960 } 1993 }
1994
1995 --periodiccnt;
1961 } 1996 }
1962 1997
1963 ev_stop (EV_A_ (W)w); 1998 ev_stop (EV_A_ (W)w);
1964} 1999}
1965 2000
2081 if (w->wd < 0) 2116 if (w->wd < 0)
2082 { 2117 {
2083 ev_timer_start (EV_A_ &w->timer); /* this is not race-free, so we still need to recheck periodically */ 2118 ev_timer_start (EV_A_ &w->timer); /* this is not race-free, so we still need to recheck periodically */
2084 2119
2085 /* monitor some parent directory for speedup hints */ 2120 /* monitor some parent directory for speedup hints */
2121 /* note that exceeding the hardcoded limit is not a correctness issue, */
2122 /* but an efficiency issue only */
2086 if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096) 2123 if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096)
2087 { 2124 {
2088 char path [4096]; 2125 char path [4096];
2089 strcpy (path, w->path); 2126 strcpy (path, w->path);
2090 2127
2335 clear_pending (EV_A_ (W)w); 2372 clear_pending (EV_A_ (W)w);
2336 if (expect_false (!ev_is_active (w))) 2373 if (expect_false (!ev_is_active (w)))
2337 return; 2374 return;
2338 2375
2339 { 2376 {
2340 int active = ((W)w)->active; 2377 int active = ev_active (w);
2341 2378
2342 idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]]; 2379 idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]];
2343 ((W)idles [ABSPRI (w)][active - 1])->active = active; 2380 ev_active (idles [ABSPRI (w)][active - 1]) = active;
2344 2381
2345 ev_stop (EV_A_ (W)w); 2382 ev_stop (EV_A_ (W)w);
2346 --idleall; 2383 --idleall;
2347 } 2384 }
2348} 2385}
2365 clear_pending (EV_A_ (W)w); 2402 clear_pending (EV_A_ (W)w);
2366 if (expect_false (!ev_is_active (w))) 2403 if (expect_false (!ev_is_active (w)))
2367 return; 2404 return;
2368 2405
2369 { 2406 {
2370 int active = ((W)w)->active; 2407 int active = ev_active (w);
2408
2371 prepares [active - 1] = prepares [--preparecnt]; 2409 prepares [active - 1] = prepares [--preparecnt];
2372 ((W)prepares [active - 1])->active = active; 2410 ev_active (prepares [active - 1]) = active;
2373 } 2411 }
2374 2412
2375 ev_stop (EV_A_ (W)w); 2413 ev_stop (EV_A_ (W)w);
2376} 2414}
2377 2415
2392 clear_pending (EV_A_ (W)w); 2430 clear_pending (EV_A_ (W)w);
2393 if (expect_false (!ev_is_active (w))) 2431 if (expect_false (!ev_is_active (w)))
2394 return; 2432 return;
2395 2433
2396 { 2434 {
2397 int active = ((W)w)->active; 2435 int active = ev_active (w);
2436
2398 checks [active - 1] = checks [--checkcnt]; 2437 checks [active - 1] = checks [--checkcnt];
2399 ((W)checks [active - 1])->active = active; 2438 ev_active (checks [active - 1]) = active;
2400 } 2439 }
2401 2440
2402 ev_stop (EV_A_ (W)w); 2441 ev_stop (EV_A_ (W)w);
2403} 2442}
2404 2443
2500 clear_pending (EV_A_ (W)w); 2539 clear_pending (EV_A_ (W)w);
2501 if (expect_false (!ev_is_active (w))) 2540 if (expect_false (!ev_is_active (w)))
2502 return; 2541 return;
2503 2542
2504 { 2543 {
2505 int active = ((W)w)->active; 2544 int active = ev_active (w);
2545
2506 forks [active - 1] = forks [--forkcnt]; 2546 forks [active - 1] = forks [--forkcnt];
2507 ((W)forks [active - 1])->active = active; 2547 ev_active (forks [active - 1]) = active;
2508 } 2548 }
2509 2549
2510 ev_stop (EV_A_ (W)w); 2550 ev_stop (EV_A_ (W)w);
2511} 2551}
2512#endif 2552#endif
2531 clear_pending (EV_A_ (W)w); 2571 clear_pending (EV_A_ (W)w);
2532 if (expect_false (!ev_is_active (w))) 2572 if (expect_false (!ev_is_active (w)))
2533 return; 2573 return;
2534 2574
2535 { 2575 {
2536 int active = ((W)w)->active; 2576 int active = ev_active (w);
2577
2537 asyncs [active - 1] = asyncs [--asynccnt]; 2578 asyncs [active - 1] = asyncs [--asynccnt];
2538 ((W)asyncs [active - 1])->active = active; 2579 ev_active (asyncs [active - 1]) = active;
2539 } 2580 }
2540 2581
2541 ev_stop (EV_A_ (W)w); 2582 ev_stop (EV_A_ (W)w);
2542} 2583}
2543 2584

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines