/usr/include/ace/OS_NS_Thread.inl is in libace-dev 6.0.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 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 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 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 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 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 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 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 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 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 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 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 1385 1386 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 1416 1417 1418 1419 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 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 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 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 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 1746 1747 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 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 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 2205 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 2232 2233 2234 2235 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 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 | // -*- C++ -*-
//
// $Id: OS_NS_Thread.inl 92682 2010-11-23 23:41:19Z shuston $
#include "ace/OS_NS_macros.h"
// for timespec_t, perhaps move it to os_time.h
#include "ace/Time_Value.h"
#include "ace/OS_NS_sys_mman.h"
#include "ace/OS_NS_sys_time.h"
#include "ace/OS_NS_string.h"
#include "ace/OS_NS_unistd.h"
#include "ace/OS_NS_stdio.h"
#include "ace/OS_NS_errno.h"
#if defined (ACE_USES_FIFO_SEM)
# include "ace/OS_NS_sys_stat.h"
# include "ace/OS_NS_sys_select.h"
# include "ace/OS_NS_fcntl.h"
# include "ace/Handle_Set.h"
# endif /* ACE_USES_FIFO_SEM */
#if defined (ACE_HAS_PRIOCNTL)
# include /**/ <sys/priocntl.h>
#endif /* ACE_HAS_PRIOCNTL */
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
/*****************************************************************************/
#if defined (ACE_LACKS_COND_T) && defined (ACE_HAS_THREADS)
ACE_INLINE long
ACE_cond_t::waiters (void) const
{
return this->waiters_;
}
#endif /* ACE_LACKS_COND_T && ACE_HAS_THREADS */
/*****************************************************************************/
#if defined (ACE_HAS_TSS_EMULATION)
# if !defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
ACE_INLINE
void **&
ACE_TSS_Emulation::tss_base ()
{
# if defined (ACE_HAS_VXTHREADS)
int &spare = taskIdCurrent->ACE_VXWORKS_SPARE;
return reinterpret_cast <void **&> (spare);
# else
// Uh oh.
ACE_NOTSUP_RETURN (0);
# endif /* ACE_HAS_VXTHREADS */
}
# endif /* ! ACE_HAS_THREAD_SPECIFIC_STORAGE */
ACE_INLINE
ACE_TSS_Emulation::ACE_TSS_DESTRUCTOR
ACE_TSS_Emulation::tss_destructor (const ACE_thread_key_t key)
{
ACE_KEY_INDEX (key_index, key);
return tss_destructor_ [key_index];
}
ACE_INLINE
void
ACE_TSS_Emulation::tss_destructor (const ACE_thread_key_t key,
ACE_TSS_DESTRUCTOR destructor)
{
ACE_KEY_INDEX (key_index, key);
tss_destructor_ [key_index] = destructor;
}
ACE_INLINE
void *&
ACE_TSS_Emulation::ts_object (const ACE_thread_key_t key)
{
ACE_KEY_INDEX (key_index, key);
# if defined (ACE_HAS_VXTHREADS)
/* If someone wants tss_base make sure they get one. This
gets used if someone spawns a VxWorks task directly, not
through ACE. The allocated array will never be deleted! */
if (0 == taskIdCurrent->ACE_VXWORKS_SPARE)
{
taskIdCurrent->ACE_VXWORKS_SPARE =
reinterpret_cast<int> (new void *[ACE_TSS_THREAD_KEYS_MAX]);
// Zero the entire TSS array. Do it manually instead of using
// memset, for optimum speed. Though, memset may be faster :-)
void **tss_base_p =
reinterpret_cast<void **> (taskIdCurrent->ACE_VXWORKS_SPARE);
for (u_int i = 0; i < ACE_TSS_THREAD_KEYS_MAX; ++i, ++tss_base_p)
{
*tss_base_p = 0;
}
}
# endif /* ACE_HAS_VXTHREADS */
return tss_base ()[key_index];
}
#endif /* ACE_HAS_TSS_EMULATION */
/*****************************************************************************/
ACE_INLINE int
ACE_OS::thr_equal (ACE_thread_t t1, ACE_thread_t t2)
{
#if defined (ACE_HAS_PTHREADS)
# if defined (pthread_equal)
// If it's a macro we can't say "pthread_equal"...
return pthread_equal (t1, t2);
# else
return pthread_equal (t1, t2);
# endif /* pthread_equal */
#else /* For both STHREADS and WTHREADS... */
// Hum, Do we need to treat WTHREAD differently?
// levine 13 oct 98 % I don't think so, ACE_thread_t is a DWORD.
return t1 == t2;
#endif /* ACE_HAS_PTHREADS */
}
ACE_INLINE int
ACE_OS::condattr_destroy (ACE_condattr_t &attributes)
{
#if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_PTHREADS)
pthread_condattr_destroy (&attributes);
# else
attributes.type = 0;
# endif /* ACE_HAS_PTHREADS */
return 0;
# else
ACE_UNUSED_ARG (attributes);
return 0;
# endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::condattr_init (ACE_condattr_t &attributes, int type)
{
ACE_UNUSED_ARG (type);
# if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_PTHREADS)
int result = -1;
# if defined (ACE_PTHREAD_CONDATTR_T_INITIALIZE)
/* Tests show that VxWorks 6.x pthread lib does not only
* require zeroing of mutex/condition objects to function correctly
* but also of the attribute objects.
*/
ACE_OS::memset (&attributes, 0, sizeof (attributes));
# endif
if (
ACE_ADAPT_RETVAL (pthread_condattr_init (&attributes), result) == 0
# if defined (_POSIX_THREAD_PROCESS_SHARED) && !defined (ACE_LACKS_CONDATTR_PSHARED)
&& ACE_ADAPT_RETVAL (pthread_condattr_setpshared (&attributes, type),
result) == 0
# endif /* _POSIX_THREAD_PROCESS_SHARED && ! ACE_LACKS_CONDATTR_PSHARED */
)
result = 0;
else
result = -1; // ACE_ADAPT_RETVAL used it for intermediate status
return result;
# else
attributes.type = type;
return 0;
# endif /* ACE_HAS_PTHREADS */
# else
ACE_UNUSED_ARG (attributes);
ACE_UNUSED_ARG (type);
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_THREADS */
}
#if !defined (ACE_LACKS_COND_T)
// NOTE: The ACE_OS::cond_* functions for Unix platforms are defined
// here because the ACE_OS::sema_* functions below need them.
// However, ACE_WIN32 and VXWORKS define the ACE_OS::cond_* functions
// using the ACE_OS::sema_* functions. So, they are defined in OS_NS_Tread.cpp.
ACE_INLINE int
ACE_OS::cond_broadcast (ACE_cond_t *cv)
{
ACE_OS_TRACE ("ACE_OS::cond_broadcast");
# if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_PTHREADS)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_cond_broadcast (cv),
result),
int, -1);
# elif defined (ACE_HAS_STHREADS)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::cond_broadcast (cv),
result),
int, -1);
# elif defined (ACE_HAS_WTHREADS) && defined (ACE_HAS_WTHREADS_CONDITION_VARIABLE)
::WakeAllConditionVariable (cv);
return 0;
# endif /* ACE_HAS_STHREADS */
# else
ACE_UNUSED_ARG (cv);
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::cond_destroy (ACE_cond_t *cv)
{
ACE_OS_TRACE ("ACE_OS::cond_destroy");
# if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_PTHREADS)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_cond_destroy (cv), result), int, -1);
# elif defined (ACE_HAS_STHREADS)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::cond_destroy (cv), result), int, -1);
# elif defined (ACE_HAS_WTHREADS) && defined (ACE_HAS_WTHREADS_CONDITION_VARIABLE)
// Windows doesn't have a destroy
return 0;
# endif /* ACE_HAS_STHREADS */
# else
ACE_UNUSED_ARG (cv);
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::cond_init (ACE_cond_t *cv,
ACE_condattr_t &attributes,
const char *name,
void *arg)
{
// ACE_OS_TRACE ("ACE_OS::cond_init");
ACE_UNUSED_ARG (name);
ACE_UNUSED_ARG (arg);
# if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_PTHREADS)
int result = -1;
# if defined (ACE_PTHREAD_COND_T_INITIALIZE)
/* VxWorks 6.x API reference states:
* If the memory for the condition variable object has been allocated
* dynamically, it is a good policy to always zero out the
* block of memory so as to avoid spurious EBUSY return code
* when calling this routine.
*/
ACE_OS::memset (cv, 0, sizeof (*cv));
# endif
if (ACE_ADAPT_RETVAL (pthread_cond_init (cv, &attributes), result) == 0)
result = 0;
else
result = -1; // ACE_ADAPT_RETVAL used it for intermediate status
return result;
# elif defined (ACE_HAS_STHREADS)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::cond_init (cv,
attributes.type,
arg),
result),
int, -1);
# elif defined (ACE_HAS_WTHREADS) && defined (ACE_HAS_WTHREADS_CONDITION_VARIABLE)
::InitializeConditionVariable (cv);
return 0;
# endif /* ACE_HAS_PTHREADS vs. ACE_HAS_STHREADS */
# else
ACE_UNUSED_ARG (cv);
ACE_UNUSED_ARG (attributes);
ACE_UNUSED_ARG (name);
ACE_UNUSED_ARG (arg);
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_THREADS */
}
#if defined (ACE_HAS_WCHAR)
ACE_INLINE int
ACE_OS::cond_init (ACE_cond_t *cv,
ACE_condattr_t &attributes,
const wchar_t *name,
void *arg)
{
return ACE_OS::cond_init (cv, attributes, ACE_Wide_To_Ascii (name).char_rep (), arg);
}
#endif /* ACE_HAS_WCHAR */
#if defined (ACE_HAS_WCHAR)
ACE_INLINE int
ACE_OS::cond_init (ACE_cond_t *cv, short type, const wchar_t *name, void *arg)
{
return ACE_OS::cond_init (cv, type, ACE_Wide_To_Ascii (name).char_rep (), arg);
}
#endif /* ACE_HAS_WCHAR */
ACE_INLINE int
ACE_OS::cond_signal (ACE_cond_t *cv)
{
ACE_OS_TRACE ("ACE_OS::cond_signal");
# if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_PTHREADS)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_cond_signal (cv), result),
int, -1);
# elif defined (ACE_HAS_STHREADS)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::cond_signal (cv), result), int, -1);
# elif defined (ACE_HAS_WTHREADS) && defined (ACE_HAS_WTHREADS_CONDITION_VARIABLE)
::WakeConditionVariable (cv);
return 0;
# endif /* ACE_HAS_STHREADS */
# else
ACE_UNUSED_ARG (cv);
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::cond_wait (ACE_cond_t *cv,
ACE_mutex_t *external_mutex)
{
ACE_OS_TRACE ("ACE_OS::cond_wait");
# if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_PTHREADS)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_cond_wait (cv, external_mutex), result),
int, -1);
# elif defined (ACE_HAS_STHREADS)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::cond_wait (cv, external_mutex), result),
int, -1);
# elif defined (ACE_HAS_WTHREADS) && defined (ACE_HAS_WTHREADS_CONDITION_VARIABLE)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::SleepConditionVariableCS (cv, &external_mutex->thr_mutex_, INFINITE), result),
int, -1);
# endif /* ACE_HAS_PTHREADS */
# else
ACE_UNUSED_ARG (cv);
ACE_UNUSED_ARG (external_mutex);
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::cond_timedwait (ACE_cond_t *cv,
ACE_mutex_t *external_mutex,
ACE_Time_Value *timeout)
{
ACE_OS_TRACE ("ACE_OS::cond_timedwait");
# if defined (ACE_HAS_THREADS)
int result = 0;
timespec_t ts;
if (timeout != 0)
ts = *timeout; // Calls ACE_Time_Value::operator timespec_t().
# if defined (ACE_HAS_PTHREADS)
ACE_OSCALL (ACE_ADAPT_RETVAL (timeout == 0
? pthread_cond_wait (cv, external_mutex)
: pthread_cond_timedwait (cv, external_mutex,
(ACE_TIMESPEC_PTR) &ts),
result),
int, -1, result);
// We need to adjust this to make the POSIX and Solaris return
// values consistent. EAGAIN is from Pthreads DRAFT4 (HP-UX 10.20 and down)
if (result == -1 &&
(errno == ETIMEDOUT || errno == EAGAIN))
errno = ETIME;
# elif defined (ACE_HAS_STHREADS)
ACE_OSCALL (ACE_ADAPT_RETVAL (timeout == 0
? ::cond_wait (cv, external_mutex)
: ::cond_timedwait (cv,
external_mutex,
(timestruc_t*)&ts),
result),
int, -1, result);
# elif defined (ACE_HAS_WTHREADS) && defined (ACE_HAS_WTHREADS_CONDITION_VARIABLE)
int msec_timeout = 0;
if (timeout != 0)
{
ACE_Time_Value relative_time (*timeout - ACE_OS::gettimeofday ());
// Watchout for situations where a context switch has caused the
// current time to be > the timeout.
if (relative_time > ACE_Time_Value::zero)
msec_timeout = relative_time.msec ();
}
ACE_OSCALL (ACE_ADAPT_RETVAL (::SleepConditionVariableCS (cv, &external_mutex->thr_mutex_, msec_timeout),
result),
int, -1, result);
return result;
# endif /* ACE_HAS_STHREADS */
if (timeout != 0)
timeout->set (ts); // Update the time value before returning.
return result;
# else
ACE_UNUSED_ARG (cv);
ACE_UNUSED_ARG (external_mutex);
ACE_UNUSED_ARG (timeout);
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_THREADS */
}
#endif /* !ACE_LACKS_COND_T */
ACE_INLINE int
ACE_OS::mutex_lock (ACE_mutex_t *m,
const ACE_Time_Value *timeout)
{
return timeout == 0 ? ACE_OS::mutex_lock (m) : ACE_OS::mutex_lock (m, *timeout);
}
#if defined (ACE_HAS_WCHAR)
ACE_INLINE int
ACE_OS::event_init (ACE_event_t *event,
int manual_reset,
int initial_state,
int type,
const wchar_t *name,
void *arg,
LPSECURITY_ATTRIBUTES sa)
{
#if defined (ACE_WIN32)
ACE_UNUSED_ARG (type);
ACE_UNUSED_ARG (arg);
SECURITY_ATTRIBUTES sa_buffer;
SECURITY_DESCRIPTOR sd_buffer;
*event = ::CreateEventW (ACE_OS::default_win32_security_attributes_r
(sa, &sa_buffer, &sd_buffer),
manual_reset,
initial_state,
name);
if (*event == 0)
ACE_FAIL_RETURN (-1);
// Make sure to set errno to ERROR_ALREADY_EXISTS if necessary.
ACE_OS::set_errno_to_last_error ();
return 0;
#else /* ACE_WIN32 */
return ACE_OS::event_init (event,
manual_reset,
initial_state,
type,
ACE_Wide_To_Ascii (name).char_rep (),
arg,
sa);
#endif /* ACE_WIN32 */
}
#endif /* ACE_HAS_WCHAR */
ACE_INLINE long
ACE_OS::priority_control (ACE_idtype_t idtype, ACE_id_t identifier, int cmd, void *arg)
{
ACE_OS_TRACE ("ACE_OS::priority_control");
#if defined (ACE_HAS_PRIOCNTL)
ACE_OSCALL_RETURN (priocntl (idtype, identifier, cmd, static_cast<caddr_t> (arg)),
long, -1);
#else /* ! ACE_HAS_PRIOCNTL*/
ACE_UNUSED_ARG (idtype);
ACE_UNUSED_ARG (identifier);
ACE_UNUSED_ARG (cmd);
ACE_UNUSED_ARG (arg);
ACE_NOTSUP_RETURN (-1);
#endif /* ! ACE_HAS_PRIOCNTL*/
}
// This method is used to prepare the recursive mutex for releasing
// when waiting on a condition variable. If the platform doesn't have
// native recursive mutex and condition variable support, then ACE needs
// to save the recursion state around the wait and also ensure that the
// wait and lock release are atomic. recursive_mutex_cond_relock()
// is the inverse of this method.
ACE_INLINE int
ACE_OS::recursive_mutex_cond_unlock (ACE_recursive_thread_mutex_t *m,
ACE_recursive_mutex_state &state)
{
#if defined (ACE_HAS_THREADS)
ACE_OS_TRACE ("ACE_OS::recursive_mutex_cond_unlock");
# if defined (ACE_HAS_RECURSIVE_MUTEXES)
// Windows need special handling since it has recursive mutexes, but
// does not integrate them into a condition variable.
# if defined (ACE_WIN32)
// For Windows, the OS takes care of the mutex and its recursion. We just
// need to release the lock one fewer times than this thread has acquired
// it. Remember how many times, and reacquire it that many more times when
// the condition is signaled.
// We're using undocumented fields in the CRITICAL_SECTION structure
// and they've been known to change across Windows variants and versions./
// So be careful if you need to change these - there may be other
// Windows variants that depend on existing values and limits.
state.relock_count_ = 0;
while (
# if !defined (ACE_HAS_WINCE)
m->LockCount > 0 && m->RecursionCount > 1
# else
// WinCE doesn't have RecursionCount and the LockCount semantic
// Mobile 5 has it 1-indexed.
m->LockCount > 1
# endif /* ACE_HAS_WINCE */
)
{
// This may fail if the current thread doesn't own the mutex. If it
// does fail, it'll be on the first try, so don't worry about resetting
// the state.
if (ACE_OS::recursive_mutex_unlock (m) == -1)
return -1;
++state.relock_count_;
}
# else /* not ACE_WIN32 */
// prevent warnings for unused variables
ACE_UNUSED_ARG (state);
ACE_UNUSED_ARG (m);
# endif /* ACE_WIN32 */
return 0;
# else /* ACE_HAS_RECURSIVE_MUTEXES */
// For platforms without recursive mutexes, we obtain the nesting mutex
// to gain control over the mutex internals. Then set the internals to say
// the mutex is available. If there are waiters, signal the condition
// to notify them (this is mostly like the recursive_mutex_unlock() method).
// Then, return with the nesting mutex still held. The condition wait
// will release it atomically, allowing mutex waiters to continue.
// Note that this arrangement relies on the fact that on return from
// the condition wait, this thread will again own the nesting mutex
// and can either set the mutex internals directly or get in line for
// the mutex... this part is handled in recursive_mutex_cond_relock().
if (ACE_OS::thread_mutex_lock (&m->nesting_mutex_) == -1)
return -1;
# if !defined (ACE_NDEBUG)
if (m->nesting_level_ == 0
|| ACE_OS::thr_equal (ACE_OS::thr_self (), m->owner_id_) == 0)
{
ACE_OS::thread_mutex_unlock (&m->nesting_mutex_);
errno = EINVAL;
return -1;
}
# endif /* ACE_NDEBUG */
// To make error recovery a bit easier, signal the condition now. Any
// waiter won't regain control until the mutex is released, which won't
// be until the caller returns and does the wait on the condition.
if (ACE_OS::cond_signal (&m->lock_available_) == -1)
{
// Save/restore errno.
ACE_Errno_Guard error (errno);
ACE_OS::thread_mutex_unlock (&m->nesting_mutex_);
return -1;
}
// Ok, the nesting_mutex_ lock is still held, the condition has been
// signaled... reset the nesting info and return _WITH_ the lock
// held. The lock will be released when the condition waits, in the
// caller.
state.nesting_level_ = m->nesting_level_;
state.owner_id_ = m->owner_id_;
m->nesting_level_ = 0;
m->owner_id_ = ACE_OS::NULL_thread;
return 0;
# endif /* ACE_HAS_RECURSIVE_MUTEXES */
#else
ACE_UNUSED_ARG (m);
ACE_UNUSED_ARG (state);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
// This method is called after waiting on a condition variable when a
// recursive mutex must be reacquired. If the platform doesn't natively
// integrate recursive mutexes and condition variables, it's taken care
// of here (inverse of ACE_OS::recursive_mutex_cond_unlock).
ACE_INLINE void
ACE_OS::recursive_mutex_cond_relock (ACE_recursive_thread_mutex_t *m,
ACE_recursive_mutex_state &state)
{
#if defined (ACE_HAS_THREADS)
ACE_OS_TRACE ("ACE_OS::recursive_mutex_cond_relock");
# if defined (ACE_HAS_RECURSIVE_MUTEXES)
// Windows need special handling since it has recursive mutexes, but
// does not integrate them into a condition variable.
// On entry, the OS has already reacquired the lock for us. Just
// reacquire it the proper number of times so the recursion is the same as
// before waiting on the condition.
# if defined (ACE_WIN32)
while (state.relock_count_ > 0)
{
ACE_OS::recursive_mutex_lock (m);
--state.relock_count_;
}
return;
# else /* not ACE_WIN32 */
// prevent warnings for unused variables
ACE_UNUSED_ARG (state);
ACE_UNUSED_ARG (m);
# endif /* ACE_WIN32 */
# else
// Without recursive mutex support, it's somewhat trickier. On entry,
// the current thread holds the nesting_mutex_, but another thread may
// still be holding the ACE_recursive_mutex_t. If so, mimic the code
// in ACE_OS::recursive_mutex_lock that waits to acquire the mutex.
// After acquiring it, restore the nesting counts and release the
// nesting mutex. This will restore the conditions to what they were
// before calling ACE_OS::recursive_mutex_cond_unlock().
while (m->nesting_level_ > 0)
ACE_OS::cond_wait (&m->lock_available_, &m->nesting_mutex_);
// At this point, we still have nesting_mutex_ and the mutex is free.
m->nesting_level_ = state.nesting_level_;
m->owner_id_ = state.owner_id_;
ACE_OS::thread_mutex_unlock (&m->nesting_mutex_);
return;
# endif /* ACE_HAS_RECURSIVE_MUTEXES */
#else
ACE_UNUSED_ARG (m);
ACE_UNUSED_ARG (state);
return;
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::recursive_mutex_destroy (ACE_recursive_thread_mutex_t *m)
{
#if defined (ACE_HAS_THREADS)
#if defined (ACE_HAS_RECURSIVE_MUTEXES)
return ACE_OS::thread_mutex_destroy (m);
#else
if (ACE_OS::thread_mutex_destroy (&m->nesting_mutex_) == -1)
return -1;
else if (ACE_OS::cond_destroy (&m->lock_available_) == -1)
return -1;
else
return 0;
#endif /* ACE_HAS_RECURSIVE_MUTEXES */
#else
ACE_UNUSED_ARG (m);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::recursive_mutex_init (ACE_recursive_thread_mutex_t *m,
const ACE_TCHAR *name,
ACE_mutexattr_t *arg,
LPSECURITY_ATTRIBUTES sa)
{
ACE_UNUSED_ARG (sa);
#if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_RECURSIVE_MUTEXES)
# if defined (ACE_HAS_PTHREADS_UNIX98_EXT)
return ACE_OS::thread_mutex_init (m, PTHREAD_MUTEX_RECURSIVE, name, arg);
# else
return ACE_OS::thread_mutex_init (m, 0, name, arg);
# endif /* ACE_HAS_PTHREADS_UNIX98_EXT */
# else
if (ACE_OS::thread_mutex_init (&m->nesting_mutex_, 0, name, arg) == -1)
return -1;
else if (ACE_OS::cond_init (&m->lock_available_,
(short) USYNC_THREAD,
name,
0) == -1)
return -1;
else
{
m->nesting_level_ = 0;
m->owner_id_ = ACE_OS::NULL_thread;
return 0;
}
# endif /* ACE_HAS_RECURSIVE_MUTEXES */
#else
ACE_UNUSED_ARG (m);
ACE_UNUSED_ARG (name);
ACE_UNUSED_ARG (arg);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::recursive_mutex_lock (ACE_recursive_thread_mutex_t *m)
{
#if defined (ACE_HAS_THREADS)
#if defined (ACE_HAS_RECURSIVE_MUTEXES)
return ACE_OS::thread_mutex_lock (m);
#else
ACE_thread_t const t_id = ACE_OS::thr_self ();
int result = 0;
// Acquire the guard.
if (ACE_OS::thread_mutex_lock (&m->nesting_mutex_) == -1)
result = -1;
else
{
// If there's no contention, just grab the lock immediately
// (since this is the common case we'll optimize for it).
if (m->nesting_level_ == 0)
m->owner_id_ = t_id;
// If we already own the lock, then increment the nesting level
// and return.
else if (ACE_OS::thr_equal (t_id, m->owner_id_) == 0)
{
// Wait until the nesting level has dropped to zero, at
// which point we can acquire the lock.
while (m->nesting_level_ > 0)
ACE_OS::cond_wait (&m->lock_available_,
&m->nesting_mutex_);
// At this point the nesting_mutex_ is held...
m->owner_id_ = t_id;
}
// At this point, we can safely increment the nesting_level_ no
// matter how we got here!
++m->nesting_level_;
}
{
// Save/restore errno.
ACE_Errno_Guard error (errno);
ACE_OS::thread_mutex_unlock (&m->nesting_mutex_);
}
return result;
#endif /* ACE_HAS_RECURSIVE_MUTEXES */
#else
ACE_UNUSED_ARG (m);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::recursive_mutex_lock (ACE_recursive_thread_mutex_t *m,
const ACE_Time_Value &timeout)
{
#if defined (ACE_HAS_THREADS)
#if defined (ACE_HAS_RECURSIVE_MUTEXES)
return ACE_OS::thread_mutex_lock (m, timeout);
#else
ACE_thread_t t_id = ACE_OS::thr_self ();
int result = 0;
// Try to acquire the guard.
if (ACE_OS::thread_mutex_lock (&m->nesting_mutex_, timeout) == -1)
result = -1;
else
{
// If there's no contention, just grab the lock immediately
// (since this is the common case we'll optimize for it).
if (m->nesting_level_ == 0)
m->owner_id_ = t_id;
// If we already own the lock, then increment the nesting level
// and return.
else if (ACE_OS::thr_equal (t_id, m->owner_id_) == 0)
{
// Wait until the nesting level has dropped to zero, at
// which point we can acquire the lock.
while (m->nesting_level_ > 0)
{
result = ACE_OS::cond_timedwait (&m->lock_available_,
&m->nesting_mutex_,
const_cast <ACE_Time_Value *> (&timeout));
// The mutex is reacquired even in the case of a timeout
// release the mutex to prevent a deadlock
if (result == -1)
{
// Save/restore errno.
ACE_Errno_Guard error (errno);
ACE_OS::thread_mutex_unlock (&m->nesting_mutex_);
return result;
}
}
// At this point the nesting_mutex_ is held...
m->owner_id_ = t_id;
}
// At this point, we can safely increment the nesting_level_ no
// matter how we got here!
m->nesting_level_++;
// Save/restore errno.
ACE_Errno_Guard error (errno);
ACE_OS::thread_mutex_unlock (&m->nesting_mutex_);
}
return result;
#endif /* ACE_HAS_RECURSIVE_MUTEXES */
#else
ACE_UNUSED_ARG (m);
ACE_UNUSED_ARG (timeout);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::recursive_mutex_lock (ACE_recursive_thread_mutex_t *m,
const ACE_Time_Value *timeout)
{
return timeout == 0
? ACE_OS::recursive_mutex_lock (m)
: ACE_OS::recursive_mutex_lock (m, *timeout);
}
ACE_INLINE int
ACE_OS::recursive_mutex_trylock (ACE_recursive_thread_mutex_t *m)
{
#if defined (ACE_HAS_THREADS)
#if defined (ACE_HAS_RECURSIVE_MUTEXES)
return ACE_OS::thread_mutex_trylock (m);
#else
ACE_thread_t t_id = ACE_OS::thr_self ();
int result = 0;
// Acquire the guard.
if (ACE_OS::thread_mutex_lock (&m->nesting_mutex_) == -1)
result = -1;
else
{
// If there's no contention, just grab the lock immediately.
if (m->nesting_level_ == 0)
{
m->owner_id_ = t_id;
m->nesting_level_ = 1;
}
// If we already own the lock, then increment the nesting level
// and proceed.
else if (ACE_OS::thr_equal (t_id, m->owner_id_))
m->nesting_level_++;
else
{
errno = EBUSY;
result = -1;
}
}
{
// Save/restore errno.
ACE_Errno_Guard error (errno);
ACE_OS::thread_mutex_unlock (&m->nesting_mutex_);
}
return result;
#endif /* ACE_HAS_RECURSIVE_MUTEXES */
#else
ACE_UNUSED_ARG (m);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::recursive_mutex_unlock (ACE_recursive_thread_mutex_t *m)
{
#if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_RECURSIVE_MUTEXES)
return ACE_OS::thread_mutex_unlock (m);
# else
ACE_OS_TRACE ("ACE_OS::recursive_mutex_unlock");
# if !defined (ACE_NDEBUG)
ACE_thread_t t_id = ACE_OS::thr_self ();
# endif /* ACE_NDEBUG */
int result = 0;
if (ACE_OS::thread_mutex_lock (&m->nesting_mutex_) == -1)
result = -1;
else
{
# if !defined (ACE_NDEBUG)
if (m->nesting_level_ == 0
|| ACE_OS::thr_equal (t_id, m->owner_id_) == 0)
{
errno = EINVAL;
result = -1;
}
else
# endif /* ACE_NDEBUG */
{
m->nesting_level_--;
if (m->nesting_level_ == 0)
{
// This may not be strictly necessary, but it does put
// the mutex into a known state...
m->owner_id_ = ACE_OS::NULL_thread;
// Inform a waiter that the lock is free.
if (ACE_OS::cond_signal (&m->lock_available_) == -1)
result = -1;
}
}
}
{
// Save/restore errno.
ACE_Errno_Guard error (errno);
ACE_OS::thread_mutex_unlock (&m->nesting_mutex_);
}
return result;
# endif /* ACE_HAS_RECURSIVE_MUTEXES */
#else
ACE_UNUSED_ARG (m);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::rw_rdlock (ACE_rwlock_t *rw)
{
ACE_OS_TRACE ("ACE_OS::rw_rdlock");
#if defined (ACE_HAS_THREADS)
# if !defined (ACE_LACKS_RWLOCK_T) || defined (ACE_HAS_PTHREADS_UNIX98_EXT)
# if defined (ACE_HAS_PTHREADS_UNIX98_EXT)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_rwlock_rdlock (rw),
result),
int, -1);
# else /* Solaris */
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::rw_rdlock (rw), result), int, -1);
# endif /* ACE_HAS_PTHREADS_UNIX98_EXT */
# else /* NT, POSIX, and VxWorks don't support this natively. */
# if defined (ACE_HAS_PTHREADS)
ACE_PTHREAD_CLEANUP_PUSH (&rw->lock_);
# endif /* ACE_HAS_PTHREADS */
int result = 0;
if (ACE_OS::mutex_lock (&rw->lock_) == -1)
result = -1; // -1 means didn't get the mutex.
else
{
// Give preference to writers who are waiting.
while (rw->ref_count_ < 0 || rw->num_waiting_writers_ > 0)
{
rw->num_waiting_readers_++;
if (ACE_OS::cond_wait (&rw->waiting_readers_, &rw->lock_) == -1)
{
result = -2; // -2 means that we need to release the mutex.
break;
}
rw->num_waiting_readers_--;
}
}
if (result == 0)
rw->ref_count_++;
if (result != -1)
ACE_OS::mutex_unlock (&rw->lock_);
# if defined (ACE_HAS_PTHREADS)
ACE_PTHREAD_CLEANUP_POP (0);
# endif /* defined (ACE_HAS_PTHREADS) */
return 0;
# endif /* ! ACE_LACKS_RWLOCK_T */
#else
ACE_UNUSED_ARG (rw);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::rw_tryrdlock (ACE_rwlock_t *rw)
{
ACE_OS_TRACE ("ACE_OS::rw_tryrdlock");
#if defined (ACE_HAS_THREADS)
# if !defined (ACE_LACKS_RWLOCK_T) || defined (ACE_HAS_PTHREADS_UNIX98_EXT)
# if defined (ACE_HAS_PTHREADS_UNIX98_EXT)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_rwlock_tryrdlock (rw),
result),
int, -1);
# else /* Solaris */
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::rw_tryrdlock (rw), result), int, -1);
# endif /* ACE_HAS_PTHREADS_UNIX98_EXT */
# else /* NT, POSIX, and VxWorks don't support this natively. */
int result = -1;
if (ACE_OS::mutex_lock (&rw->lock_) != -1)
{
ACE_Errno_Guard error (errno);
if (rw->ref_count_ == -1 || rw->num_waiting_writers_ > 0)
{
error = EBUSY;
result = -1;
}
else
{
rw->ref_count_++;
result = 0;
}
ACE_OS::mutex_unlock (&rw->lock_);
}
return result;
# endif /* ! ACE_LACKS_RWLOCK_T */
#else
ACE_UNUSED_ARG (rw);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::rw_trywrlock (ACE_rwlock_t *rw)
{
ACE_OS_TRACE ("ACE_OS::rw_trywrlock");
#if defined (ACE_HAS_THREADS)
# if !defined (ACE_LACKS_RWLOCK_T) || defined (ACE_HAS_PTHREADS_UNIX98_EXT)
# if defined (ACE_HAS_PTHREADS_UNIX98_EXT)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_rwlock_trywrlock (rw),
result),
int, -1);
# else /* Solaris */
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::rw_trywrlock (rw), result), int, -1);
# endif /* ACE_HAS_PTHREADS_UNIX98_EXT */
# else /* NT, POSIX, and VxWorks don't support this natively. */
int result = -1;
if (ACE_OS::mutex_lock (&rw->lock_) != -1)
{
ACE_Errno_Guard error (errno);
if (rw->ref_count_ != 0)
{
error = EBUSY;
result = -1;
}
else
{
rw->ref_count_ = -1;
result = 0;
}
ACE_OS::mutex_unlock (&rw->lock_);
}
return result;
# endif /* ! ACE_LACKS_RWLOCK_T */
#else
ACE_UNUSED_ARG (rw);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
// Note that the caller of this method *must* already possess this
// lock as a read lock.
// return {-1 and no errno set means: error,
// -1 and errno==EBUSY set means: could not upgrade,
// 0 means: upgraded successfully}
ACE_INLINE int
ACE_OS::rw_trywrlock_upgrade (ACE_rwlock_t *rw)
{
ACE_OS_TRACE ("ACE_OS::rw_trywrlock_upgrade");
#if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_PTHREADS_UNIX98_EXT)
// This will probably result in -1, EDEADLK, at least on HP-UX, but let it
// go - it's a more descriptive error than ENOTSUP.
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_rwlock_trywrlock (rw),
result),
int, -1);
# elif !defined (ACE_LACKS_RWLOCK_T)
// Some native rwlocks, such as those on Solaris, don't
// support the upgrade feature . . .
ACE_UNUSED_ARG (rw);
ACE_NOTSUP_RETURN (-1);
# else /* NT, POSIX, and VxWorks don't support this natively. */
// The ACE rwlock emulation does support upgrade . . .
int result = 0;
# if defined (ACE_HAS_PTHREADS)
ACE_PTHREAD_CLEANUP_PUSH (&rw->lock_);
# endif /* defined (ACE_HAS_PTHREADS) */
if (ACE_OS::mutex_lock (&rw->lock_) == -1)
return -1;
// -1 means didn't get the mutex, error
else if (rw->important_writer_)
// an other reader upgrades already
{
result = -1;
errno = EBUSY;
}
else
{
while (rw->ref_count_ > 1) // wait until only I am left
{
rw->num_waiting_writers_++; // prohibit any more readers
rw->important_writer_ = true;
if (ACE_OS::cond_wait (&rw->waiting_important_writer_, &rw->lock_) == -1)
{
result = -1;
// we know that we have the lock again, we have this guarantee,
// but something went wrong
}
rw->important_writer_ = false;
rw->num_waiting_writers_--;
}
if (result == 0)
{
// nothing bad happend
rw->ref_count_ = -1;
// now I am a writer
// everything is O.K.
}
}
ACE_OS::mutex_unlock (&rw->lock_);
# if defined (ACE_HAS_PTHREADS)
ACE_PTHREAD_CLEANUP_POP (0);
# endif /* defined (ACE_HAS_PTHREADS) */
return result;
# endif /* ! ACE_LACKS_RWLOCK_T */
#else
ACE_UNUSED_ARG (rw);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::rw_unlock (ACE_rwlock_t *rw)
{
ACE_OS_TRACE ("ACE_OS::rw_unlock");
#if defined (ACE_HAS_THREADS)
# if !defined (ACE_LACKS_RWLOCK_T) || defined (ACE_HAS_PTHREADS_UNIX98_EXT)
# if defined (ACE_HAS_PTHREADS_UNIX98_EXT)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_rwlock_unlock (rw),
result),
int, -1);
# else /* Solaris */
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::rw_unlock (rw), result), int, -1);
# endif /* ACE_HAS_PTHREADS_UNIX98_EXT */
# else /* NT, POSIX, and VxWorks don't support this natively. */
if (ACE_OS::mutex_lock (&rw->lock_) == -1)
return -1;
if (rw->ref_count_ > 0) // Releasing a reader.
rw->ref_count_--;
else if (rw->ref_count_ == -1) // Releasing a writer.
rw->ref_count_ = 0;
else
{
(void) ACE_OS::mutex_unlock (&rw->lock_);
return -1; // @@ ACE_ASSERT (!"count should not be 0!\n");
}
int result = 0;
ACE_Errno_Guard error (errno);
if (rw->important_writer_ && rw->ref_count_ == 1)
// only the reader requesting to upgrade its lock is left over.
{
result = ACE_OS::cond_signal (&rw->waiting_important_writer_);
error = errno;
}
else if (rw->num_waiting_writers_ > 0 && rw->ref_count_ == 0)
// give preference to writers over readers...
{
result = ACE_OS::cond_signal (&rw->waiting_writers_);
error = errno;
}
else if (rw->num_waiting_readers_ > 0 && rw->num_waiting_writers_ == 0)
{
result = ACE_OS::cond_broadcast (&rw->waiting_readers_);
error = errno;
}
(void) ACE_OS::mutex_unlock (&rw->lock_);
return result;
# endif /* ! ace_lacks_rwlock_t */
#else
ACE_UNUSED_ARG (rw);
ACE_NOTSUP_RETURN (-1);
#endif /* ace_has_threads */
}
ACE_INLINE int
ACE_OS::rw_wrlock (ACE_rwlock_t *rw)
{
ACE_OS_TRACE ("ACE_OS::rw_wrlock");
#if defined (ACE_HAS_THREADS)
# if !defined (ACE_LACKS_RWLOCK_T) || defined (ACE_HAS_PTHREADS_UNIX98_EXT)
# if defined (ACE_HAS_PTHREADS_UNIX98_EXT)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_rwlock_wrlock (rw),
result),
int, -1);
# else /* Solaris */
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::rw_wrlock (rw), result), int, -1);
# endif /* ACE_HAS_PTHREADS_UNIX98_EXT */
# else /* NT, POSIX, and VxWorks don't support this natively. */
# if defined (ACE_HAS_PTHREADS)
ACE_PTHREAD_CLEANUP_PUSH (&rw->lock_);
# endif /* defined (ACE_HAS_PTHREADS) */
int result = 0;
if (ACE_OS::mutex_lock (&rw->lock_) == -1)
result = -1; // -1 means didn't get the mutex.
else
{
while (rw->ref_count_ != 0)
{
rw->num_waiting_writers_++;
if (ACE_OS::cond_wait (&rw->waiting_writers_, &rw->lock_) == -1)
{
result = -2; // -2 means we need to release the mutex.
break;
}
rw->num_waiting_writers_--;
}
}
if (result == 0)
rw->ref_count_ = -1;
if (result != -1)
ACE_OS::mutex_unlock (&rw->lock_);
# if defined (ACE_HAS_PTHREADS)
ACE_PTHREAD_CLEANUP_POP (0);
# endif /* defined (ACE_HAS_PTHREADS) */
return 0;
# endif /* ! ACE_LACKS_RWLOCK_T */
#else
ACE_UNUSED_ARG (rw);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::rwlock_destroy (ACE_rwlock_t *rw)
{
ACE_OS_TRACE ("ACE_OS::rwlock_destroy");
#if defined (ACE_HAS_THREADS)
# if !defined (ACE_LACKS_RWLOCK_T) || defined (ACE_HAS_PTHREADS_UNIX98_EXT)
# if defined (ACE_HAS_PTHREADS_UNIX98_EXT)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_rwlock_destroy (rw),
result),
int, -1);
# else /* Solaris */
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::rwlock_destroy (rw), result), int, -1);
# endif /* ACE_HAS_PTHREADS_UNIX98_EXT */
# else /* NT, POSIX, and VxWorks don't support this natively. */
ACE_OS::mutex_destroy (&rw->lock_);
ACE_OS::cond_destroy (&rw->waiting_readers_);
ACE_OS::cond_destroy (&rw->waiting_important_writer_);
return ACE_OS::cond_destroy (&rw->waiting_writers_);
# endif /* ACE_HAS_STHREADS && !defined (ACE_LACKS_RWLOCK_T) */
#else
ACE_UNUSED_ARG (rw);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
#if defined (ACE_HAS_THREADS) && (!defined (ACE_LACKS_RWLOCK_T) || \
defined (ACE_HAS_PTHREADS_UNIX98_EXT))
ACE_INLINE int
ACE_OS::rwlock_init (ACE_rwlock_t *rw,
int type,
const ACE_TCHAR *name,
void *arg)
{
// ACE_OS_TRACE ("ACE_OS::rwlock_init");
# if defined (ACE_HAS_PTHREADS_UNIX98_EXT)
ACE_UNUSED_ARG (name);
ACE_UNUSED_ARG (arg);
int status;
pthread_rwlockattr_t attr;
pthread_rwlockattr_init (&attr);
# if !defined (ACE_LACKS_RWLOCKATTR_PSHARED)
pthread_rwlockattr_setpshared (&attr, (type == USYNC_THREAD ?
PTHREAD_PROCESS_PRIVATE :
PTHREAD_PROCESS_SHARED));
# else
ACE_UNUSED_ARG (type);
# endif /* !ACE_LACKS_RWLOCKATTR_PSHARED */
status = ACE_ADAPT_RETVAL (pthread_rwlock_init (rw, &attr), status);
pthread_rwlockattr_destroy (&attr);
return status;
# else
type = type;
name = name;
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::rwlock_init (rw, type, arg), result), int, -1);
# endif /* ACE_HAS_PTHREADS_UNIX98_EXT */
}
#endif /* ACE_HAS THREADS && !defined (ACE_LACKS_RWLOCK_T) */
ACE_INLINE int
ACE_OS::sema_destroy (ACE_sema_t *s)
{
ACE_OS_TRACE ("ACE_OS::sema_destroy");
# if defined (ACE_HAS_POSIX_SEM)
int result;
# if !defined (ACE_HAS_POSIX_SEM_TIMEOUT) && !defined (ACE_DISABLE_POSIX_SEM_TIMEOUT_EMULATION)
ACE_OS::mutex_destroy (&s->lock_);
ACE_OS::cond_destroy (&s->count_nonzero_);
# endif /* !ACE_HAS_POSIX_SEM_TIMEOUT && !ACE_DISABLE_POSIX_SEM_TIMEOUT_EMULATION */
# if defined (ACE_LACKS_NAMED_POSIX_SEM)
if (s->name_)
{
// Only destroy the semaphore if we're the ones who
// initialized it.
ACE_OSCALL (::sem_destroy (s->sema_),int, -1, result);
ACE_OS::shm_unlink (s->name_);
delete s->name_;
return result;
}
# else
if (s->name_)
{
ACE_OSCALL (::sem_unlink (s->name_), int, -1, result);
ACE_OS::free ((void *) s->name_);
ACE_OSCALL_RETURN (::sem_close (s->sema_), int, -1);
}
# endif /* ACE_LACKS_NAMED_POSIX_SEM */
else
{
ACE_OSCALL (::sem_destroy (s->sema_), int, -1, result);
# if defined (ACE_LACKS_NAMED_POSIX_SEM)
if (s->new_sema_)
# endif /* ACE_LACKS_NAMED_POSIX_SEM */
delete s->sema_;
s->sema_ = 0;
return result;
}
# elif defined (ACE_USES_FIFO_SEM)
int r0 = 0;
if (s->name_)
{
r0 = ACE_OS::unlink (s->name_);
ACE_OS::free (s->name_);
s->name_ = 0;
}
int r1 = ACE_OS::close (s->fd_[0]); /* ignore error */
int r2 = ACE_OS::close (s->fd_[1]); /* ignore error */
return r0 != 0 || r1 != 0 || r2 != 0 ? -1 : 0;
# elif defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_STHREADS)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::sema_destroy (s), result), int, -1);
# elif defined (ACE_HAS_PTHREADS)
int r1 = ACE_OS::mutex_destroy (&s->lock_);
int r2 = ACE_OS::cond_destroy (&s->count_nonzero_);
return r1 != 0 || r2 != 0 ? -1 : 0;
# elif defined (ACE_HAS_WTHREADS)
# if !defined (ACE_USES_WINCE_SEMA_SIMULATION)
ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::CloseHandle (*s), ace_result_), int, -1);
# else /* ACE_USES_WINCE_SEMA_SIMULATION */
// Free up underlying objects of the simulated semaphore.
int const r1 = ACE_OS::thread_mutex_destroy (&s->lock_);
int const r2 = ACE_OS::event_destroy (&s->count_nonzero_);
return r1 != 0 || r2 != 0 ? -1 : 0;
# endif /* ACE_USES_WINCE_SEMA_SIMULATION */
# elif defined (ACE_VXWORKS)
int result;
ACE_OSCALL (::semDelete (s->sema_), int, -1, result);
s->sema_ = 0;
return result;
# endif /* ACE_HAS_STHREADS */
# else
ACE_UNUSED_ARG (s);
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_POSIX_SEM */
}
// NOTE: The previous four function definitions must appear before
// ACE_OS::sema_init ().
ACE_INLINE int
ACE_OS::sema_init (ACE_sema_t *s,
u_int count,
int type,
const char *name,
void *arg,
int max,
LPSECURITY_ATTRIBUTES sa)
{
ACE_OS_TRACE ("ACE_OS::sema_init");
#if defined (ACE_HAS_POSIX_SEM)
ACE_UNUSED_ARG (max);
ACE_UNUSED_ARG (sa);
s->name_ = 0;
# if defined (ACE_HAS_POSIX_SEM_TIMEOUT) || defined (ACE_DISABLE_POSIX_SEM_TIMEOUT_EMULATION)
ACE_UNUSED_ARG (arg);
# else
int result = -1;
if (ACE_OS::mutex_init (&s->lock_, type, name,
(ACE_mutexattr_t *) arg) == 0
&& ACE_OS::cond_init (&s->count_nonzero_, (short)type, name, arg) == 0
&& ACE_OS::mutex_lock (&s->lock_) == 0)
{
if (ACE_OS::mutex_unlock (&s->lock_) == 0)
result = 0;
}
if (result == -1)
{
ACE_OS::mutex_destroy (&s->lock_);
ACE_OS::cond_destroy (&s->count_nonzero_);
return result;
}
# endif /* ACE_HAS_POSIX_SEM_TIMEOUT || ACE_DISABLE_POSIX_SEM_TIMEOUT_EMULATION */
# if defined (ACE_LACKS_NAMED_POSIX_SEM)
s->new_sema_ = false;
if (type == USYNC_PROCESS)
{
// Let's see if it already exists.
ACE_HANDLE fd = ACE_OS::shm_open (ACE_TEXT_CHAR_TO_TCHAR (name),
O_RDWR | O_CREAT | O_EXCL,
ACE_DEFAULT_FILE_PERMS);
if (fd == ACE_INVALID_HANDLE)
{
if (errno == EEXIST)
fd = ACE_OS::shm_open (ACE_TEXT_CHAR_TO_TCHAR (name),
O_RDWR | O_CREAT,
ACE_DEFAULT_FILE_PERMS);
else
return -1;
}
else
{
// We own this shared memory object! Let's set its
// size.
if (ACE_OS::ftruncate (fd,
sizeof (ACE_sema_t)) == -1)
return -1;
s->name_ = ACE_OS::strdup (name);
if (s->name_ == 0)
return -1;
}
if (fd == -1)
return -1;
s->sema_ = (sem_t *)
ACE_OS::mmap (0,
sizeof (ACE_sema_t),
PROT_RDWR,
MAP_SHARED,
fd,
0);
ACE_OS::close (fd);
if (s->sema_ == (sem_t *) MAP_FAILED)
return -1;
if (s->name_
// @@ According UNIX Network Programming V2 by Stevens,
// sem_init() is currently not required to return zero on
// success, but it *does* return -1 upon failure. For
// this reason, check for failure by comparing to -1,
// instead of checking for success by comparing to zero.
// -Ossama
// Only initialize it if we're the one who created it.
&& ::sem_init (s->sema_, type == USYNC_PROCESS, count) == -1)
return -1;
return 0;
}
# else
if (name)
{
# if defined (sun) || defined (HPUX)
// Solaris and HP-UX require the name to start with a slash. Solaris
// further requires that there be no other slashes than the first.
const char *last_slash = ACE_OS::strrchr (name, '/');
char name2[MAXPATHLEN];
if (0 == last_slash)
{
ACE_OS::strcpy (name2, "/");
ACE_OS::strcat (name2, name);
name = name2;
}
# if defined (sun)
else
name = last_slash; // Chop off chars preceding last slash
# endif /* sun */
# endif /* sun || HPUX */
ACE_ALLOCATOR_RETURN (s->name_,
ACE_OS::strdup (name),
-1);
s->sema_ = ::sem_open (s->name_,
O_CREAT,
ACE_DEFAULT_FILE_PERMS,
count);
if (s->sema_ == (sem_t *) SEM_FAILED)
return -1;
else
return 0;
}
# endif /* ACE_LACKS_NAMED_POSIX_SEM */
else
{
ACE_NEW_RETURN (s->sema_,
sem_t,
-1);
# if defined (ACE_LACKS_NAMED_POSIX_SEM)
s->new_sema_ = true;
# endif /* ACE_LACKS_NAMED_POSIX_SEM */
ACE_OSCALL_RETURN (::sem_init (s->sema_,
type != USYNC_THREAD,
count), int, -1);
}
#elif defined (ACE_USES_FIFO_SEM)
ACE_UNUSED_ARG (arg);
ACE_UNUSED_ARG (max);
ACE_UNUSED_ARG (sa);
int flags = 0;
mode_t mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP;
if (type == USYNC_THREAD)
{
// Create systemwide unique name for semaphore
char uname[ACE_UNIQUE_NAME_LEN];
ACE_OS::unique_name ((const void *) s,
uname,
ACE_UNIQUE_NAME_LEN);
name = &uname[0];
}
s->name_ = 0;
s->fd_[0] = s->fd_[1] = ACE_INVALID_HANDLE;
bool creator = false;
if (ACE_OS::mkfifo (ACE_TEXT_CHAR_TO_TCHAR (name), mode) < 0)
{
if (errno != EEXIST) /* already exists OK else ERR */
return -1;
// check if this is a real FIFO, not just some other existing file
ACE_stat fs;
if (ACE_OS::stat (name, &fs))
return -1;
if (!S_ISFIFO (fs.st_mode))
{
// existing file is not a FIFO
errno = EEXIST;
return -1;
}
}
else
creator = true; // remember we created it for initialization at end
// for processshared semaphores remember who we are to be able to remove
// the FIFO when we're done with it
if (type == USYNC_PROCESS)
{
s->name_ = ACE_OS::strdup (name);
if (s->name_ == 0)
{
if (creator)
ACE_OS::unlink (name);
return -1;
}
}
if ((s->fd_[0] = ACE_OS::open (name, O_RDONLY | O_NONBLOCK)) == ACE_INVALID_HANDLE
|| (s->fd_[1] = ACE_OS::open (name, O_WRONLY | O_NONBLOCK)) == ACE_INVALID_HANDLE)
return -1;
/* turn off nonblocking for fd_[0] */
if ((flags = ACE_OS::fcntl (s->fd_[0], F_GETFL, 0)) < 0)
return -1;
flags &= ~O_NONBLOCK;
if (ACE_OS::fcntl (s->fd_[0], F_SETFL, flags) < 0)
return -1;
//if (s->name_ && count)
if (creator && count)
{
char c = 1;
for (u_int i=0; i<count ;++i)
if (ACE_OS::write (s->fd_[1], &c, sizeof (char)) != 1)
return -1;
}
// In the case of process scope semaphores we can already unlink the FIFO now that
// we completely set it up (the opened handles will keep it active until we close
// thos down). This way we're protected against unexpected crashes as far as removal
// is concerned.
// Unfortunately this does not work for processshared FIFOs since as soon as we
// have unlinked the semaphore no other process will be able to open it anymore.
if (type == USYNC_THREAD)
{
ACE_OS::unlink (name);
}
return 0;
#elif defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_STHREADS)
ACE_UNUSED_ARG (name);
ACE_UNUSED_ARG (max);
ACE_UNUSED_ARG (sa);
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::sema_init (s, count, type, arg), result),
int, -1);
# elif defined (ACE_HAS_PTHREADS)
ACE_UNUSED_ARG (max);
ACE_UNUSED_ARG (sa);
int result = -1;
if (ACE_OS::mutex_init (&s->lock_, type, name,
(ACE_mutexattr_t *) arg) == 0
&& ACE_OS::cond_init (&s->count_nonzero_, type, name, arg) == 0
&& ACE_OS::mutex_lock (&s->lock_) == 0)
{
s->count_ = count;
s->waiters_ = 0;
if (ACE_OS::mutex_unlock (&s->lock_) == 0)
result = 0;
}
if (result == -1)
{
ACE_OS::mutex_destroy (&s->lock_);
ACE_OS::cond_destroy (&s->count_nonzero_);
}
return result;
# elif defined (ACE_HAS_WTHREADS)
# if ! defined (ACE_USES_WINCE_SEMA_SIMULATION)
ACE_UNUSED_ARG (type);
ACE_UNUSED_ARG (arg);
// Create the semaphore with its value initialized to <count> and
// its maximum value initialized to <max>.
SECURITY_ATTRIBUTES sa_buffer;
SECURITY_DESCRIPTOR sd_buffer;
*s = ACE_TEXT_CreateSemaphore
(ACE_OS::default_win32_security_attributes_r (sa, &sa_buffer, &sd_buffer),
count,
max,
ACE_TEXT_CHAR_TO_TCHAR (name));
if (*s == 0)
ACE_FAIL_RETURN (-1);
/* NOTREACHED */
else
{
// Make sure to set errno to ERROR_ALREADY_EXISTS if necessary.
ACE_OS::set_errno_to_last_error ();
return 0;
}
# else /* ACE_USES_WINCE_SEMA_SIMULATION */
int result = -1;
// Initialize internal object for semaphore simulation.
// Grab the lock as soon as possible when we initializing
// the semaphore count. Notice that we initialize the
// event object as "manually reset" so we can amortize the
// cost for singling/reseting the event.
// @@ I changed the mutex type to thread_mutex. Notice that this
// is basically a CriticalSection object and doesn't not has
// any security attribute whatsoever. However, since this
// semaphore implementation only works within a process, there
// shouldn't any security issue at all.
if (ACE_OS::thread_mutex_init (&s->lock_, type, name, (ACE_mutexattr_t *)arg) == 0
&& ACE_OS::event_init (&s->count_nonzero_, 1,
count > 0, type, name, arg, sa) == 0
&& ACE_OS::thread_mutex_lock (&s->lock_) == 0)
{
s->count_ = count;
if (ACE_OS::thread_mutex_unlock (&s->lock_) == 0)
result = 0;
}
// Destroy the internal objects if we didn't initialize
// either of them successfully. Don't bother to check
// for errors.
if (result == -1)
{
ACE_OS::thread_mutex_destroy (&s->lock_);
ACE_OS::event_destroy (&s->count_nonzero_);
}
return result;
# endif /* ACE_USES_WINCE_SEMA_SIMULATION */
# elif defined (ACE_VXWORKS)
ACE_UNUSED_ARG (name);
ACE_UNUSED_ARG (arg);
ACE_UNUSED_ARG (max);
ACE_UNUSED_ARG (sa);
s->name_ = 0;
s->sema_ = ::semCCreate (type, count);
return s->sema_ ? 0 : -1;
# endif /* ACE_HAS_STHREADS */
#else
ACE_UNUSED_ARG (s);
ACE_UNUSED_ARG (count);
ACE_UNUSED_ARG (type);
ACE_UNUSED_ARG (name);
ACE_UNUSED_ARG (arg);
ACE_UNUSED_ARG (max);
ACE_UNUSED_ARG (sa);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_POSIX_SEM */
}
#if defined (ACE_HAS_WCHAR)
ACE_INLINE int
ACE_OS::sema_init (ACE_sema_t *s,
u_int count,
int type,
const wchar_t *name,
void *arg,
int max,
LPSECURITY_ATTRIBUTES sa)
{
# if defined (ACE_HAS_WTHREADS)
# if ! defined (ACE_USES_WINCE_SEMA_SIMULATION)
ACE_UNUSED_ARG (type);
ACE_UNUSED_ARG (arg);
// Create the semaphore with its value initialized to <count> and
// its maximum value initialized to <max>.
SECURITY_ATTRIBUTES sa_buffer;
SECURITY_DESCRIPTOR sd_buffer;
*s = ::CreateSemaphoreW
(ACE_OS::default_win32_security_attributes_r (sa, &sa_buffer, &sd_buffer),
count,
max,
name);
if (*s == 0)
ACE_FAIL_RETURN (-1);
/* NOTREACHED */
else
{
// Make sure to set errno to ERROR_ALREADY_EXISTS if necessary.
ACE_OS::set_errno_to_last_error ();
return 0;
}
# else /* ACE_USES_WINCE_SEMA_SIMULATION */
int result = -1;
// Initialize internal object for semaphore simulation.
// Grab the lock as soon as possible when we initializing
// the semaphore count. Notice that we initialize the
// event object as "manually reset" so we can amortize the
// cost for singling/reseting the event.
// @@ I changed the mutex type to thread_mutex. Notice that this
// is basically a CriticalSection object and doesn't not has
// any security attribute whatsoever. However, since this
// semaphore implementation only works within a process, there
// shouldn't any security issue at all.
if (ACE_OS::thread_mutex_init (&s->lock_, type, name, (ACE_mutexattr_t *)arg) == 0
&& ACE_OS::event_init (&s->count_nonzero_, 1,
count > 0, type, name, arg, sa) == 0
&& ACE_OS::thread_mutex_lock (&s->lock_) == 0)
{
s->count_ = count;
if (ACE_OS::thread_mutex_unlock (&s->lock_) == 0)
result = 0;
}
// Destroy the internal objects if we didn't initialize
// either of them successfully. Don't bother to check
// for errors.
if (result == -1)
{
ACE_OS::thread_mutex_destroy (&s->lock_);
ACE_OS::event_destroy (&s->count_nonzero_);
}
return result;
# endif /* ACE_USES_WINCE_SEMA_SIMULATION */
# else /* ACE_HAS_WTHREADS */
// Just call the normal char version.
return ACE_OS::sema_init (s, count, type, ACE_Wide_To_Ascii (name).char_rep (), arg, max, sa);
# endif /* ACE_HAS_WTHREADS */
}
#endif /* ACE_HAS_WCHAR */
ACE_INLINE int
ACE_OS::sema_post (ACE_sema_t *s)
{
ACE_OS_TRACE ("ACE_OS::sema_post");
# if defined (ACE_HAS_POSIX_SEM)
# if defined (ACE_HAS_POSIX_SEM_TIMEOUT) || defined (ACE_DISABLE_POSIX_SEM_TIMEOUT_EMULATION)
ACE_OSCALL_RETURN (::sem_post (s->sema_), int, -1);
# else
int result = -1;
if (ACE_OS::mutex_lock (&s->lock_) == 0)
{
if (::sem_post (s->sema_) == 0)
result = ACE_OS::cond_signal (&s->count_nonzero_);
ACE_OS::mutex_unlock (&s->lock_);
}
return result;
# endif /* ACE_HAS_POSIX_SEM_TIMEOUT || ACE_DISABLE_POSIX_SEM_TIMEOUT_EMULATION */
# elif defined (ACE_USES_FIFO_SEM)
char c = 1;
if (ACE_OS::write (s->fd_[1], &c, sizeof (char)) == sizeof (char))
return 0;
return -1;
# elif defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_STHREADS)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::sema_post (s), result), int, -1);
# elif defined (ACE_HAS_PTHREADS)
int result = -1;
if (ACE_OS::mutex_lock (&s->lock_) == 0)
{
// Always allow a waiter to continue if there is one.
if (s->waiters_ > 0)
result = ACE_OS::cond_signal (&s->count_nonzero_);
else
result = 0;
s->count_++;
ACE_OS::mutex_unlock (&s->lock_);
}
return result;
# elif defined (ACE_HAS_WTHREADS)
# if !defined (ACE_USES_WINCE_SEMA_SIMULATION)
ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::ReleaseSemaphore (*s, 1, 0),
ace_result_),
int, -1);
# else /* ACE_USES_WINCE_SEMA_SIMULATION */
int result = -1;
// Since we are simulating semaphores, we need to update semaphore
// count manually. Grab the lock to prevent race condition first.
if (ACE_OS::thread_mutex_lock (&s->lock_) == 0)
{
// Check the original state of event object. Single the event
// object in transition from semaphore not available to
// semaphore available.
if (s->count_++ <= 0)
result = ACE_OS::event_signal (&s->count_nonzero_);
else
result = 0;
ACE_OS::thread_mutex_unlock (&s->lock_);
}
return result;
# endif /* ACE_USES_WINCE_SEMA_SIMULATION */
# elif defined (ACE_VXWORKS)
ACE_OSCALL_RETURN (::semGive (s->sema_), int, -1);
# endif /* ACE_HAS_STHREADS */
# else
ACE_UNUSED_ARG (s);
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_POSIX_SEM */
}
ACE_INLINE int
ACE_OS::sema_post (ACE_sema_t *s, u_int release_count)
{
#if defined (ACE_WIN32) && !defined (ACE_USES_WINCE_SEMA_SIMULATION)
// Win32 supports this natively.
ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::ReleaseSemaphore (*s, release_count, 0),
ace_result_), int, -1);
#else
// On POSIX platforms we need to emulate this ourselves.
// @@ We can optimize on this implementation. However,
// the semaphore promitive on Win32 doesn't allow one
// to increase a semaphore to more than the count it was
// first initialized. Posix and solaris don't seem to have
// this restriction. Should we impose the restriction in
// our semaphore simulation?
for (size_t i = 0; i < release_count; i++)
if (ACE_OS::sema_post (s) == -1)
return -1;
return 0;
#endif /* ACE_WIN32 */
}
ACE_INLINE int
ACE_OS::sema_trywait (ACE_sema_t *s)
{
ACE_OS_TRACE ("ACE_OS::sema_trywait");
# if defined (ACE_HAS_POSIX_SEM)
// POSIX semaphores set errno to EAGAIN if trywait fails
ACE_OSCALL_RETURN (::sem_trywait (s->sema_), int, -1);
# elif defined (ACE_USES_FIFO_SEM)
char c;
int rc, flags;
/* turn on nonblocking for s->fd_[0] */
if ((flags = ACE_OS::fcntl (s->fd_[0], F_GETFL, 0)) < 0)
return -1;
flags |= O_NONBLOCK;
if (ACE_OS::fcntl (s->fd_[0], F_SETFL, flags) < 0)
return -1;
// read sets errno to EAGAIN if no input
rc = ACE_OS::read (s->fd_[0], &c, sizeof (char));
/* turn off nonblocking for fd_[0] */
if ((flags = ACE_OS::fcntl (s->fd_[0], F_GETFL, 0)) >= 0)
{
flags &= ~O_NONBLOCK;
ACE_OS::fcntl (s->fd_[0], F_SETFL, flags);
}
return rc == 1 ? 0 : (-1);
# elif defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_STHREADS)
// STHREADS semaphores set errno to EBUSY if trywait fails.
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::sema_trywait (s),
result),
int, -1);
# elif defined (ACE_HAS_PTHREADS)
int result = -1;
if (ACE_OS::mutex_lock (&s->lock_) == 0)
{
if (s->count_ > 0)
{
--s->count_;
result = 0;
}
else
errno = EBUSY;
ACE_OS::mutex_unlock (&s->lock_);
}
return result;
# elif defined (ACE_HAS_WTHREADS)
# if !defined (ACE_USES_WINCE_SEMA_SIMULATION)
DWORD result = ::WaitForSingleObject (*s, 0);
if (result == WAIT_OBJECT_0)
return 0;
else
{
if (result == WAIT_TIMEOUT)
errno = EBUSY;
else
ACE_OS::set_errno_to_last_error ();
// This is a hack, we need to find an appropriate mapping...
return -1;
}
# else /* ACE_USES_WINCE_SEMA_SIMULATION */
// Check the status of semaphore first. Return immediately
// if the semaphore is not available and avoid grabing the
// lock.
DWORD result = ::WaitForSingleObject (s->count_nonzero_, 0);
if (result == WAIT_OBJECT_0) // Proceed when it is available.
{
ACE_OS::thread_mutex_lock (&s->lock_);
// Need to double check if the semaphore is still available.
// The double checking scheme will slightly affect the
// efficiency if most of the time semaphores are not blocked.
result = ::WaitForSingleObject (s->count_nonzero_, 0);
if (result == WAIT_OBJECT_0)
{
// Adjust the semaphore count. Only update the event
// object status when the state changed.
s->count_--;
if (s->count_ <= 0)
ACE_OS::event_reset (&s->count_nonzero_);
result = 0;
}
ACE_OS::thread_mutex_unlock (&s->lock_);
}
// Translate error message to errno used by ACE.
if (result == WAIT_TIMEOUT)
errno = EBUSY;
else
ACE_OS::set_errno_to_last_error ();
// This is taken from the hack above. ;)
return -1;
# endif /* ACE_USES_WINCE_SEMA_SIMULATION */
# elif defined (ACE_VXWORKS)
if (::semTake (s->sema_, NO_WAIT) == ERROR)
if (errno == S_objLib_OBJ_UNAVAILABLE)
{
// couldn't get the semaphore
errno = EBUSY;
return -1;
}
else
// error
return -1;
else
// got the semaphore
return 0;
# endif /* ACE_HAS_STHREADS */
# else
ACE_UNUSED_ARG (s);
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_POSIX_SEM */
}
ACE_INLINE int
ACE_OS::sema_wait (ACE_sema_t *s)
{
ACE_OS_TRACE ("ACE_OS::sema_wait");
# if defined (ACE_HAS_POSIX_SEM)
ACE_OSCALL_RETURN (::sem_wait (s->sema_), int, -1);
# elif defined (ACE_USES_FIFO_SEM)
char c;
if (ACE_OS::read (s->fd_[0], &c, sizeof (char)) == 1)
return 0;
return -1;
# elif defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_STHREADS)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::sema_wait (s), result), int, -1);
# elif defined (ACE_HAS_PTHREADS)
int result = 0;
ACE_PTHREAD_CLEANUP_PUSH (&s->lock_);
if (ACE_OS::mutex_lock (&s->lock_) != 0)
result = -1;
else
{
// Keep track of the number of waiters so that we can signal
// them properly in <ACE_OS::sema_post>.
s->waiters_++;
// Wait until the semaphore count is > 0.
while (s->count_ == 0)
if (ACE_OS::cond_wait (&s->count_nonzero_,
&s->lock_) == -1)
{
result = -2; // -2 means that we need to release the mutex.
break;
}
--s->waiters_;
}
if (result == 0)
--s->count_;
if (result != -1)
ACE_OS::mutex_unlock (&s->lock_);
ACE_PTHREAD_CLEANUP_POP (0);
return result < 0 ? -1 : result;
# elif defined (ACE_HAS_WTHREADS)
# if !defined (ACE_USES_WINCE_SEMA_SIMULATION)
switch (::WaitForSingleObject (*s, INFINITE))
{
case WAIT_OBJECT_0:
return 0;
default:
// This is a hack, we need to find an appropriate mapping...
ACE_OS::set_errno_to_last_error ();
return -1;
}
/* NOTREACHED */
# else /* ACE_USES_WINCE_SEMA_SIMULATION */
// Timed wait.
int result = -1;
for (;;)
// Check if the semaphore is avialable or not and wait forever.
// Don't bother to grab the lock if it is not available (to avoid
// deadlock.)
switch (::WaitForSingleObject (s->count_nonzero_, INFINITE))
{
case WAIT_OBJECT_0:
ACE_OS::thread_mutex_lock (&s->lock_);
// Need to double check if the semaphore is still available.
// This time, we shouldn't wait at all.
if (::WaitForSingleObject (s->count_nonzero_, 0) == WAIT_OBJECT_0)
{
// Decrease the internal counter. Only update the event
// object's status when the state changed.
s->count_--;
if (s->count_ <= 0)
ACE_OS::event_reset (&s->count_nonzero_);
result = 0;
}
ACE_OS::thread_mutex_unlock (&s->lock_);
// if we didn't get a hold on the semaphore, the result won't
// be 0 and thus, we'll start from the beginning again.
if (result == 0)
return 0;
break;
default:
// Since we wait indefinitely, anything other than
// WAIT_OBJECT_O indicates an error.
ACE_OS::set_errno_to_last_error ();
// This is taken from the hack above. ;)
return -1;
}
/* NOTREACHED */
# endif /* ACE_USES_WINCE_SEMA_SIMULATION */
# elif defined (ACE_VXWORKS)
ACE_OSCALL_RETURN (::semTake (s->sema_, WAIT_FOREVER), int, -1);
# endif /* ACE_HAS_STHREADS */
# else
ACE_UNUSED_ARG (s);
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_POSIX_SEM */
}
ACE_INLINE int
ACE_OS::sema_wait (ACE_sema_t *s, ACE_Time_Value &tv)
{
ACE_OS_TRACE ("ACE_OS::sema_wait");
# if defined (ACE_HAS_POSIX_SEM)
# if defined (ACE_HAS_POSIX_SEM_TIMEOUT)
int rc;
timespec_t ts;
ts = tv; // Calls ACE_Time_Value::operator timespec_t().
ACE_OSCALL (::sem_timedwait (s->sema_, &ts), int, -1, rc);
if (rc == -1 && errno == ETIMEDOUT)
errno = ETIME; /* POSIX returns ETIMEDOUT but we need ETIME */
return rc;
# elif !defined (ACE_DISABLE_POSIX_SEM_TIMEOUT_EMULATION)
int result = 0;
bool expired = false;
ACE_Errno_Guard error (errno);
ACE_PTHREAD_CLEANUP_PUSH (&s->lock_);
if (ACE_OS::mutex_lock (&s->lock_) != 0)
result = -2;
else
{
bool finished = true;
do
{
result = ACE_OS::sema_trywait (s);
if (result == -1 && errno == EAGAIN)
expired = ACE_OS::gettimeofday () > tv;
else
expired = false;
finished = result != -1 || expired ||
(result == -1 && errno != EAGAIN);
if (!finished)
{
if (ACE_OS::cond_timedwait (&s->count_nonzero_,
&s->lock_,
&tv) == -1)
{
error = errno;
result = -1;
break;
}
}
} while (!finished);
if (expired)
error = ETIME;
# if defined (ACE_LACKS_COND_TIMEDWAIT_RESET)
tv = ACE_OS::gettimeofday ();
# endif /* ACE_LACKS_COND_TIMEDWAIT_RESET */
}
if (result != -2)
ACE_OS::mutex_unlock (&s->lock_);
ACE_PTHREAD_CLEANUP_POP (0);
return result < 0 ? -1 : result;
# else /* No native sem_timedwait(), and emulation disabled */
ACE_UNUSED_ARG (s);
ACE_UNUSED_ARG (tv);
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_POSIX_SEM_TIMEOUT */
# elif defined (ACE_USES_FIFO_SEM)
int rc;
ACE_Time_Value now = ACE_OS::gettimeofday ();
while (tv > now)
{
ACE_Time_Value timeout = tv;
timeout -= now;
ACE_Handle_Set fds_;
fds_.set_bit (s->fd_[0]);
if ((rc = ACE_OS::select (ACE_Handle_Set::MAXSIZE, fds_, 0, 0, timeout)) != 1)
{
if (rc == 0 || errno != EAGAIN)
{
if (rc == 0)
errno = ETIME;
return -1;
}
}
// try to read the signal *but* do *not* block
if (rc == 1 && ACE_OS::sema_trywait (s) == 0)
return 0;
// we were woken for input but someone beat us to it
// so we wait again if there is still time
now = ACE_OS::gettimeofday ();
}
// make sure errno is set right
errno = ETIME;
return -1;
# elif defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_STHREADS)
ACE_UNUSED_ARG (s);
ACE_UNUSED_ARG (tv);
ACE_NOTSUP_RETURN (-1);
# elif defined (ACE_HAS_PTHREADS)
int result = 0;
ACE_Errno_Guard error (errno);
ACE_PTHREAD_CLEANUP_PUSH (&s->lock_);
if (ACE_OS::mutex_lock (&s->lock_) != 0)
result = -1;
else
{
// Keep track of the number of waiters so that we can signal
// them properly in <ACE_OS::sema_post>.
s->waiters_++;
// Wait until the semaphore count is > 0 or until we time out.
while (s->count_ == 0)
if (ACE_OS::cond_timedwait (&s->count_nonzero_,
&s->lock_,
&tv) == -1)
{
error = errno;
result = -2; // -2 means that we need to release the mutex.
break;
}
--s->waiters_;
}
if (result == 0)
{
# if defined (ACE_LACKS_COND_TIMEDWAIT_RESET)
tv = ACE_OS::gettimeofday ();
# endif /* ACE_LACKS_COND_TIMEDWAIT_RESET */
--s->count_;
}
if (result != -1)
ACE_OS::mutex_unlock (&s->lock_);
ACE_PTHREAD_CLEANUP_POP (0);
return result < 0 ? -1 : result;
# elif defined (ACE_HAS_WTHREADS)
# if !defined (ACE_USES_WINCE_SEMA_SIMULATION)
int msec_timeout;
if (tv == ACE_Time_Value::zero)
msec_timeout = 0; // Do a "poll."
else
{
// Note that we must convert between absolute time (which is
// passed as a parameter) and relative time (which is what
// <WaitForSingleObjects> expects).
ACE_Time_Value relative_time (tv - ACE_OS::gettimeofday ());
// Watchout for situations where a context switch has caused the
// current time to be > the timeout.
if (relative_time < ACE_Time_Value::zero)
msec_timeout = 0;
else
msec_timeout = relative_time.msec ();
}
switch (::WaitForSingleObject (*s, msec_timeout))
{
case WAIT_OBJECT_0:
tv = ACE_OS::gettimeofday (); // Update time to when acquired
return 0;
case WAIT_TIMEOUT:
errno = ETIME;
return -1;
default:
// This is a hack, we need to find an appropriate mapping...
ACE_OS::set_errno_to_last_error ();
return -1;
}
/* NOTREACHED */
# else /* ACE_USES_WINCE_SEMA_SIMULATION */
// Note that in this mode, the acquire is done in two steps, and
// we may get signaled but cannot grab the semaphore before
// timeout. In that case, we'll need to restart the process with
// updated timeout value.
// tv is an absolute time, but we need relative to work with the Windows
// API. Also, some users have become accustomed to using a 0 time value
// as a shortcut for "now", which works on non-Windows because 0 is
// always earlier than now. However, the need to convert to relative time
// means we need to watch out for this case.
ACE_Time_Value end_time = tv;
if (tv == ACE_Time_Value::zero)
end_time = ACE_OS::gettimeofday ();
ACE_Time_Value relative_time = end_time - ACE_OS::gettimeofday ();
int result = -1;
// While we are not timeout yet. >= 0 will let this go through once
// and if not able to get the object, it should hit WAIT_TIMEOUT
// right away.
while (relative_time >= ACE_Time_Value::zero)
{
// Wait for our turn to get the object.
switch (::WaitForSingleObject (s->count_nonzero_, relative_time.msec ()))
{
case WAIT_OBJECT_0:
ACE_OS::thread_mutex_lock (&s->lock_);
// Need to double check if the semaphore is still available.
// We can only do a "try lock" styled wait here to avoid
// blocking threads that want to signal the semaphore.
if (::WaitForSingleObject (s->count_nonzero_, 0) == WAIT_OBJECT_0)
{
// As before, only reset the object when the semaphore
// is no longer available.
s->count_--;
if (s->count_ <= 0)
ACE_OS::event_reset (&s->count_nonzero_);
result = 0;
}
ACE_OS::thread_mutex_unlock (&s->lock_);
// Only return when we successfully get the semaphore.
if (result == 0)
{
tv = ACE_OS::gettimeofday (); // Update to time acquired
return 0;
}
break;
// We have timed out.
case WAIT_TIMEOUT:
errno = ETIME;
return -1;
// What?
default:
ACE_OS::set_errno_to_last_error ();
// This is taken from the hack above. ;)
return -1;
};
// Haven't been able to get the semaphore yet, update the
// timeout value to reflect the remaining time we want to wait.
relative_time = end_time - ACE_OS::gettimeofday ();
}
// We have timed out.
errno = ETIME;
return -1;
# endif /* ACE_USES_WINCE_SEMA_SIMULATION */
# elif defined (ACE_VXWORKS)
// Note that we must convert between absolute time (which is
// passed as a parameter) and relative time (which is what
// the system call expects).
ACE_Time_Value relative_time (tv - ACE_OS::gettimeofday ());
int ticks_per_sec = ::sysClkRateGet ();
int ticks = relative_time.sec () * ticks_per_sec +
relative_time.usec () * ticks_per_sec / ACE_ONE_SECOND_IN_USECS;
if (::semTake (s->sema_, ticks) == ERROR)
{
if (errno == S_objLib_OBJ_TIMEOUT)
// Convert the VxWorks errno to one that's common for to ACE
// platforms.
errno = ETIME;
else if (errno == S_objLib_OBJ_UNAVAILABLE)
errno = EBUSY;
return -1;
}
else
{
tv = ACE_OS::gettimeofday (); // Update to time acquired
return 0;
}
# endif /* ACE_HAS_STHREADS */
# else
ACE_UNUSED_ARG (s);
ACE_UNUSED_ARG (tv);
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_POSIX_SEM */
}
ACE_INLINE int
ACE_OS::sema_wait (ACE_sema_t *s, ACE_Time_Value *tv)
{
return tv == 0 ? ACE_OS::sema_wait (s) : ACE_OS::sema_wait (s, *tv);
}
ACE_INLINE int
ACE_OS::semctl (int int_id, int semnum, int cmd, semun value)
{
ACE_OS_TRACE ("ACE_OS::semctl");
#if defined (ACE_HAS_SYSV_IPC)
ACE_OSCALL_RETURN (::semctl (int_id, semnum, cmd, value), int, -1);
#else
ACE_UNUSED_ARG (int_id);
ACE_UNUSED_ARG (semnum);
ACE_UNUSED_ARG (cmd);
ACE_UNUSED_ARG (value);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_SYSV_IPC */
}
ACE_INLINE int
ACE_OS::semget (key_t key, int nsems, int flags)
{
ACE_OS_TRACE ("ACE_OS::semget");
#if defined (ACE_HAS_SYSV_IPC)
ACE_OSCALL_RETURN (::semget (key, nsems, flags), int, -1);
#else
ACE_UNUSED_ARG (key);
ACE_UNUSED_ARG (nsems);
ACE_UNUSED_ARG (flags);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_SYSV_IPC */
}
ACE_INLINE int
ACE_OS::semop (int int_id, struct sembuf *sops, size_t nsops)
{
ACE_OS_TRACE ("ACE_OS::semop");
#if defined (ACE_HAS_SYSV_IPC)
ACE_OSCALL_RETURN (::semop (int_id, sops, nsops), int, -1);
#else
ACE_UNUSED_ARG (int_id);
ACE_UNUSED_ARG (sops);
ACE_UNUSED_ARG (nsops);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_SYSV_IPC */
}
ACE_INLINE int
ACE_OS::sigtimedwait (const sigset_t *sset,
siginfo_t *info,
const ACE_Time_Value *timeout)
{
ACE_OS_TRACE ("ACE_OS::sigtimedwait");
#if defined (ACE_HAS_SIGTIMEDWAIT)
timespec_t ts;
timespec_t *tsp = 0;
if (timeout != 0)
{
ts = *timeout; // Calls ACE_Time_Value::operator timespec_t().
tsp = &ts;
}
ACE_OSCALL_RETURN (::sigtimedwait (sset, info, tsp),
int, -1);
#else
ACE_UNUSED_ARG (sset);
ACE_UNUSED_ARG (info);
ACE_UNUSED_ARG (timeout);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_SIGTIMEDWAIT */
}
ACE_INLINE int
ACE_OS::sigwait (sigset_t *sset, int *sig)
{
ACE_OS_TRACE ("ACE_OS::sigwait");
int local_sig;
if (sig == 0)
sig = &local_sig;
#if defined (ACE_HAS_THREADS)
# if (defined (__FreeBSD__) && (__FreeBSD__ < 3))
ACE_UNUSED_ARG (sset);
ACE_NOTSUP_RETURN (-1);
# elif defined (ACE_HAS_STHREADS)
# if (_POSIX_C_SOURCE - 0 >= 199506L) || defined (_POSIX_PTHREAD_SEMANTICS)
errno = ::sigwait (sset, sig);
return errno == 0 ? *sig : -1;
#else
*sig = ::sigwait (sset);
return *sig;
#endif /* _POSIX_C_SOURCE - 0 >= 199506L || _POSIX_PTHREAD_SEMANTICS */
# elif defined (ACE_HAS_PTHREADS)
# if defined (CYGWIN32)
// Cygwin has sigwait definition, but it is not implemented
ACE_UNUSED_ARG (sset);
ACE_NOTSUP_RETURN (-1);
# elif defined (ACE_TANDEM_T1248_PTHREADS)
errno = ::spt_sigwait (sset, sig);
return errno == 0 ? *sig : -1;
# else /* this is draft 7 or std */
errno = ::sigwait (sset, sig);
return errno == 0 ? *sig : -1;
# endif /* CYGWIN32 */
# elif defined (ACE_HAS_WTHREADS)
ACE_UNUSED_ARG (sset);
ACE_NOTSUP_RETURN (-1);
# elif defined (ACE_VXWORKS)
// Second arg is a struct siginfo *, which we don't need (the
// selected signal number is returned). Third arg is timeout: 0
// means forever.
*sig = ::sigtimedwait (sset, 0, 0);
return *sig;
# endif /* __FreeBSD__ */
#else
ACE_UNUSED_ARG (sset);
ACE_UNUSED_ARG (sig);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::sigwaitinfo (const sigset_t *sset,
siginfo_t *info)
{
ACE_OS_TRACE ("ACE_OS::sigwaitinfo");
// If this platform has sigtimedwait, it should have sigwaitinfo as well.
// If this isn't true somewhere, let me know and I'll fix this.
// -Steve Huston <shuston@riverace.com>.
#if defined (ACE_HAS_SIGTIMEDWAIT)
ACE_OSCALL_RETURN (::sigwaitinfo (sset, info), int, -1);
#else
ACE_UNUSED_ARG (sset);
ACE_UNUSED_ARG (info);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_SIGTIMEDWAIT */
}
ACE_INLINE int
ACE_OS::thr_cancel (ACE_thread_t thr_id)
{
ACE_OS_TRACE ("ACE_OS::thr_cancel");
#if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_PTHREADS) && !defined (ACE_LACKS_PTHREAD_CANCEL)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_cancel (thr_id),
result),
int, -1);
# elif defined (ACE_HAS_VXTHREADS)
ACE_OSCALL_RETURN (::taskDelete (thr_id), int, -1);
# else /* Could be ACE_HAS_PTHREADS && ACE_LACKS_PTHREAD_CANCEL */
ACE_UNUSED_ARG (thr_id);
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_PTHREADS */
#else
ACE_UNUSED_ARG (thr_id);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::thr_cmp (ACE_hthread_t t1, ACE_hthread_t t2)
{
#if defined (ACE_HAS_PTHREADS)
# if defined (pthread_equal)
// If it's a macro we can't say "pthread_equal"...
return pthread_equal (t1, t2);
# else
return pthread_equal (t1, t2);
# endif /* pthread_equal */
#else /* For STHREADS, WTHREADS, and VXWORKS ... */
// Hum, Do we need to treat WTHREAD differently?
// levine 13 oct 98 % Probably, ACE_hthread_t is a HANDLE.
return t1 == t2;
#endif /* ACE_HAS_PTHREADS */
}
ACE_INLINE int
ACE_OS::thr_continue (ACE_hthread_t target_thread)
{
ACE_OS_TRACE ("ACE_OS::thr_continue");
#if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_STHREADS)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::thr_continue (target_thread), result), int, -1);
# elif defined (ACE_HAS_PTHREADS)
# if defined (ACE_HAS_PTHREAD_CONTINUE)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_continue (target_thread),
result),
int, -1);
# elif defined (ACE_HAS_PTHREAD_CONTINUE_NP)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_continue_np (target_thread),
result),
int, -1);
# elif defined (ACE_HAS_PTHREAD_RESUME_NP)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_resume_np (target_thread),
result),
int, -1);
# else
ACE_UNUSED_ARG (target_thread);
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_PTHREAD_CONTINUE */
# elif defined (ACE_HAS_WTHREADS)
DWORD result = ::ResumeThread (target_thread);
if (result == ACE_SYSCALL_FAILED)
ACE_FAIL_RETURN (-1);
else
return 0;
# elif defined (ACE_HAS_VXTHREADS)
ACE_OSCALL_RETURN (::taskResume (target_thread), int, -1);
# endif /* ACE_HAS_STHREADS */
#else
ACE_UNUSED_ARG (target_thread);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::thr_getconcurrency (void)
{
ACE_OS_TRACE ("ACE_OS::thr_getconcurrency");
#if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_STHREADS)
return ::thr_getconcurrency ();
# elif defined (ACE_HAS_PTHREADS) && defined (ACE_HAS_PTHREAD_GETCONCURRENCY)
return pthread_getconcurrency ();
# else
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_STHREADS */
#else
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::thr_getprio (ACE_hthread_t ht_id, int &priority, int &policy)
{
ACE_OS_TRACE ("ACE_OS::thr_getprio");
ACE_UNUSED_ARG (policy);
#if defined (ACE_HAS_THREADS)
# if (defined (ACE_HAS_PTHREADS) && \
(!defined (ACE_LACKS_SETSCHED) || defined (ACE_HAS_PTHREAD_SCHEDPARAM)))
struct sched_param param;
int result;
ACE_OSCALL (ACE_ADAPT_RETVAL (pthread_getschedparam (ht_id, &policy, ¶m),
result), int,
-1, result);
priority = param.sched_priority;
return result;
# elif defined (ACE_HAS_STHREADS)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::thr_getprio (ht_id, &priority), result), int, -1);
# elif defined (ACE_HAS_WTHREADS)
ACE_Errno_Guard error (errno);
# if defined (ACE_HAS_WINCE) && !defined (ACE_LACKS_CE_THREAD_PRIORITY)
priority = ::CeGetThreadPriority (ht_id);
# else
priority = ::GetThreadPriority (ht_id);
# endif /* defined (ACE_HAS_WINCE) && !defined (ACE_LACKS_CE_THREAD_PRIORITY) */
# if defined (ACE_HAS_PHARLAP)
# if defined (ACE_PHARLAP_LABVIEW_RT)
policy = ACE_SCHED_FIFO;
# else
DWORD timeslice = ::EtsGetTimeSlice ();
policy = timeslice == 0 ? ACE_SCHED_OTHER : ACE_SCHED_FIFO;
# endif /* ACE_PHARLAP_LABVIEW_RT */
# elif !defined (ACE_HAS_WINCE)
DWORD priority_class = ::GetPriorityClass (::GetCurrentProcess ());
if (priority_class == 0 && (error = ::GetLastError ()) != NO_ERROR)
ACE_FAIL_RETURN (-1);
policy =
(priority_class ==
REALTIME_PRIORITY_CLASS) ? ACE_SCHED_FIFO : ACE_SCHED_OTHER;
# endif /* ACE_HAS_PHARLAP */
return 0;
# elif defined (ACE_HAS_VXTHREADS)
ACE_OSCALL_RETURN (::taskPriorityGet (ht_id, &priority), int, -1);
# else
ACE_UNUSED_ARG (ht_id);
ACE_UNUSED_ARG (priority);
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_STHREADS */
#else
ACE_UNUSED_ARG (ht_id);
ACE_UNUSED_ARG (priority);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::thr_getprio (ACE_hthread_t ht_id, int &priority)
{
ACE_OS_TRACE ("ACE_OS::thr_getprio");
int policy = 0;
return ACE_OS::thr_getprio (ht_id, priority, policy);
}
#if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
ACE_INLINE int
ACE_OS::thr_getspecific_native (ACE_OS_thread_key_t key, void **data)
{
// ACE_OS_TRACE ("ACE_OS::thr_getspecific_native");
# if defined (ACE_HAS_PTHREADS)
*data = pthread_getspecific (key);
return 0;
# elif defined (ACE_HAS_STHREADS)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::thr_getspecific (key, data), result), int, -1);
# elif defined (ACE_HAS_WTHREADS)
*data = ::TlsGetValue (key);
if (*data == 0 && ::GetLastError () != NO_ERROR)
{
ACE_OS::set_errno_to_last_error ();
return -1;
}
else
return 0;
# else /* ACE_HAS_PTHREADS etc.*/
ACE_UNUSED_ARG (key);
ACE_UNUSED_ARG (data);
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_PTHREADS etc.*/
}
#endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE */
ACE_INLINE int
ACE_OS::thr_getspecific (ACE_thread_key_t key, void **data)
{
// ACE_OS_TRACE ("ACE_OS::thr_getspecific");
#if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_TSS_EMULATION)
if (ACE_TSS_Emulation::is_key (key) == 0)
{
errno = EINVAL;
data = 0;
return -1;
}
else
{
*data = ACE_TSS_Emulation::ts_object (key);
return 0;
}
# elif defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
return ACE_OS::thr_getspecific_native (key, data);
#else
ACE_UNUSED_ARG (key);
ACE_UNUSED_ARG (data);
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_TSS_EMULATION */
#else
ACE_UNUSED_ARG (key);
ACE_UNUSED_ARG (data);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
#if !defined (ACE_HAS_VXTHREADS)
ACE_INLINE int
ACE_OS::thr_join (ACE_hthread_t thr_handle,
ACE_THR_FUNC_RETURN *status)
{
ACE_OS_TRACE ("ACE_OS::thr_join");
#if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_STHREADS)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::thr_join (thr_handle, 0, status), result),
int, -1);
# elif defined (ACE_HAS_PTHREADS)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_join (thr_handle, status), result),
int, -1);
# elif defined (ACE_HAS_WTHREADS)
ACE_THR_FUNC_RETURN local_status = 0;
// Make sure that status is non-NULL.
if (status == 0)
status = &local_status;
if (::WaitForSingleObject (thr_handle, INFINITE) == WAIT_OBJECT_0
&& ::GetExitCodeThread (thr_handle, status) != FALSE)
{
::CloseHandle (thr_handle);
return 0;
}
ACE_FAIL_RETURN (-1);
/* NOTREACHED */
# else
ACE_UNUSED_ARG (thr_handle);
ACE_UNUSED_ARG (status);
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_STHREADS */
#else
ACE_UNUSED_ARG (thr_handle);
ACE_UNUSED_ARG (status);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::thr_join (ACE_thread_t waiter_id,
ACE_thread_t *thr_id,
ACE_THR_FUNC_RETURN *status)
{
ACE_OS_TRACE ("ACE_OS::thr_join");
#if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_STHREADS)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::thr_join (waiter_id, thr_id, status), result),
int, -1);
# elif defined (ACE_HAS_PTHREADS)
ACE_UNUSED_ARG (thr_id);
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_join (waiter_id, status), result),
int, -1);
# elif defined (ACE_HAS_WTHREADS)
ACE_UNUSED_ARG (waiter_id);
ACE_UNUSED_ARG (thr_id);
ACE_UNUSED_ARG (status);
// This could be implemented if the DLL-Main function or the
// task exit base class some log the threads which have exited
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_STHREADS */
#else
ACE_UNUSED_ARG (waiter_id);
ACE_UNUSED_ARG (thr_id);
ACE_UNUSED_ARG (status);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
#endif /* !VXWORKS */
ACE_INLINE int
ACE_OS::thr_kill (ACE_thread_t thr_id, int signum)
{
ACE_OS_TRACE ("ACE_OS::thr_kill");
#if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_PTHREADS)
# if defined (ACE_LACKS_PTHREAD_KILL)
ACE_UNUSED_ARG (signum);
ACE_UNUSED_ARG (thr_id);
ACE_NOTSUP_RETURN (-1);
# else
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_kill (thr_id, signum),
result),
int, -1);
# endif /* ACE_LACKS_PTHREAD_KILL */
# elif defined (ACE_HAS_STHREADS)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::thr_kill (thr_id, signum),
result),
int, -1);
# elif defined (ACE_HAS_VXTHREADS)
//FUZZ: disable check_for_lack_ACE_OS
ACE_OSCALL_RETURN (::kill (thr_id, signum), int, -1);
//FUZZ: enable check_for_lack_ACE_OS
# else
ACE_UNUSED_ARG (thr_id);
ACE_UNUSED_ARG (signum);
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_STHREADS */
#else
ACE_UNUSED_ARG (thr_id);
ACE_UNUSED_ARG (signum);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE size_t
ACE_OS::thr_min_stack (void)
{
ACE_OS_TRACE ("ACE_OS::thr_min_stack");
#if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_STHREADS)
# if defined (ACE_HAS_THR_MINSTACK)
// Tandem did some weirdo mangling of STHREAD names...
return ::thr_minstack ();
# else
return ::thr_min_stack ();
# endif /* !ACE_HAS_THR_MINSTACK */
# elif defined (ACE_HAS_PTHREADS)
# if defined (_SC_THREAD_STACK_MIN)
return (size_t) ACE_OS::sysconf (_SC_THREAD_STACK_MIN);
# elif defined (PTHREAD_STACK_MIN)
return PTHREAD_STACK_MIN;
# else
ACE_NOTSUP_RETURN (0);
# endif /* _SC_THREAD_STACK_MIN */
# elif defined (ACE_HAS_WTHREADS)
ACE_NOTSUP_RETURN (0);
# elif defined (ACE_HAS_VXTHREADS)
TASK_DESC taskDesc;
STATUS status;
ACE_thread_t tid = ACE_OS::thr_self ();
ACE_OSCALL (ACE_ADAPT_RETVAL (::taskInfoGet (tid, &taskDesc),
status),
STATUS, -1, status);
return status == OK ? taskDesc.td_stackSize : 0;
# else /* Should not happen... */
ACE_NOTSUP_RETURN (0);
# endif /* ACE_HAS_STHREADS */
#else
ACE_NOTSUP_RETURN (0);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE ACE_thread_t
ACE_OS::thr_self (void)
{
// ACE_OS_TRACE ("ACE_OS::thr_self");
#if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_PTHREADS)
// Note, don't use "::" here since the following call is often a macro.
return pthread_self ();
# elif defined (ACE_HAS_STHREADS)
ACE_OSCALL_RETURN (::thr_self (), int, -1);
# elif defined (ACE_HAS_WTHREADS)
return ::GetCurrentThreadId ();
# elif defined (ACE_HAS_VXTHREADS)
return ::taskIdSelf ();
# endif /* ACE_HAS_STHREADS */
#else
return 1; // Might as well make it the first thread ;-)
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE const char*
ACE_OS::thr_name (void)
{
#if defined (ACE_HAS_THREADS)
#if defined (ACE_HAS_VXTHREADS)
return ::taskName (ACE_OS::thr_self ());
#else
ACE_NOTSUP_RETURN (0);
#endif
#else
ACE_NOTSUP_RETURN (0);
#endif
}
ACE_INLINE void
ACE_OS::thr_self (ACE_hthread_t &self)
{
ACE_OS_TRACE ("ACE_OS::thr_self");
#if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_PTHREADS)
// Note, don't use "::" here since the following call is often a macro.
self = pthread_self ();
# elif defined (ACE_HAS_THREAD_SELF)
self = ::thread_self ();
# elif defined (ACE_HAS_STHREADS)
self = ::thr_self ();
# elif defined (ACE_HAS_WTHREADS)
self = ::GetCurrentThread ();
# elif defined (ACE_HAS_VXTHREADS)
self = ::taskIdSelf ();
# endif /* ACE_HAS_STHREADS */
#else
self = 1; // Might as well make it the main thread ;-)
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::thr_setcancelstate (int new_state, int *old_state)
{
ACE_OS_TRACE ("ACE_OS::thr_setcancelstate");
#if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_PTHREADS) && !defined (ACE_LACKS_PTHREAD_CANCEL)
int result;
int local_new, local_old;
switch (new_state)
{
case THR_CANCEL_ENABLE:
local_new = PTHREAD_CANCEL_ENABLE;
break;
case THR_CANCEL_DISABLE:
local_new = PTHREAD_CANCEL_DISABLE;
break;
default:
errno = EINVAL;
return -1;
}
ACE_OSCALL (ACE_ADAPT_RETVAL (pthread_setcancelstate (local_new,
&local_old),
result),
int, -1, result);
if (result == -1)
return -1;
switch (local_old)
{
case PTHREAD_CANCEL_ENABLE:
*old_state = THR_CANCEL_ENABLE;
break;
case PTHREAD_CANCEL_DISABLE:
*old_state = THR_CANCEL_DISABLE;
break;
}
return result;
# elif defined (ACE_HAS_STHREADS)
ACE_UNUSED_ARG (new_state);
ACE_UNUSED_ARG (old_state);
ACE_NOTSUP_RETURN (-1);
# elif defined (ACE_HAS_WTHREADS)
ACE_UNUSED_ARG (new_state);
ACE_UNUSED_ARG (old_state);
ACE_NOTSUP_RETURN (-1);
# else /* Could be ACE_HAS_PTHREADS && ACE_LACKS_PTHREAD_CANCEL */
ACE_UNUSED_ARG (new_state);
ACE_UNUSED_ARG (old_state);
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_PTHREADS */
#else
ACE_UNUSED_ARG (new_state);
ACE_UNUSED_ARG (old_state);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::thr_setcanceltype (int new_type, int *old_type)
{
ACE_OS_TRACE ("ACE_OS::thr_setcanceltype");
#if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_PTHREADS) && !defined (ACE_LACKS_PTHREAD_CANCEL)
int result;
int local_new, local_old;
switch (new_type)
{
case THR_CANCEL_DEFERRED:
local_new = PTHREAD_CANCEL_DEFERRED;
break;
case THR_CANCEL_ASYNCHRONOUS:
local_new = PTHREAD_CANCEL_ASYNCHRONOUS;
break;
default:
errno = EINVAL;
return -1;
}
ACE_OSCALL (ACE_ADAPT_RETVAL (pthread_setcanceltype (local_new,
&local_old),
result),
int, -1, result);
if (result == -1)
return -1;
switch (local_old)
{
case PTHREAD_CANCEL_DEFERRED:
*old_type = THR_CANCEL_DEFERRED;
break;
case PTHREAD_CANCEL_ASYNCHRONOUS:
*old_type = THR_CANCEL_ASYNCHRONOUS;
break;
}
return result;
# else /* Could be ACE_HAS_PTHREADS && ACE_LACKS_PTHREAD_CANCEL */
ACE_UNUSED_ARG (new_type);
ACE_UNUSED_ARG (old_type);
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_PTHREADS */
#else
ACE_UNUSED_ARG (new_type);
ACE_UNUSED_ARG (old_type);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::thr_setconcurrency (int hint)
{
ACE_OS_TRACE ("ACE_OS::thr_setconcurrency");
#if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_STHREADS)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::thr_setconcurrency (hint),
result),
int, -1);
# elif defined (ACE_HAS_PTHREADS) && defined (ACE_HAS_PTHREAD_SETCONCURRENCY)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_setconcurrency (hint),
result),
int, -1);
# else
ACE_UNUSED_ARG (hint);
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_STHREADS */
#else
ACE_UNUSED_ARG (hint);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::thr_setprio (ACE_hthread_t ht_id, int priority, int policy)
{
ACE_OS_TRACE ("ACE_OS::thr_setprio");
ACE_UNUSED_ARG (policy);
#if defined (ACE_HAS_THREADS)
# if (defined (ACE_HAS_PTHREADS) && \
(!defined (ACE_LACKS_SETSCHED) || defined (ACE_HAS_PTHREAD_SCHEDPARAM)))
int result;
struct sched_param param;
ACE_OS::memset ((void *) ¶m, 0, sizeof param);
// If <policy> is -1, we don't want to use it for
// pthread_setschedparam(). Instead, obtain policy from
// pthread_getschedparam().
if (policy == -1)
{
ACE_OSCALL (ACE_ADAPT_RETVAL (pthread_getschedparam (ht_id, &policy, ¶m),
result),
int, -1, result);
if (result == -1)
return result;
}
param.sched_priority = priority;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_setschedparam (ht_id,
policy,
¶m),
result),
int, -1);
# elif defined (ACE_HAS_STHREADS)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::thr_setprio (ht_id, priority),
result),
int, -1);
# elif defined (ACE_HAS_WTHREADS)
# if defined (ACE_HAS_WINCE) && !defined (ACE_LACKS_CE_THREAD_PRIORITY)
ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::CeSetThreadPriority (ht_id, priority),
ace_result_),
int, -1);
# else
ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::SetThreadPriority (ht_id, priority),
ace_result_),
int, -1);
# endif /* defined (ACE_HAS_WINCE) && !defined (ACE_LACKS_CE_THREAD_PRIORITY) */
# elif defined (ACE_HAS_VXTHREADS)
ACE_OSCALL_RETURN (::taskPrioritySet (ht_id, priority), int, -1);
# else
// For example, platforms that support Pthreads but LACK_SETSCHED.
ACE_UNUSED_ARG (ht_id);
ACE_UNUSED_ARG (priority);
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_STHREADS */
#else
ACE_UNUSED_ARG (ht_id);
ACE_UNUSED_ARG (priority);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::thr_sigsetmask (int how,
const sigset_t *nsm,
sigset_t *osm)
{
ACE_OS_TRACE ("ACE_OS::thr_sigsetmask");
#if defined (ACE_HAS_THREADS)
# if defined (ACE_LACKS_PTHREAD_THR_SIGSETMASK)
// DCE threads and Solaris 2.4 have no such function.
ACE_UNUSED_ARG (osm);
ACE_UNUSED_ARG (nsm);
ACE_UNUSED_ARG (how);
ACE_NOTSUP_RETURN (-1);
# elif defined (ACE_HAS_SIGTHREADMASK)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::sigthreadmask (how, nsm, osm),
result), int, -1);
# elif defined (ACE_HAS_STHREADS)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::thr_sigsetmask (how, nsm, osm),
result),
int, -1);
# elif defined (ACE_HAS_PTHREADS)
# if !defined (ACE_LACKS_PTHREAD_SIGMASK)
int result;
//FUZZ: disable check_for_lack_ACE_OS
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::pthread_sigmask (how, nsm, osm),
result), int, -1);
//FUZZ: enable check_for_lack_ACE_OS
# endif /* !ACE_LACKS_PTHREAD_SIGMASK */
# elif defined (ACE_HAS_WTHREADS)
ACE_UNUSED_ARG (osm);
ACE_UNUSED_ARG (nsm);
ACE_UNUSED_ARG (how);
ACE_NOTSUP_RETURN (-1);
# elif defined (ACE_VXWORKS)
int old_mask = 0;
switch (how)
{
case SIG_BLOCK:
case SIG_UNBLOCK:
{
// get the old mask
old_mask = ::sigsetmask (*nsm);
// create a new mask: the following assumes that sigset_t is 4 bytes,
// which it is on VxWorks 5.2, so bit operations are done simply . . .
::sigsetmask (how == SIG_BLOCK ? (old_mask |= *nsm) : (old_mask &= ~*nsm));
if (osm)
*osm = old_mask;
break;
}
case SIG_SETMASK:
old_mask = ::sigsetmask (*nsm);
if (osm)
*osm = old_mask;
break;
default:
return -1;
}
return 0;
# else /* Should not happen. */
ACE_UNUSED_ARG (how);
ACE_UNUSED_ARG (nsm);
ACE_UNUSED_ARG (osm);
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_LACKS_PTHREAD_THR_SIGSETMASK */
#else
ACE_UNUSED_ARG (how);
ACE_UNUSED_ARG (nsm);
ACE_UNUSED_ARG (osm);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::thr_suspend (ACE_hthread_t target_thread)
{
ACE_OS_TRACE ("ACE_OS::thr_suspend");
#if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_STHREADS)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::thr_suspend (target_thread), result), int, -1);
# elif defined (ACE_HAS_PTHREADS)
# if defined (ACE_HAS_PTHREAD_SUSPEND)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_suspend (target_thread),
result),
int, -1);
# elif defined (ACE_HAS_PTHREAD_SUSPEND_NP)
int result;
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_suspend_np (target_thread),
result),
int, -1);
# else
ACE_UNUSED_ARG (target_thread);
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_PTHREAD_SUSPEND */
# elif defined (ACE_HAS_WTHREADS)
if (::SuspendThread (target_thread) != ACE_SYSCALL_FAILED)
return 0;
else
ACE_FAIL_RETURN (-1);
/* NOTREACHED */
# elif defined (ACE_HAS_VXTHREADS)
ACE_OSCALL_RETURN (::taskSuspend (target_thread), int, -1);
# endif /* ACE_HAS_STHREADS */
#else
ACE_UNUSED_ARG (target_thread);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE void
ACE_OS::thr_testcancel (void)
{
ACE_OS_TRACE ("ACE_OS::thr_testcancel");
#if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_PTHREADS) && !defined (ACE_LACKS_PTHREAD_CANCEL)
pthread_testcancel ();
# elif defined (ACE_HAS_STHREADS)
# elif defined (ACE_HAS_WTHREADS)
# elif defined (ACE_HAS_VXTHREADS)
# else
// no-op: can't use ACE_NOTSUP_RETURN because there is no return value
# endif /* ACE_HAS_PTHREADS */
#else
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE void
ACE_OS::thr_yield (void)
{
ACE_OS_TRACE ("ACE_OS::thr_yield");
#if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_PTHREADS)
::sched_yield ();
# elif defined (ACE_HAS_STHREADS)
::thr_yield ();
# elif defined (ACE_HAS_WTHREADS)
::Sleep (0);
# elif defined (ACE_HAS_VXTHREADS)
// An argument of 0 to ::taskDelay doesn't appear to yield the
// current thread.
// Now, it does seem to work. The context_switch_time test
// works fine with task_delay set to 0.
::taskDelay (0);
# endif /* ACE_HAS_STHREADS */
#else
;
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::thread_mutex_destroy (ACE_thread_mutex_t *m)
{
ACE_OS_TRACE ("ACE_OS::thread_mutex_destroy");
#if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_WTHREADS)
::DeleteCriticalSection (m);
return 0;
# else
return ACE_OS::mutex_destroy (m);
# endif /* ACE_HAS_WTHREADS */
#else
ACE_UNUSED_ARG (m);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::thread_mutex_init (ACE_thread_mutex_t *m,
int lock_type,
const char *name,
ACE_mutexattr_t *arg)
{
// ACE_OS_TRACE ("ACE_OS::thread_mutex_init");
#if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_WTHREADS)
ACE_UNUSED_ARG (lock_type);
ACE_UNUSED_ARG (name);
ACE_UNUSED_ARG (arg);
ACE_SEH_TRY
{
::InitializeCriticalSection (m);
}
ACE_SEH_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
errno = ENOMEM;
return -1;
}
return 0;
# elif defined (ACE_HAS_STHREADS) || defined (ACE_HAS_PTHREADS)
// Force the use of USYNC_THREAD!
return ACE_OS::mutex_init (m, USYNC_THREAD, name, arg, 0, lock_type);
# elif defined (ACE_HAS_VXTHREADS)
return mutex_init (m, lock_type, name, arg);
# endif /* ACE_HAS_STHREADS || ACE_HAS_PTHREADS */
#else
ACE_UNUSED_ARG (m);
ACE_UNUSED_ARG (lock_type);
ACE_UNUSED_ARG (name);
ACE_UNUSED_ARG (arg);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
#if defined (ACE_HAS_WCHAR)
ACE_INLINE int
ACE_OS::thread_mutex_init (ACE_thread_mutex_t *m,
int lock_type,
const wchar_t *name,
ACE_mutexattr_t *arg)
{
// ACE_OS_TRACE ("ACE_OS::thread_mutex_init");
#if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_WTHREADS)
ACE_UNUSED_ARG (lock_type);
ACE_UNUSED_ARG (name);
ACE_UNUSED_ARG (arg);
ACE_SEH_TRY
{
::InitializeCriticalSection (m);
}
ACE_SEH_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
errno = ENOMEM;
return -1;
}
return 0;
# elif defined (ACE_HAS_STHREADS) || defined (ACE_HAS_PTHREADS)
// Force the use of USYNC_THREAD!
return ACE_OS::mutex_init (m, USYNC_THREAD, name, arg, 0, lock_type);
# elif defined (ACE_HAS_VXTHREADS)
return mutex_init (m, lock_type, name, arg);
# endif /* ACE_HAS_STHREADS || ACE_HAS_PTHREADS */
#else
ACE_UNUSED_ARG (m);
ACE_UNUSED_ARG (lock_type);
ACE_UNUSED_ARG (name);
ACE_UNUSED_ARG (arg);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
#endif /* ACE_HAS_WCHAR */
ACE_INLINE int
ACE_OS::thread_mutex_lock (ACE_thread_mutex_t *m)
{
// ACE_OS_TRACE ("ACE_OS::thread_mutex_lock");
#if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_WTHREADS)
::EnterCriticalSection (m);
return 0;
# else
return ACE_OS::mutex_lock (m);
# endif /* ACE_HAS_WTHREADS */
#else
ACE_UNUSED_ARG (m);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::thread_mutex_lock (ACE_thread_mutex_t *m,
const ACE_Time_Value &timeout)
{
// ACE_OS_TRACE ("ACE_OS::thread_mutex_lock");
// For all platforms, except MS Windows, this method is equivalent
// to calling ACE_OS::mutex_lock() since ACE_thread_mutex_t and
// ACE_mutex_t are the same type. However, those typedefs evaluate
// to different types on MS Windows. The "thread mutex"
// implementation in ACE for MS Windows cannot readily support
// timeouts due to a lack of timeout features for this type of MS
// Windows synchronization mechanism.
#if defined (ACE_HAS_THREADS) && !defined (ACE_HAS_WTHREADS)
return ACE_OS::mutex_lock (m, timeout);
#else
ACE_UNUSED_ARG (m);
ACE_UNUSED_ARG (timeout);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::thread_mutex_lock (ACE_thread_mutex_t *m,
const ACE_Time_Value *timeout)
{
return timeout == 0
? ACE_OS::thread_mutex_lock (m)
: ACE_OS::thread_mutex_lock (m, *timeout);
}
ACE_INLINE int
ACE_OS::thread_mutex_trylock (ACE_thread_mutex_t *m)
{
ACE_OS_TRACE ("ACE_OS::thread_mutex_trylock");
#if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_WTHREADS)
# if defined (ACE_HAS_WIN32_TRYLOCK)
BOOL result = ::TryEnterCriticalSection (m);
if (result == TRUE)
return 0;
else
{
errno = EBUSY;
return -1;
}
# else
ACE_UNUSED_ARG (m);
ACE_NOTSUP_RETURN (-1);
# endif /* ACE_HAS_WIN32_TRYLOCK */
# elif defined (ACE_HAS_STHREADS) || defined (ACE_HAS_PTHREADS) || defined (ACE_VXWORKS)
return ACE_OS::mutex_trylock (m);
#endif /* Threads variety case */
#else
ACE_UNUSED_ARG (m);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
ACE_INLINE int
ACE_OS::thread_mutex_unlock (ACE_thread_mutex_t *m)
{
ACE_OS_TRACE ("ACE_OS::thread_mutex_unlock");
#if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_WTHREADS)
::LeaveCriticalSection (m);
return 0;
# else
return ACE_OS::mutex_unlock (m);
# endif /* ACE_HAS_WTHREADS */
#else
ACE_UNUSED_ARG (m);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
/*****************************************************************************/
# if defined (ACE_IS_SPLITTING)
# define ACE_SPECIAL_INLINE
# else
# define ACE_SPECIAL_INLINE ACE_INLINE
//# define ACE_SPECIAL_INLINE inline
# endif
#if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
ACE_INLINE
int
ACE_OS_Thread_Mutex_Guard::acquire (void)
{
return owner_ = ACE_OS::thread_mutex_lock (&lock_);
}
ACE_INLINE
int
ACE_OS_Thread_Mutex_Guard::release (void)
{
if (owner_ == -1)
return 0;
else
{
owner_ = -1;
return ACE_OS::thread_mutex_unlock (&lock_);
}
}
ACE_INLINE
ACE_OS_Thread_Mutex_Guard::ACE_OS_Thread_Mutex_Guard (ACE_thread_mutex_t &m)
: lock_ (m), owner_ (-1)
{
if (!ACE_OS_Object_Manager::starting_up ())
acquire ();
}
ACE_INLINE
ACE_OS_Thread_Mutex_Guard::~ACE_OS_Thread_Mutex_Guard ()
{
release ();
}
/*****************************************************************************/
ACE_INLINE
int
ACE_OS_Recursive_Thread_Mutex_Guard::acquire (void)
{
return owner_ = ACE_OS::recursive_mutex_lock (&lock_);
}
ACE_INLINE
int
ACE_OS_Recursive_Thread_Mutex_Guard::release (void)
{
if (owner_ == -1)
return 0;
else
{
owner_ = -1;
return ACE_OS::recursive_mutex_unlock (&lock_);
}
}
ACE_INLINE
ACE_OS_Recursive_Thread_Mutex_Guard::ACE_OS_Recursive_Thread_Mutex_Guard (
ACE_recursive_thread_mutex_t &m)
: lock_ (m),
owner_ (-1)
{
if (!ACE_OS_Object_Manager::starting_up ())
acquire ();
}
ACE_INLINE
ACE_OS_Recursive_Thread_Mutex_Guard::~ACE_OS_Recursive_Thread_Mutex_Guard ()
{
release ();
}
#endif /* ACE_MT_SAFE && ACE_MT_SAFE != 0 */
/*****************************************************************************/
ACE_INLINE
ACE_Thread_ID::ACE_Thread_ID (ACE_thread_t thread_id,
ACE_hthread_t thread_handle)
: thread_id_ (thread_id),
thread_handle_ (thread_handle)
{
}
ACE_INLINE
ACE_Thread_ID::ACE_Thread_ID (const ACE_Thread_ID &id)
: thread_id_ (id.thread_id_),
thread_handle_ (id.thread_handle_)
{
}
ACE_INLINE
ACE_Thread_ID&
ACE_Thread_ID::operator= (const ACE_Thread_ID &id)
{
if (this != &id)
{
this->thread_id_ = id.thread_id_;
this->thread_handle_ = id.thread_handle_;
}
return *this;
}
ACE_INLINE
ACE_Thread_ID::ACE_Thread_ID (void)
: thread_id_ (ACE_OS::thr_self ())
{
ACE_OS::thr_self (thread_handle_);
}
ACE_INLINE
ACE_thread_t
ACE_Thread_ID::id (void) const
{
return this->thread_id_;
}
ACE_INLINE void
ACE_Thread_ID::id (ACE_thread_t thread_id)
{
this->thread_id_ = thread_id;
}
ACE_INLINE ACE_hthread_t
ACE_Thread_ID::handle (void) const
{
return this->thread_handle_;
}
ACE_INLINE void
ACE_Thread_ID::handle (ACE_hthread_t thread_handle)
{
this->thread_handle_ = thread_handle;
}
ACE_INLINE bool
ACE_Thread_ID::operator== (const ACE_Thread_ID &rhs) const
{
return
ACE_OS::thr_cmp (this->thread_handle_, rhs.thread_handle_)
&& ACE_OS::thr_equal (this->thread_id_, rhs.thread_id_);
}
ACE_INLINE bool
ACE_Thread_ID::operator!= (const ACE_Thread_ID &rhs) const
{
return !(*this == rhs);
}
ACE_END_VERSIONED_NAMESPACE_DECL
|