ry / ebb fork watch download tarball
public
Description: web server
Homepage: http://ebb.rubyforge.org
Clone URL: git://github.com/ry/ebb.git
Upgrade to libev 3.41
ry (author)
Sun Jun 15 05:29:36 -0700 2008
commit  ca99b30a2d4cec322fd183cff99c1478987c362b
tree    848780ef4d79ab12ea3caa3ae42b6382653b1d57
parent  3099d923f4eeae6902a0e0012c97625db3849ca2
...
41
42
43
 
44
45
46
...
120
121
122
 
 
 
 
 
 
 
 
123
124
125
...
154
155
156
157
 
158
159
160
...
181
182
183
184
 
 
 
 
 
185
186
187
...
193
194
195
196
 
 
 
 
 
197
198
199
...
212
213
214
215
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
216
217
218
...
243
244
245
 
 
 
 
 
 
 
 
 
 
 
 
246
247
 
 
 
 
 
 
248
249
250
...
265
266
267
268
 
269
270
271
...
290
291
292
 
 
 
293
294
295
...
325
326
327
328
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
329
330
331
...
336
337
338
339
 
340
341
342
...
369
370
371
 
372
373
374
375
376
377
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
378
379
380
...
467
468
469
 
 
470
471
472
...
476
477
478
479
480
 
 
481
482
483
 
484
485
486
...
704
705
706
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
707
708
 
709
710
 
 
711
712
 
713
714
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
715
716
 
717
718
719
720
721
 
 
 
 
722
723
724
725
 
 
726
727
 
 
 
 
 
 
 
728
729
 
730
731
 
732
733
734
735
 
736
737
 
738
739
740
 
741
742
743
 
744
745
746
747
748
 
 
749
750
751
752
753
 
 
754
 
 
 
 
 
 
 
755
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
756
757
 
758
759
760
 
 
 
 
 
 
761
762
763
...
804
805
806
807
808
 
 
 
 
 
 
 
 
 
 
 
 
809
810
811
 
 
 
 
812
813
814
815
816
...
824
825
826
827
 
 
 
 
 
 
 
 
 
 
828
829
830
...
833
834
835
836
837
838
839
 
 
 
 
 
 
 
 
 
 
 
 
840
841
842
...
1107
1108
1109
1110
 
1111
1112
1113
...
1141
1142
1143
1144
1145
 
 
 
 
 
 
 
 
 
 
1146
1147
1148
...
1197
1198
1199
 
1200
 
1201
1202
1203
...
1226
1227
1228
1229
1230
 
 
 
 
 
 
 
 
 
 
 
1231
1232
1233
...
1238
1239
1240
 
1241
1242
1243
...
1266
1267
1268
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1269
1270
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1271
1272
1273
...
1352
1353
1354
 
1355
1356
1357
1358
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1359
1360
1361
1362
 
 
 
1363
1364
 
1365
1366
1367
1368
1369
1370
1371
 
 
 
1372
1373
1374
1375
 
1376
1377
 
 
1378
1379
1380
1381
 
1382
1383
1384
...
1387
1388
1389
1390
 
 
 
1391
1392
 
1393
1394
1395
1396
1397
1398
1399
1400
1401
 
 
 
 
 
 
1402
1403
1404
1405
1406
1407
1408
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1409
1410
1411
1412
 
1413
1414
1415
...
1420
1421
1422
1423
 
1424
1425
 
1426
1427
1428
 
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
 
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
 
1458
 
 
1459
1460
1461
...
1494
1495
1496
1497
 
1498
1499
1500
...
1520
1521
1522
1523
 
 
 
 
 
1524
1525
1526
...
1550
1551
1552
 
 
 
 
1553
1554
1555
...
1600
1601
1602
1603
 
1604
1605
1606
1607
1608
1609
1610
 
1611
1612
1613
...
1754
1755
1756
 
 
1757
1758
1759
1760
1761
1762
 
 
1763
1764
1765
...
1769
1770
1771
1772
 
 
 
1773
1774
1775
1776
1777
 
 
1778
1779
1780
...
1783
1784
1785
1786
 
1787
1788
1789
1790
1791
1792
1793
 
 
 
 
 
 
 
 
 
 
1794
1795
 
1796
1797
1798
...
1802
1803
1804
1805
 
1806
1807
1808
 
1809
1810
 
 
 
 
 
1811
1812
 
1813
1814
1815
1816
1817
 
 
 
1818
1819
1820
...
1822
1823
1824
 
 
1825
1826
1827
1828
1829
1830
 
 
 
1831
1832
1833
1834
1835
1836
1837
 
1838
1839
 
 
1840
1841
1842
...
1847
1848
1849
1850
 
1851
1852
1853
1854
1855
 
1856
1857
1858
 
 
 
 
 
 
 
 
 
 
1859
1860
1861
1862
1863
 
1864
1865
 
1866
1867
1868
...
1872
1873
1874
1875
 
1876
1877
1878
 
 
 
 
 
1879
1880
 
1881
1882
 
1883
1884
1885
1886
 
 
1887
1888
1889
...
1913
1914
1915
 
 
1916
1917
1918
...
1942
1943
1944
 
 
1945
1946
1947
...
1951
1952
1953
 
 
1954
1955
1956
1957
1958
 
 
1959
1960
1961
...
1967
1968
1969
 
 
1970
1971
 
 
1972
1973
1974
...
1978
1979
1980
 
 
1981
1982
 
 
1983
1984
1985
...
2007
2008
2009
 
 
2010
2011
2012
...
2215
2216
2217
 
 
2218
2219
2220
...
2224
2225
2226
 
 
2227
2228
2229
2230
2231
2232
 
 
2233
2234
2235
...
2242
2243
2244
 
 
2245
2246
2247
...
2251
2252
2253
 
 
2254
2255
2256
...
2260
2261
2262
 
 
2263
2264
 
2265
2266
2267
 
2268
2269
2270
2271
 
 
2272
2273
2274
...
2278
2279
2280
 
 
2281
2282
2283
 
 
2284
2285
2286
...
2290
2291
2292
 
 
2293
2294
 
 
2295
2296
 
2297
2298
2299
 
 
2300
2301
2302
...
2305
2306
2307
 
 
2308
2309
2310
 
 
2311
2312
2313
...
2317
2318
2319
 
 
2320
2321
 
 
2322
2323
 
2324
2325
2326
 
 
2327
2328
2329
...
2380
2381
2382
 
 
2383
2384
2385
...
2390
2391
2392
 
 
2393
2394
2395
...
2399
2400
2401
 
 
2402
2403
2404
2405
 
 
2406
2407
2408
...
2413
2414
2415
 
 
2416
2417
2418
 
 
2419
2420
2421
...
2425
2426
2427
 
 
2428
2429
 
 
2430
2431
 
2432
2433
2434
 
 
2435
2436
2437
...
2444
2445
2446
 
 
2447
2448
2449
 
 
2450
2451
2452
...
2456
2457
2458
 
 
2459
2460
 
 
2461
2462
 
2463
2464
2465
 
 
2466
2467
2468
...
41
42
43
44
45
46
47
...
121
122
123
124
125
126
127
128
129
130
131
132
133
134
...
163
164
165
 
166
167
168
169
...
190
191
192
 
193
194
195
196
197
198
199
200
...
206
207
208
 
209
210
211
212
213
214
215
216
...
229
230
231
 
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
...
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
...
326
327
328
 
329
330
331
332
...
351
352
353
354
355
356
357
358
359
...
389
390
391
 
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
...
415
416
417
 
418
419
420
421
...
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
...
565
566
567
568
569
570
571
572
...
576
577
578
 
 
579
580
581
582
 
583
584
585
586
...
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
 
828
829
 
830
831
832
 
833
834
 
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
 
857
858
859
 
 
 
860
861
862
863
864
865
 
 
866
867
868
869
870
871
872
873
874
875
876
877
 
878
879
 
880
881
882
883
 
884
885
 
886
887
888
 
889
890
891
 
892
893
894
895
 
 
896
897
898
899
900
 
 
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
 
939
940
 
 
941
942
943
944
945
946
947
948
949
...
990
991
992
 
 
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
 
 
1006
1007
1008
1009
1010
 
1011
1012
1013
...
1021
1022
1023
 
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
...
1039
1040
1041
 
 
 
 
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
...
1321
1322
1323
 
1324
1325
1326
1327
...
1355
1356
1357
 
 
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
...
1419
1420
1421
1422
1423
1424
1425
1426
1427
...
1450
1451
1452
 
 
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
...
1471
1472
1473
1474
1475
1476
1477
...
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
...
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
 
1719
1720
1721
1722
 
1723
1724
1725
1726
1727
1728
1729
 
1730
1731
1732
1733
 
 
 
1734
1735
 
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
...
1748
1749
1750
 
1751
1752
1753
1754
 
1755
1756
1757
1758
1759
1760
1761
 
 
 
1762
1763
1764
1765
1766
1767
1768
1769
1770
 
 
 
 
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
...
1799
1800
1801
 
1802
1803
 
1804
1805
1806
 
1807
1808
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1809
1810
 
 
 
 
 
 
 
 
 
 
 
1811
1812
1813
1814
1815
1816
1817
...
1850
1851
1852
 
1853
1854
1855
1856
...
1876
1877
1878
 
1879
1880
1881
1882
1883
1884
1885
1886
...
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
...
1964
1965
1966
 
1967
1968
1969
1970
1971
1972
1973
 
1974
1975
1976
1977
...
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
...
2137
2138
2139
 
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
...
2155
2156
2157
 
2158
2159
2160
2161
 
 
 
 
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
 
2173
2174
2175
2176
...
2180
2181
2182
 
2183
2184
2185
 
2186
2187
 
2188
2189
2190
2191
2192
2193
 
2194
2195
2196
2197
2198
 
2199
2200
2201
2202
2203
2204
...
2206
2207
2208
2209
2210
2211
2212
2213
2214
 
 
2215
2216
2217
2218
2219
2220
2221
2222
2223
 
2224
2225
2226
2227
2228
2229
2230
2231
...
2236
2237
2238
 
2239
2240
2241
2242
2243
 
2244
2245
2246
 
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
 
 
 
 
2258
2259
 
2260
2261
2262
2263
...
2267
2268
2269
 
2270
2271
2272
 
2273
2274
2275
2276
2277
2278
 
2279
2280
 
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
...
2314
2315
2316
2317
2318
2319
2320
2321
...
2345
2346
2347
2348
2349
2350
2351
2352
...
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
...
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
...
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
...
2424
2425
2426
2427
2428
2429
2430
2431
...
2634
2635
2636
2637
2638
2639
2640
2641
...
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
...
2667
2668
2669
2670
2671
2672
2673
2674
...
2678
2679
2680
2681
2682
2683
2684
2685
...
2689
2690
2691
2692
2693
2694
 
2695
2696
2697
 
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
...
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
...
2727
2728
2729
2730
2731
2732
 
2733
2734
2735
 
2736
2737
2738
2739
2740
2741
2742
2743
2744
...
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
...
2763
2764
2765
2766
2767
2768
 
2769
2770
2771
 
2772
2773
2774
2775
2776
2777
2778
2779
2780
...
2831
2832
2833
2834
2835
2836
2837
2838
...
2843
2844
2845
2846
2847
2848
2849
2850
...
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
...
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
...
2888
2889
2890
2891
2892
2893
 
2894
2895
2896
 
2897
2898
2899
2900
2901
2902
2903
2904
2905
...
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
...
2928
2929
2930
2931
2932
2933
 
2934
2935
2936
 
2937
2938
2939
2940
2941
2942
2943
2944
2945
0
@@ -41,6 +41,7 @@
0
 extern "C" {
0
 #endif
0
 
0
+/* this big block deduces configuration from config.h */
0
 #ifndef EV_STANDALONE
0
 # ifdef EV_CONFIG_H
0
 # include EV_CONFIG_H
0
@@ -120,6 +121,14 @@ extern "C" {
0
 # endif
0
 # endif
0
 
0
+# ifndef EV_USE_EVENTFD
0
+# if HAVE_EVENTFD
0
+# define EV_USE_EVENTFD 1
0
+# else
0
+# define EV_USE_EVENTFD 0
0
+# endif
0
+# endif
0
+
0
 #endif
0
 
0
 #include <math.h>
0
@@ -154,7 +163,7 @@ extern "C" {
0
 # endif
0
 #endif
0
 
0
-/**/
0
+/* this block tries to deduce configuration from header-defined symbols and defaults */
0
 
0
 #ifndef EV_USE_MONOTONIC
0
 # define EV_USE_MONOTONIC 0
0
@@ -181,7 +190,11 @@ extern "C" {
0
 #endif
0
 
0
 #ifndef EV_USE_EPOLL
0
-# define EV_USE_EPOLL 0
0
+# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4))
0
+# define EV_USE_EPOLL 1
0
+# else
0
+# define EV_USE_EPOLL 0
0
+# endif
0
 #endif
0
 
0
 #ifndef EV_USE_KQUEUE
0
@@ -193,7 +206,11 @@ extern "C" {
0
 #endif
0
 
0
 #ifndef EV_USE_INOTIFY
0
-# define EV_USE_INOTIFY 0
0
+# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4))
0
+# define EV_USE_INOTIFY 1
0
+# else
0
+# define EV_USE_INOTIFY 0
0
+# endif
0
 #endif
0
 
0
 #ifndef EV_PID_HASHSIZE
0
@@ -212,7 +229,33 @@ extern "C" {
0
 # endif
0
 #endif
0
 
0
-/**/
0
+#ifndef EV_USE_EVENTFD
0
+# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7))
0
+# define EV_USE_EVENTFD 1
0
+# else
0
+# define EV_USE_EVENTFD 0
0
+# endif
0
+#endif
0
+
0
+#if 0 /* debugging */
0
+# define EV_VERIFY 3
0
+# define EV_USE_4HEAP 1
0
+# define EV_HEAP_CACHE_AT 1
0
+#endif
0
+
0
+#ifndef EV_VERIFY
0
+# define EV_VERIFY !EV_MINIMAL
0
+#endif
0
+
0
+#ifndef EV_USE_4HEAP
0
+# define EV_USE_4HEAP !EV_MINIMAL
0
+#endif
0
+
0
+#ifndef EV_HEAP_CACHE_AT
0
+# define EV_HEAP_CACHE_AT !EV_MINIMAL
0
+#endif
0
+
0
+/* this block fixes any misconfiguration where we know we run into trouble otherwise */
0
 
0
 #ifndef CLOCK_MONOTONIC
0
 # undef EV_USE_MONOTONIC
0
@@ -243,8 +286,26 @@ extern "C" {
0
 # include <winsock.h>
0
 #endif
0
 
0
+#if EV_USE_EVENTFD
0
+/* our minimum requirement is glibc 2.7 which has the stub, but not the header */
0
+# include <stdint.h>
0
+# ifdef __cplusplus
0
+extern "C" {
0
+# endif
0
+int eventfd (unsigned int initval, int flags);
0
+# ifdef __cplusplus
0
+}
0
+# endif
0
+#endif
0
+
0
 /**/
0
 
0
+#if EV_VERIFY >= 3
0
+# define EV_FREQUENT_CHECK ev_loop_verify (EV_A)
0
+#else
0
+# define EV_FREQUENT_CHECK do { } while (0)
0
+#endif
0
+
0
 /*
0
  * This is used to avoid floating point rounding problems.
0
  * It is added to ev_rt_now when scheduling periodics
0
@@ -265,7 +326,7 @@ extern "C" {
0
 #else
0
 # define expect(expr,value) (expr)
0
 # define noinline
0
-# if __STDC_VERSION__ < 199901L
0
+# if __STDC_VERSION__ < 199901L && __GNUC__ < 2
0
 # define inline
0
 # endif
0
 #endif
0
@@ -290,6 +351,9 @@ typedef ev_watcher *W;
0
 typedef ev_watcher_list *WL;
0
 typedef ev_watcher_time *WT;
0
 
0
+#define ev_active(w) ((W)(w))->active
0
+#define ev_at(w) ((WT)(w))->at
0
+
0
 #if EV_USE_MONOTONIC
0
 /* sig_atomic_t is used to avoid per-thread variables or locking but still */
0
 /* giving it a reasonably high chance of working on typical architetcures */
0
@@ -325,7 +389,22 @@ syserr (const char *msg)
0
     }
0
 }
0
 
0
-static void *(*alloc)(void *ptr, long size);
0
+static void *
0
+ev_realloc_emul (void *ptr, long size)
0
+{
0
+ /* some systems, notably openbsd and darwin, fail to properly
0
+ * implement realloc (x, 0) (as required by both ansi c-98 and
0
+ * the single unix specification, so work around them here.
0
+ */
0
+
0
+ if (size)
0
+ return realloc (ptr, size);
0
+
0
+ free (ptr);
0
+ return 0;
0
+}
0
+
0
+static void *(*alloc)(void *ptr, long size) = ev_realloc_emul;
0
 
0
 void
0
 ev_set_allocator (void *(*cb)(void *ptr, long size))
0
@@ -336,7 +415,7 @@ ev_set_allocator (void *(*cb)(void *ptr, long size))
0
 inline_speed void *
0
 ev_realloc (void *ptr, long size)
0
 {
0
- ptr = alloc ? alloc (ptr, size) : realloc (ptr, size);
0
+ ptr = alloc (ptr, size);
0
 
0
   if (!ptr && size)
0
     {
0
@@ -369,12 +448,31 @@ typedef struct
0
 } ANPENDING;
0
 
0
 #if EV_USE_INOTIFY
0
+/* hash table entry per inotify-id */
0
 typedef struct
0
 {
0
   WL head;
0
 } ANFS;
0
 #endif
0
 
0
+/* Heap Entry */
0
+#if EV_HEAP_CACHE_AT
0
+ typedef struct {
0
+ ev_tstamp at;
0
+ WT w;
0
+ } ANHE;
0
+
0
+ #define ANHE_w(he) (he).w /* access watcher, read-write */
0
+ #define ANHE_at(he) (he).at /* access cached at, read-only */
0
+ #define ANHE_at_cache(he) (he).at = (he).w->at /* update at from watcher */
0
+#else
0
+ typedef WT ANHE;
0
+
0
+ #define ANHE_w(he) (he)
0
+ #define ANHE_at(he) (he)->at
0
+ #define ANHE_at_cache(he)
0
+#endif
0
+
0
 #if EV_MULTIPLICITY
0
 
0
   struct ev_loop
0
@@ -467,6 +565,8 @@ ev_sleep (ev_tstamp delay)
0
 
0
 /*****************************************************************************/
0
 
0
+#define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */
0
+
0
 int inline_size
0
 array_nextsize (int elem, int cur, int cnt)
0
 {
0
@@ -476,11 +576,11 @@ array_nextsize (int elem, int cur, int cnt)
0
     ncur <<= 1;
0
   while (cnt > ncur);
0
 
0
- /* if size > 4096, round to 4096 - 4 * longs to accomodate malloc overhead */
0
- if (elem * ncur > 4096)
0
+ /* if size is large, round to MALLOC_ROUND - 4 * longs to accomodate malloc overhead */
0
+ if (elem * ncur > MALLOC_ROUND - sizeof (void *) * 4)
0
     {
0
       ncur *= elem;
0
- ncur = (ncur + elem + 4095 + sizeof (void *) * 4) & ~4095;
0
+ ncur = (ncur + elem + (MALLOC_ROUND - 1) + sizeof (void *) * 4) & ~(MALLOC_ROUND - 1);
0
       ncur = ncur - sizeof (void *) * 4;
0
       ncur /= elem;
0
     }
0
@@ -704,60 +804,146 @@ fd_rearm_all (EV_P)
0
 
0
 /*****************************************************************************/
0
 
0
+/*
0
+ * the heap functions want a real array index. array index 0 uis guaranteed to not
0
+ * be in-use at any time. the first heap entry is at array [HEAP0]. DHEAP gives
0
+ * the branching factor of the d-tree.
0
+ */
0
+
0
+/*
0
+ * at the moment we allow libev the luxury of two heaps,
0
+ * a small-code-size 2-heap one and a ~1.5kb larger 4-heap
0
+ * which is more cache-efficient.
0
+ * the difference is about 5% with 50000+ watchers.
0
+ */
0
+#if EV_USE_4HEAP
0
+
0
+#define DHEAP 4
0
+#define HEAP0 (DHEAP - 1) /* index of first element in heap */
0
+#define HPARENT(k) ((((k) - HEAP0 - 1) / DHEAP) + HEAP0)
0
+#define UPHEAP_DONE(p,k) ((p) == (k))
0
+
0
+/* away from the root */
0
 void inline_speed
0
-upheap (WT *heap, int k)