/usr/include/ace/OS_NS_Thread.h 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 | // -*- C++ -*-
//=============================================================================
/**
* @file OS_NS_Thread.h
*
* $Id: OS_NS_Thread.h 92682 2010-11-23 23:41:19Z shuston $
*
* @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
* @author Jesper S. M|ller<stophph@diku.dk>
* @author and a cast of thousands...
*
* Originally in OS.h.
*/
//=============================================================================
#ifndef ACE_OS_NS_THREAD_H
# define ACE_OS_NS_THREAD_H
# include /**/ "ace/pre.h"
# include "ace/config-all.h"
# if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
# endif /* ACE_LACKS_PRAGMA_ONCE */
# include "ace/Global_Macros.h"
# include "ace/Basic_Types.h"
# include "ace/Default_Constants.h"
# include "ace/os_include/os_pthread.h"
# include "ace/os_include/os_sched.h"
# include "ace/Base_Thread_Adapter.h"
# include "ace/os_include/sys/os_sem.h"
# include "ace/os_include/os_semaphore.h"
# include "ace/OS_Memory.h"
# include "ace/OS_NS_signal.h"
# include "ace/ACE_export.h"
# include "ace/Object_Manager_Base.h"
# if defined (ACE_EXPORT_MACRO)
# undef ACE_EXPORT_MACRO
# endif
# define ACE_EXPORT_MACRO ACE_Export
# if defined (ACE_HAS_PRIOCNTL)
// Need to #include thread.h before #defining THR_BOUND, etc.,
// when building without threads on SunOS 5.x.
# if defined (sun)
# include /**/ <thread.h>
# endif /* sun */
// Need to #include these before #defining USYNC_PROCESS on SunOS 5.x.
# include /**/ <sys/rtpriocntl.h>
# include /**/ <sys/tspriocntl.h>
# endif /* ACE_HAS_PRIOCNTL */
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
# if defined (ACE_WIN32)
typedef DWORD ACE_thread_t;
typedef HANDLE ACE_hthread_t;
// Native TSS key type
typedef DWORD ACE_OS_thread_key_t;
// Application TSS key type (use this type except in TSS Emulation)
# if defined (ACE_HAS_TSS_EMULATION)
typedef u_int ACE_thread_key_t;
# else /* ! ACE_HAS_TSS_EMULATION */
typedef ACE_OS_thread_key_t ACE_thread_key_t;
# endif /* ! ACE_HAS_TSS_EMULATION */
# endif /* ACE_WIN32 */
ACE_END_VERSIONED_NAMESPACE_DECL
# if !defined (ACE_HAS_POSIX_SEM) && defined (ACE_USES_FIFO_SEM)
extern "C" {
typedef struct
{
char* name_;
ACE_HANDLE fd_[2];
} ACE_sema_t;
}
#endif /* !ACE_HAS_POSIX_SEM && ACE_USES_FIFO_SEM */
# if defined (ACE_HAS_THREADS)
# if defined (ACE_HAS_STHREADS)
# include /**/ <synch.h>
# include /**/ <thread.h>
# define ACE_SCOPE_PROCESS P_PID
# define ACE_SCOPE_LWP P_LWPID
# define ACE_SCOPE_THREAD (ACE_SCOPE_LWP + 1)
# else
# define ACE_SCOPE_PROCESS 0
# define ACE_SCOPE_LWP 1
# define ACE_SCOPE_THREAD 2
# endif /* ACE_HAS_STHREADS */
# if !defined (ACE_HAS_PTHREADS)
# define ACE_SCHED_OTHER 0
# define ACE_SCHED_FIFO 1
# define ACE_SCHED_RR 2
# endif /* ! ACE_HAS_PTHREADS */
# if defined (ACE_HAS_PTHREADS)
// moved to pthread.h
# elif defined (ACE_HAS_STHREADS)
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
// Solaris threads, without PTHREADS.
// Typedefs to help compatibility with Windows NT and Pthreads.
typedef thread_t ACE_thread_t;
// Native TSS key type (not for general use)
typedef thread_key_t ACE_OS_thread_key_t;
// Application TSS key type (use this type except in TSS Emulation)
# if defined (ACE_HAS_TSS_EMULATION)
typedef u_int ACE_thread_key_t;
# else /* ! ACE_HAS_TSS_EMULATION */
typedef ACE_OS_thread_key_t ACE_thread_key_t;
# endif /* ! ACE_HAS_TSS_EMULATION */
typedef mutex_t ACE_mutex_t;
# if !defined (ACE_LACKS_RWLOCK_T)
typedef rwlock_t ACE_rwlock_t;
# endif /* !ACE_LACKS_RWLOCK_T */
# if !defined (ACE_HAS_POSIX_SEM) && !defined (ACE_USES_FIFO_SEM)
typedef sema_t ACE_sema_t;
# endif /* !ACE_HAS_POSIX_SEM */
typedef cond_t ACE_cond_t;
struct ACE_Export ACE_condattr_t
{
int type;
};
struct ACE_Export ACE_mutexattr_t
{
int type;
};
typedef ACE_thread_t ACE_hthread_t;
typedef ACE_mutex_t ACE_thread_mutex_t;
ACE_END_VERSIONED_NAMESPACE_DECL
# define THR_CANCEL_DISABLE 0
# define THR_CANCEL_ENABLE 0
# define THR_CANCEL_DEFERRED 0
# define THR_CANCEL_ASYNCHRONOUS 0
# define THR_JOINABLE 0
# define THR_SCHED_FIFO 0
# define THR_SCHED_RR 0
# define THR_SCHED_DEFAULT 0
# define THR_INHERIT_SCHED 0
# define THR_SCOPE_PROCESS 0
# elif defined (ACE_VXWORKS)
# include /**/ <sysLib.h> // for sysClkRateGet()
# if !defined (__RTP__)
# include /**/ <taskLib.h>
# include /**/ <taskHookLib.h>
# endif
// make sure these are included for VXWORKS.
// @todo move these to a common place, perhaps the top of the file.
# include "ace/os_include/os_fcntl.h"
# include "ace/os_include/os_netdb.h"
# include "ace/os_include/os_semaphore.h"
# include "ace/os_include/os_signal.h"
# include "ace/os_include/os_stdio.h"
# include "ace/os_include/os_stdlib.h"
# include "ace/os_include/os_stropts.h"
# include "ace/os_include/os_unistd.h"
# include "ace/os_include/arpa/os_inet.h"
# include "ace/os_include/sys/os_select.h"
# include "ace/os_include/sys/os_socket.h"
// task options: the other options are either obsolete, internal, or for
// Fortran or Ada support
# define VX_UNBREAKABLE 0x0002 /* breakpoints ignored */
# if !defined (VX_FP_TASK)
# define VX_FP_TASK 0x0008 /* floating point coprocessor */
# endif
# define VX_PRIVATE_ENV 0x0080 /* private environment support */
# define VX_NO_STACK_FILL 0x0100 /* do not stack fill for
checkstack () */
# define THR_CANCEL_DISABLE 0
# define THR_CANCEL_ENABLE 0
# define THR_CANCEL_DEFERRED 0
# define THR_CANCEL_ASYNCHRONOUS 0
# define THR_BOUND 0
# define THR_NEW_LWP 0
# define THR_DETACHED 0
# define THR_SUSPENDED 0
# define THR_DAEMON 0
# define THR_JOINABLE 0
# define THR_SCHED_FIFO 0
# define THR_SCHED_RR 0
# define THR_SCHED_DEFAULT 0
# define THR_INHERIT_SCHED 0
# define THR_EXPLICIT_SCHED 0
# define THR_SCHED_IO 0
# define THR_SCOPE_SYSTEM 0
# define THR_SCOPE_PROCESS 0
# define USYNC_THREAD 0
# define USYNC_PROCESS 1 /* It's all global on VxWorks
(without MMU option). */
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
typedef SEM_ID ACE_mutex_t;
// Implement ACE_thread_mutex_t with ACE_mutex_t because there's just
// one process . . .
typedef ACE_mutex_t ACE_thread_mutex_t;
# if !defined (ACE_HAS_POSIX_SEM)
// Use VxWorks semaphores, wrapped ...
typedef struct
{
/// Semaphore handle. This is allocated by VxWorks.
SEM_ID sema_;
/// Name of the semaphore: always NULL with VxWorks.
char *name_;
} ACE_sema_t;
# endif /* !ACE_HAS_POSIX_SEM */
typedef int ACE_thread_t;
typedef int ACE_hthread_t;
// Key type: the ACE TSS emulation requires the key type be unsigned,
// for efficiency. (Current POSIX and Solaris TSS implementations also
// use u_int, so the ACE TSS emulation is compatible with them.)
// Native TSS key type
typedef u_int ACE_OS_thread_key_t;
// Application TSS key type (use this type except in TSS Emulation)
# if defined (ACE_HAS_TSS_EMULATION)
typedef u_int ACE_thread_key_t;
# else /* ! ACE_HAS_TSS_EMULATION */
typedef ACE_OS_thread_key_t ACE_thread_key_t;
# endif /* ! ACE_HAS_TSS_EMULATION */
ACE_END_VERSIONED_NAMESPACE_DECL
# elif defined (ACE_HAS_WTHREADS)
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
typedef CRITICAL_SECTION ACE_thread_mutex_t;
typedef struct
{
/// Either USYNC_THREAD or USYNC_PROCESS
int type_;
union
{
HANDLE proc_mutex_;
CRITICAL_SECTION thr_mutex_;
};
} ACE_mutex_t;
// Wrapper for NT Events.
typedef HANDLE ACE_event_t;
# if defined (ACE_WIN32)
//@@ ACE_USES_WINCE_SEMA_SIMULATION is used to debug
// semaphore simulation on WinNT. It should be
// changed to ACE_USES_HAS_WINCE at some later point.
# if !defined (ACE_USES_WINCE_SEMA_SIMULATION)
typedef HANDLE ACE_sema_t;
# else
/**
* @class ACE_sema_t
*
* @brief Semaphore simulation for Windows CE.
*/
class ACE_Export ACE_sema_t
{
public:
/// Serializes access to @c count_.
ACE_thread_mutex_t lock_;
/// This event is signaled whenever the count becomes non-zero.
ACE_event_t count_nonzero_;
/// Current count of the semaphore.
u_int count_;
};
# endif /* ACE_USES_WINCE_SEMA_SIMULATION */
# endif /* defined (ACE_WIN32) */
ACE_END_VERSIONED_NAMESPACE_DECL
// These need to be different values, neither of which can be 0...
# define USYNC_THREAD 1
# define USYNC_PROCESS 2
# define THR_CANCEL_DISABLE 0
# define THR_CANCEL_ENABLE 0
# define THR_CANCEL_DEFERRED 0
# define THR_CANCEL_ASYNCHRONOUS 0
# define THR_DETACHED 0x02000000 /* ignore in most places */
# define THR_BOUND 0 /* ignore in most places */
# define THR_NEW_LWP 0 /* ignore in most places */
# define THR_DAEMON 0 /* ignore in most places */
# define THR_JOINABLE 0 /* ignore in most places */
# define THR_SUSPENDED CREATE_SUSPENDED
# if !defined (STACK_SIZE_PARAM_IS_A_RESERVATION)
# define STACK_SIZE_PARAM_IS_A_RESERVATION 0x00010000
# endif /* STACK_SIZE_PARAM_IS_A_RESERVATION */
# define THR_USE_AFX 0x01000000
# define THR_SCHED_FIFO 0
# define THR_SCHED_RR 0
# define THR_SCHED_DEFAULT 0
# define THR_INHERIT_SCHED 0
# define THR_EXPLICIT_SCHED 0
# define THR_SCOPE_PROCESS 0
# define THR_SCOPE_SYSTEM 0
# endif /* ACE_HAS_PTHREADS / STHREADS / VXWORKS / WTHREADS **********/
# if defined (ACE_HAS_WTHREADS_CONDITION_VARIABLE)
typedef CONDITION_VARIABLE ACE_cond_t;
# elif defined (ACE_LACKS_COND_T)
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
/**
* @class ACE_cond_t
*
* @brief This structure is used to implement condition variables on
* platforms that lack it natively, such as VxWorks, and Win32.
*
* At the current time, this stuff only works for threads
* within the same process.
*/
class ACE_Export ACE_cond_t
{
public:
/// Returns the number of waiters.
long waiters (void) const;
//protected:
/// Number of waiting threads.
long waiters_;
/// Serialize access to the waiters count.
ACE_thread_mutex_t waiters_lock_;
/// Queue up threads waiting for the condition to become signaled.
ACE_sema_t sema_;
# if defined (ACE_VXWORKS)
/**
* A semaphore used by the broadcast/signal thread to wait for all
* the waiting thread(s) to wake up and be released from the
* semaphore.
*/
ACE_sema_t waiters_done_;
# elif defined (ACE_WIN32)
/**
* An auto reset event used by the broadcast/signal thread to wait
* for the waiting thread(s) to wake up and get a chance at the
* semaphore.
*/
HANDLE waiters_done_;
# else
# error "Please implement this feature or check your config.h file!"
# endif /* ACE_VXWORKS */
/// Keeps track of whether we were broadcasting or just signaling.
size_t was_broadcast_;
};
ACE_END_VERSIONED_NAMESPACE_DECL
# endif /* ACE_LACKS_COND_T */
# if defined (ACE_HAS_WTHREADS_CONDITION_VARIABLE) || defined (ACE_LACKS_COND_T)
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
struct ACE_Export ACE_condattr_t
{
int type;
};
struct ACE_Export ACE_mutexattr_t
{
int type;
};
ACE_END_VERSIONED_NAMESPACE_DECL
# endif /* ACE_HAS_WTHREADS_CONDITION_VARIABLE || ACE_LACKS_COND_T */
# if defined (ACE_LACKS_RWLOCK_T) && !defined (ACE_HAS_PTHREADS_UNIX98_EXT)
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
/**
* @class ACE_rwlock_t
*
* @brief This is used to implement readers/writer locks on NT,
* VxWorks, and POSIX pthreads.
*
* At the current time, this stuff only works for threads
* within the same process.
*/
struct ACE_Export ACE_rwlock_t
{
public:
//protected:
/// Serialize access to internal state.
ACE_mutex_t lock_;
/// Reader threads waiting to acquire the lock.
ACE_cond_t waiting_readers_;
/// Number of waiting readers.
int num_waiting_readers_;
/// Writer threads waiting to acquire the lock.
ACE_cond_t waiting_writers_;
/// Number of waiting writers.
int num_waiting_writers_;
/// Value is -1 if writer has the lock, else this keeps track of the
/// number of readers holding the lock.
int ref_count_;
/// Indicate that a reader is trying to upgrade
bool important_writer_;
/// Condition for the upgrading reader
ACE_cond_t waiting_important_writer_;
};
ACE_END_VERSIONED_NAMESPACE_DECL
# elif defined (ACE_HAS_PTHREADS_UNIX98_EXT)
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
typedef pthread_rwlock_t ACE_rwlock_t;
ACE_END_VERSIONED_NAMESPACE_DECL
# elif defined (ACE_HAS_STHREADS)
# include /**/ <synch.h>
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
typedef rwlock_t ACE_rwlock_t;
ACE_END_VERSIONED_NAMESPACE_DECL
# endif /* ACE_LACKS_RWLOCK_T */
// Define some default thread priorities on all threaded platforms, if
// not defined above or in the individual platform config file.
// ACE_THR_PRI_FIFO_DEF should be used by applications for default
// real-time thread priority. ACE_THR_PRI_OTHER_DEF should be used
// for non-real-time priority.
# if !defined(ACE_THR_PRI_FIFO_DEF)
# if defined (ACE_WTHREADS)
// It would be more in spirit to use THREAD_PRIORITY_NORMAL. But,
// using THREAD_PRIORITY_ABOVE_NORMAL should give preference to the
// threads in this process, even if the process is not in the
// REALTIME_PRIORITY_CLASS.
# define ACE_THR_PRI_FIFO_DEF THREAD_PRIORITY_ABOVE_NORMAL
# else /* ! ACE_WTHREADS */
# define ACE_THR_PRI_FIFO_DEF 0
# endif /* ! ACE_WTHREADS */
# endif /* ! ACE_THR_PRI_FIFO_DEF */
# if !defined(ACE_THR_PRI_OTHER_DEF)
# if defined (ACE_WTHREADS)
// It would be more in spirit to use THREAD_PRIORITY_NORMAL. But,
// using THREAD_PRIORITY_ABOVE_NORMAL should give preference to the
// threads in this process, even if the process is not in the
// REALTIME_PRIORITY_CLASS.
# define ACE_THR_PRI_OTHER_DEF THREAD_PRIORITY_NORMAL
# else /* ! ACE_WTHREADS */
# define ACE_THR_PRI_OTHER_DEF 0
# endif /* ! ACE_WTHREADS */
# endif /* ! ACE_THR_PRI_OTHER_DEF */
// Recursive mutex support.
//
// There are two parts to this:
// 1. The mutex type itself. This is based on whether or not the
// platform supports recursive mutexes natively or they're emulated.
// 2. Support for using the recursive mutex with a condition variable.
// When a thread waits on a condition variable, it has to relinquish
// the lock and wait atomically, then reacquire it after the condition
// variable is signaled. In non-recursive mutexes, the platform
// handles this automatically. But in recursive mutexes, especially
// when emulated, the recursion count needs to be maintained across
// the wait. Since another thread needs to be able to acquire the
// lock, it needs to appear free, even if the waiting thread had done
// multiple acquires. Thus, there's another structure to hold this
// information, and is used with the recursive_mutex_cond_unlock()
// and recursive_mutex_cond_relock() methods to maintain the expected
// state when the wait finishes.
# if defined (ACE_HAS_RECURSIVE_MUTEXES)
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
typedef ACE_thread_mutex_t ACE_recursive_thread_mutex_t;
# if defined (ACE_WIN32)
// Windows has recursive mutexes, but doesn't have condition variables,
// so there's no built-in support for this. Thus, the condition-related
// unlock/relock is augmented in ACE.
struct ACE_recursive_mutex_state
{
// On Windows the augmented processing is simply unlocking/relocking
// the recursive locks - the condition handles a single lock ok.
LONG relock_count_;
};
# else
// No need for special handling; just need a type for method signatures.
typedef int ACE_recursive_mutex_state;
# endif /* ACE_WIN32 */
ACE_END_VERSIONED_NAMESPACE_DECL
# else
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
/**
* @class ACE_recursive_thread_mutex_t
*
* @brief
* Implement a thin C++ wrapper that allows nested acquisition
* and release of a mutex that occurs in the same thread.
*
* This implementation is based on an algorithm sketched by Dave
* Butenhof <butenhof@zko.dec.com>. Naturally, I take the
* credit for any mistakes ;-)
*/
class ACE_recursive_thread_mutex_t
{
public:
/// Guards the state of the nesting level and thread id.
ACE_thread_mutex_t nesting_mutex_;
/// This condition variable suspends other waiting threads until the
/// mutex is available.
ACE_cond_t lock_available_;
/// Current nesting level of the recursion.
int nesting_level_;
/// Current owner of the lock.
ACE_thread_t owner_id_;
};
/// Since recursive mutex is emulated, the state saving needs to be handled
/// in ACE as well. These members save those from ACE_recursive_thread_mutex_t.
struct ACE_recursive_mutex_state
{
int nesting_level_;
ACE_thread_t owner_id_;
};
ACE_END_VERSIONED_NAMESPACE_DECL
# endif /* ACE_HAS_RECURSIVE_MUTEXES */
# else /* !ACE_HAS_THREADS, i.e., the OS/platform doesn't support threading. */
// Give these things some reasonable value...
# define ACE_SCOPE_PROCESS 0
# define ACE_SCOPE_LWP 1
# define ACE_SCOPE_THREAD 2
# define ACE_SCHED_OTHER 0
# define ACE_SCHED_FIFO 1
# define ACE_SCHED_RR 2
# if !defined (THR_CANCEL_DISABLE)
# define THR_CANCEL_DISABLE 0
# endif /* ! THR_CANCEL_DISABLE */
# if !defined (THR_CANCEL_ENABLE)
# define THR_CANCEL_ENABLE 0
# endif /* ! THR_CANCEL_ENABLE */
# if !defined (THR_CANCEL_DEFERRED)
# define THR_CANCEL_DEFERRED 0
# endif /* ! THR_CANCEL_DEFERRED */
# if !defined (THR_CANCEL_ASYNCHRONOUS)
# define THR_CANCEL_ASYNCHRONOUS 0
# endif /* ! THR_CANCEL_ASYNCHRONOUS */
# if !defined (THR_JOINABLE)
# define THR_JOINABLE 0 /* ignore in most places */
# endif /* ! THR_JOINABLE */
# if !defined (THR_DETACHED)
# define THR_DETACHED 0 /* ignore in most places */
# endif /* ! THR_DETACHED */
# if !defined (THR_DAEMON)
# define THR_DAEMON 0 /* ignore in most places */
# endif /* ! THR_DAEMON */
# if !defined (THR_BOUND)
# define THR_BOUND 0 /* ignore in most places */
# endif /* ! THR_BOUND */
# if !defined (THR_NEW_LWP)
# define THR_NEW_LWP 0 /* ignore in most places */
# endif /* ! THR_NEW_LWP */
# if !defined (THR_SUSPENDED)
# define THR_SUSPENDED 0 /* ignore in most places */
# endif /* ! THR_SUSPENDED */
# if !defined (THR_SCHED_FIFO)
# define THR_SCHED_FIFO 0
# endif /* ! THR_SCHED_FIFO */
# if !defined (THR_SCHED_RR)
# define THR_SCHED_RR 0
# endif /* ! THR_SCHED_RR */
# if !defined (THR_SCHED_DEFAULT)
# define THR_SCHED_DEFAULT 0
# endif /* ! THR_SCHED_DEFAULT */
# if !defined (THR_INHERIT_SCHED)
# define THR_INHERIT_SCHED 0
# endif /* ! THR_INHERIT_SCHED */
# if !defined (USYNC_THREAD)
# define USYNC_THREAD 0
# endif /* ! USYNC_THREAD */
# if !defined (USYNC_PROCESS)
# define USYNC_PROCESS 0
# endif /* ! USYNC_PROCESS */
# if !defined (THR_SCOPE_PROCESS)
# define THR_SCOPE_PROCESS 0
# endif /* ! THR_SCOPE_PROCESS */
# if !defined (THR_SCOPE_SYSTEM)
# define THR_SCOPE_SYSTEM 0
# endif /* ! THR_SCOPE_SYSTEM */
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
// These are dummies needed for class OS.h
typedef int ACE_cond_t;
struct ACE_Export ACE_condattr_t
{
int type;
};
struct ACE_Export ACE_mutexattr_t
{
int type;
};
typedef int ACE_mutex_t;
typedef int ACE_thread_mutex_t;
typedef int ACE_recursive_thread_mutex_t;
typedef int ACE_recursive_mutex_state;
# if !defined (ACE_HAS_POSIX_SEM) && !defined (ACE_USES_FIFO_SEM)
typedef int ACE_sema_t;
# endif /* !ACE_HAS_POSIX_SEM && !ACE_USES_FIFO_SEM */
typedef int ACE_rwlock_t;
typedef int ACE_thread_t;
typedef int ACE_hthread_t;
// Native TSS key type
typedef unsigned int ACE_OS_thread_key_t;
// Application TSS key type (use this type except in TSS Emulation)
# if defined (ACE_HAS_TSS_EMULATION)
typedef u_int ACE_thread_key_t;
# else /* ! ACE_HAS_TSS_EMULATION */
typedef ACE_OS_thread_key_t ACE_thread_key_t;
# endif /* ! ACE_HAS_TSS_EMULATION */
ACE_END_VERSIONED_NAMESPACE_DECL
// Ensure that ACE_THR_PRI_FIFO_DEF and ACE_THR_PRI_OTHER_DEF are
// defined on non-threaded platforms, to support application source
// code compatibility. ACE_THR_PRI_FIFO_DEF should be used by
// applications for default real-time thread priority.
// ACE_THR_PRI_OTHER_DEF should be used for non-real-time priority.
# if !defined(ACE_THR_PRI_FIFO_DEF)
# define ACE_THR_PRI_FIFO_DEF 0
# endif /* ! ACE_THR_PRI_FIFO_DEF */
# if !defined(ACE_THR_PRI_OTHER_DEF)
# define ACE_THR_PRI_OTHER_DEF 0
# endif /* ! ACE_THR_PRI_OTHER_DEF */
# endif /* ACE_HAS_THREADS ***********************************************/
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
/**
* @class ACE_Thread_ID
*
* @brief
* Defines a platform-independent thread ID class. Note that
* this class should be defined within the scope of a thread, rather
* than at global scope!
*/
class ACE_Export ACE_Thread_ID
{
public:
/// Initialize the object using the thread id and thread handle
/// passed as parameters.
ACE_Thread_ID (ACE_thread_t thr_id,
ACE_hthread_t thr_handle);
/// Initialize the object using calls to ACE_OS::thr_self().
ACE_Thread_ID (void);
/// Copy constructor.
ACE_Thread_ID (const ACE_Thread_ID &id);
/// Assignment operator
ACE_Thread_ID& operator= (const ACE_Thread_ID&id);
/// Get the thread id.
ACE_thread_t id (void) const;
/// Set the thread id.
void id (ACE_thread_t);
/// Get the thread handle.
ACE_hthread_t handle (void) const;
/// Set the thread handle.
void handle (ACE_hthread_t);
// Create a string representation of the thread id.
void to_string (char *thr_string) const;
/// Equality operator.
bool operator== (const ACE_Thread_ID &) const;
/// Inequality operator.
bool operator!= (const ACE_Thread_ID &) const;
private:
/// Identify the thread.
ACE_thread_t thread_id_;
/// Handle to the thread (typically used to "wait" on Win32).
ACE_hthread_t thread_handle_;
};
// = The ACE_Sched_Priority type should be used for platform-
// independent thread and process priorities, by convention.
// int should be used for OS-specific priorities.
typedef int ACE_Sched_Priority;
# if !defined (ACE_DEFAULT_SYNCH_TYPE)
# if defined (ACE_VXWORKS)
// Types include these options: SEM_Q_PRIORITY, SEM_Q_FIFO,
// SEM_DELETE_SAFE, and SEM_INVERSION_SAFE. SEM_Q_FIFO is
// used as the default because that is VxWorks' default.
# define ACE_DEFAULT_SYNCH_TYPE SEM_Q_FIFO
# else
# define ACE_DEFAULT_SYNCH_TYPE USYNC_THREAD
# endif /* ACE_VXWORKS */
#endif /* ! ACE_DEFAULT_SYNCH_TYPE */
// forward declaration
class ACE_Sched_Params;
class ACE_Time_Value;
#if defined (ACE_WIN32)
typedef int ACE_idtype_t;
typedef DWORD ACE_id_t;
typedef int ACE_pri_t;
# define ACE_SELF (0)
#else /* !defined (ACE_WIN32) */
# if defined (ACE_HAS_IDTYPE_T)
typedef idtype_t ACE_idtype_t;
# else
typedef int ACE_idtype_t;
# endif /* ACE_HAS_IDTYPE_T */
# if defined (ACE_HAS_STHREADS)
# if defined (ACE_LACKS_PRI_T)
typedef int pri_t;
# endif /* ACE_LACKS_PRI_T */
typedef id_t ACE_id_t;
# define ACE_SELF P_MYID
typedef pri_t ACE_pri_t;
# else /* ! ACE_HAS_STHREADS */
typedef long ACE_id_t;
# define ACE_SELF (-1)
typedef short ACE_pri_t;
# endif /* ! ACE_HAS_STHREADS */
#endif /* !defined (ACE_WIN32) */
# if defined (ACE_HAS_TSS_EMULATION)
// Allow config.h to set the default number of thread keys.
# if !defined (ACE_DEFAULT_THREAD_KEYS)
# define ACE_DEFAULT_THREAD_KEYS 64
# endif /* ! ACE_DEFAULT_THREAD_KEYS */
// forward declaration
class ACE_TSS_Keys;
/**
* @class ACE_TSS_Emulation
*
* @brief Thread-specific storage emulation.
*
* This provides a thread-specific storage implementation.
* It is intended for use on platforms that don't have a
* native TSS, or have a TSS with limitations such as the
* number of keys or lack of support for removing keys.
*/
class ACE_Export ACE_TSS_Emulation
{
public:
typedef void (*ACE_TSS_DESTRUCTOR)(void *value) /* throw () */;
/// Maximum number of TSS keys allowed over the life of the program.
enum { ACE_TSS_THREAD_KEYS_MAX = ACE_DEFAULT_THREAD_KEYS };
/// Returns the total number of keys allocated so far.
static u_int total_keys ();
/// Sets the argument to the next available key. Returns 0 on success,
/// -1 if no keys are available.
static int next_key (ACE_thread_key_t &key);
/// Release a key that was used. This way the key can be given out in a
/// new request. Returns 0 on success, 1 if the key was not reserved.
static int release_key (ACE_thread_key_t key);
/// Check a key for validity.
static int is_key (ACE_thread_key_t key);
/// Returns the exit hook associated with the key. Does _not_ check
/// for a valid key.
static ACE_TSS_DESTRUCTOR tss_destructor (const ACE_thread_key_t key);
/// Associates the TSS destructor with the key. Does _not_ check
/// for a valid key.
static void tss_destructor (const ACE_thread_key_t key,
ACE_TSS_DESTRUCTOR destructor);
/// Accesses the object referenced by key in the current thread's TSS array.
/// Does _not_ check for a valid key.
static void *&ts_object (const ACE_thread_key_t key);
/**
* Setup an array to be used for local TSS. Returns the array
* address on success. Returns 0 if local TSS had already been
* setup for this thread. There is no corresponding tss_close ()
* because it is not needed.
* @note tss_open () is called by ACE for threads that it spawns.
* If your application spawns threads without using ACE, and it uses
* ACE's TSS emulation, each of those threads should call tss_open
* (). See the ace_thread_adapter () implementation for an example.
*/
static void *tss_open (void *ts_storage[ACE_TSS_THREAD_KEYS_MAX]);
/// Shutdown TSS emulation. For use only by ACE_OS::cleanup_tss ().
static void tss_close ();
private:
// Global TSS structures.
/// Contains the possible value of the next key to be allocated. Which key
/// is actually allocated is based on the tss_keys_used
static u_int total_keys_;
/// Array of thread exit hooks (TSS destructors) that are called for each
/// key (that has one) when the thread exits.
static ACE_TSS_DESTRUCTOR tss_destructor_ [ACE_TSS_THREAD_KEYS_MAX];
/// TSS_Keys instance to administrate whether a specific key is in used
/// or not.
/// or not.
// Static construction in VxWorks 5.4 and later is slightly broken.
// If the static object is more complex than an integral type, static
// construction will occur twice. The tss_keys_used_ object is
// statically constructed and then modified by ACE_Log_Msg::instance()
// when two keys are created and TSS data is stored. However, at
// the end of static construction the tss_keys_used_ object is again
// initialized and therefore it will appear to next_key() that no
// TSS keys have been handed out. That is all true unless the
// tss_keys_used object is a static pointer instead of a static object.
static ACE_TSS_Keys* tss_keys_used_;
# if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
/// Location of current thread's TSS array.
static void **tss_base (void* ts_storage[] = 0, u_int *ts_created = 0);
# else /* ! ACE_HAS_THREAD_SPECIFIC_STORAGE */
/// Location of current thread's TSS array.
static void **&tss_base ();
# endif /* ! ACE_HAS_THREAD_SPECIFIC_STORAGE */
# if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
// Rely on native thread specific storage for the implementation,
// but just use one key.
static ACE_OS_thread_key_t native_tss_key_;
// Used to indicate if native tss key has been allocated
static bool key_created_;
# endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE */
};
# endif /* ACE_HAS_TSS_EMULATION */
// moved ACE_TSS_Ref, ACE_TSS_Info, and ACE_TSS_Keys class
// declarations from OS.cpp so they are visible to the single
// file of template instantiations.
# if defined (ACE_WIN32) || defined (ACE_HAS_TSS_EMULATION)
/**
* @class ACE_TSS_Ref
*
* @brief "Reference count" for thread-specific storage keys.
*
* Since the <ACE_Unbounded_Stack> doesn't allow duplicates, the
* "reference count" is the identify of the thread_id.
*/
class ACE_TSS_Ref
{
public:
/// Constructor
ACE_TSS_Ref (ACE_thread_t id);
/// Default constructor
ACE_TSS_Ref (void);
/// Check for equality.
bool operator== (const ACE_TSS_Ref &) const;
/// Check for inequality.
bool operator!= (const ACE_TSS_Ref &) const;
// private:
/// ID of thread using a specific key.
ACE_thread_t tid_;
};
/**
* @class ACE_TSS_Info
*
* @brief Thread Specific Key management.
*
* This class maps a key to a "destructor."
*/
class ACE_TSS_Info
{
public:
/// Declare pointer to function to destroy tss object.
typedef void (*Destructor)(void *);
/// Constructor
ACE_TSS_Info (ACE_thread_key_t key,
Destructor dest = 0);
/// Default constructor
ACE_TSS_Info (void);
/// Returns 1 if the key is in use, 0 if not.
int key_in_use (void) const { return thread_count_ != -1; }
/// Mark the key as being in use if the flag is non-zero, or
/// not in use if the flag is 0.
void key_in_use (int flag) { thread_count_ = flag == 0 ? -1 : 1; }
/// Check for equality.
bool operator== (const ACE_TSS_Info &) const;
/// Check for inequality.
bool operator!= (const ACE_TSS_Info &) const;
/// Dump the state.
void dump (void);
private:
/// Key to the thread-specific storage item.
ACE_thread_key_t key_;
/// "Destructor" that gets called when the item is finally released.
Destructor destructor_;
/// Count of threads that are using this key. Contains -1 when the
/// key is not in use.
int thread_count_;
friend class ACE_TSS_Cleanup;
};
/**
* @class ACE_TSS_Keys
*
* @brief Collection of in-use flags for a thread's TSS keys.
* For internal use only by ACE_TSS_Cleanup; it is public because
* some compilers can't use nested classes for template instantiation
* parameters.
*
* Wrapper around array of whether each key is in use. A simple
* typedef doesn't work with Sun C++ 4.2.
*/
class ACE_TSS_Keys
{
public:
/// Default constructor, to initialize all bits to zero (unused).
ACE_TSS_Keys (void);
/// Mark the specified key as being in use, if it was not already so marked.
/// Returns 1 if the had already been marked, 0 if not.
int test_and_set (const ACE_thread_key_t key);
/// Mark the specified key as not being in use, if it was not already so
/// cleared. Returns 1 if the key had already been cleared, 0 if not.
int test_and_clear (const ACE_thread_key_t key);
/// Return whether the specific key is marked as in use.
/// Returns 1 if the key is been marked, 0 if not.
int is_set (const ACE_thread_key_t key) const;
private:
/// For a given key, find the word and bit number that represent it.
static void find (const u_int key, u_int &word, u_int &bit);
enum
{
# if ACE_SIZEOF_LONG == 8
ACE_BITS_PER_WORD = 64,
# elif ACE_SIZEOF_LONG == 4
ACE_BITS_PER_WORD = 32,
# else
# error ACE_TSS_Keys only supports 32 or 64 bit longs.
# endif /* ACE_SIZEOF_LONG == 8 */
ACE_WORDS = (ACE_DEFAULT_THREAD_KEYS - 1) / ACE_BITS_PER_WORD + 1
};
/// Bit flag collection. A bit value of 1 indicates that the key is in
/// use by this thread.
u_long key_bit_words_[ACE_WORDS];
};
# endif /* defined (ACE_WIN32) || defined (ACE_HAS_TSS_EMULATION) */
// Support non-scalar thread keys, such as with some POSIX
// implementations, e.g., MVS.
# if defined (ACE_HAS_NONSCALAR_THREAD_KEY_T)
# define ACE_KEY_INDEX(OBJ,KEY) \
u_int OBJ; \
ACE_OS::memcpy (&OBJ, &KEY, sizeof (u_int))
# else
# define ACE_KEY_INDEX(OBJ,KEY) u_int OBJ = KEY
# endif /* ACE_HAS_NONSCALAR_THREAD_KEY_T */
ACE_END_VERSIONED_NAMESPACE_DECL
#if (defined (ACE_HAS_VERSIONED_NAMESPACE) && ACE_HAS_VERSIONED_NAMESPACE == 1)
# define ACE_MUTEX_LOCK_CLEANUP_ADAPTER_NAME ACE_PREPROC_CONCATENATE(ACE_VERSIONED_NAMESPACE_NAME, _ace_mutex_lock_cleanup_adapter)
#endif /* ACE_HAS_VERSIONED_NAMESPACE == 1 */
# if defined (ACE_HAS_THR_C_FUNC)
// This is necessary to work around nasty problems with MVS C++.
extern "C" ACE_Export void ACE_MUTEX_LOCK_CLEANUP_ADAPTER_NAME (void *args);
# define ACE_PTHREAD_CLEANUP_PUSH(A) pthread_cleanup_push (ACE_MUTEX_LOCK_CLEANUP_ADAPTER_NAME, (void *) A);
# define ACE_PTHREAD_CLEANUP_POP(A) pthread_cleanup_pop(A)
# elif defined (ACE_HAS_PTHREADS) && !defined (ACE_LACKS_PTHREAD_CLEANUP)
// Though we are defining a extern "C" function to match the prototype of
// pthread_cleanup_push, it is undone by the Solaris header file
// /usr/include/pthread.h. So this macro generates a warning under Solaris
// with SunCC. This is a bug in the Solaris header file.
extern "C" ACE_Export void ACE_MUTEX_LOCK_CLEANUP_ADAPTER_NAME (void *args);
# define ACE_PTHREAD_CLEANUP_PUSH(A) pthread_cleanup_push (ACE_MUTEX_LOCK_CLEANUP_ADAPTER_NAME, (void *) A);
# define ACE_PTHREAD_CLEANUP_POP(A) pthread_cleanup_pop(A)
# else
# define ACE_PTHREAD_CLEANUP_PUSH(A)
# define ACE_PTHREAD_CLEANUP_POP(A)
# endif /* ACE_HAS_THR_C_FUNC */
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
# if !defined (ACE_WIN32)
// forward decl's
class ACE_event_t;
# endif
class ACE_Base_Thread_Adapter;
namespace ACE_OS {
//@{ @name A set of wrappers for threads
/// This is necessary to deal with POSIX pthreads and their use of
/// structures for thread ids.
extern ACE_Export ACE_thread_t NULL_thread;
/// This is necessary to deal with POSIX pthreads and their use of
/// structures for thread handles.
extern ACE_Export ACE_hthread_t NULL_hthread;
/// This is necessary to deal with POSIX pthreads and their use of
/// structures for TSS keys.
extern ACE_Export ACE_thread_key_t NULL_key;
//@}
/**
* Call TSS destructors for the current thread. If the current
* thread is the main thread, then the argument must be 1.
* For private use of ACE_Object_Manager and ACE_Thread_Adapter only.
*/
extern ACE_Export
void cleanup_tss (const u_int main_thread);
//@{ @name A set of wrappers for condition variables.
ACE_NAMESPACE_INLINE_FUNCTION
int condattr_init (ACE_condattr_t &attributes,
int type = ACE_DEFAULT_SYNCH_TYPE);
ACE_NAMESPACE_INLINE_FUNCTION
int condattr_destroy (ACE_condattr_t &attributes);
#if defined (ACE_LACKS_COND_T)
extern ACE_Export
#else
ACE_NAMESPACE_INLINE_FUNCTION
#endif /* ACE_LACKS_COND_T */
int cond_broadcast (ACE_cond_t *cv);
#if defined (ACE_LACKS_COND_T)
extern ACE_Export
#else
ACE_NAMESPACE_INLINE_FUNCTION
#endif /* ACE_LACKS_COND_T */
int cond_destroy (ACE_cond_t *cv);
extern ACE_Export
int cond_init (ACE_cond_t *cv,
short type = ACE_DEFAULT_SYNCH_TYPE,
const char *name = 0,
void *arg = 0);
#if defined (ACE_LACKS_COND_T)
extern ACE_Export
#else
ACE_NAMESPACE_INLINE_FUNCTION
#endif /* ACE_LACKS_COND_T */
int cond_init (ACE_cond_t *cv,
ACE_condattr_t &attributes,
const char *name = 0,
void *arg = 0);
# if defined (ACE_HAS_WCHAR)
# if defined (ACE_LACKS_COND_T)
extern ACE_Export
# else
ACE_NAMESPACE_INLINE_FUNCTION
# endif /* ACE_LACKS_COND_T */
int cond_init (ACE_cond_t *cv,
short type,
const wchar_t *name,
void *arg = 0);
# if defined (ACE_LACKS_COND_T)
extern ACE_Export
# else
ACE_NAMESPACE_INLINE_FUNCTION
# endif /* ACE_LACKS_COND_T */
int cond_init (ACE_cond_t *cv,
ACE_condattr_t &attributes,
const wchar_t *name,
void *arg = 0);
# endif /* ACE_HAS_WCHAR */
#if defined (ACE_LACKS_COND_T)
extern ACE_Export
#else
ACE_NAMESPACE_INLINE_FUNCTION
#endif /* ACE_LACKS_COND_T */
int cond_signal (ACE_cond_t *cv);
#if defined (ACE_LACKS_COND_T)
extern ACE_Export
#else
ACE_NAMESPACE_INLINE_FUNCTION
#endif /* ACE_LACKS_COND_T */
int cond_timedwait (ACE_cond_t *cv,
ACE_mutex_t *m,
ACE_Time_Value *timeout);
#if defined (ACE_LACKS_COND_T)
extern ACE_Export
#else
ACE_NAMESPACE_INLINE_FUNCTION
#endif /* ACE_LACKS_COND_T */
int cond_wait (ACE_cond_t *cv,
ACE_mutex_t *m);
# if defined (ACE_WIN32) && defined (ACE_HAS_WTHREADS)
extern ACE_Export
int cond_timedwait (ACE_cond_t *cv,
ACE_thread_mutex_t *m,
ACE_Time_Value *timeout);
extern ACE_Export
int cond_wait (ACE_cond_t *cv,
ACE_thread_mutex_t *m);
# endif /* ACE_WIN32 && ACE_HAS_WTHREADS */
//@{ @name A set of wrappers for auto-reset and manual events.
extern ACE_Export
int event_destroy (ACE_event_t *event);
extern ACE_Export
int event_init (ACE_event_t *event,
int manual_reset = 0,
int initial_state = 0,
int type = ACE_DEFAULT_SYNCH_TYPE,
const char *name = 0,
void *arg = 0,
LPSECURITY_ATTRIBUTES sa = 0);
# if defined (ACE_HAS_WCHAR)
ACE_NAMESPACE_INLINE_FUNCTION
int event_init (ACE_event_t *event,
int manual_reset,
int initial_state,
int type,
const wchar_t *name,
void *arg = 0,
LPSECURITY_ATTRIBUTES sa = 0);
# endif /* ACE_HAS_WCHAR */
extern ACE_Export
int event_pulse (ACE_event_t *event);
extern ACE_Export
int event_reset (ACE_event_t *event);
extern ACE_Export
int event_signal (ACE_event_t *event);
extern ACE_Export
int event_timedwait (ACE_event_t *event,
ACE_Time_Value *timeout,
int use_absolute_time = 1);
extern ACE_Export
int event_wait (ACE_event_t *event);
//@}
extern ACE_Export
int lwp_getparams (ACE_Sched_Params &);
extern ACE_Export
int lwp_setparams (const ACE_Sched_Params &);
//@{ @name A set of wrappers for mutex locks.
extern ACE_Export
int mutex_destroy (ACE_mutex_t *m);
extern ACE_Export
int mutex_init (ACE_mutex_t *m,
int lock_scope = ACE_DEFAULT_SYNCH_TYPE,
const char *name = 0,
ACE_mutexattr_t *arg = 0,
LPSECURITY_ATTRIBUTES sa = 0,
int lock_type = 0);
#if defined (ACE_HAS_WCHAR)
extern ACE_Export
int mutex_init (ACE_mutex_t *m,
int lock_scope,
const wchar_t *name,
ACE_mutexattr_t *arg = 0,
LPSECURITY_ATTRIBUTES sa = 0,
int lock_type = 0);
#endif /* ACE_HAS_WCHAR */
/// Win32 note: Abandoned mutexes are not treated differently. 0 is
/// returned since the calling thread does get the ownership.
extern ACE_Export
int mutex_lock (ACE_mutex_t *m);
/// This method is only implemented for Win32. For abandoned
/// mutexes, @a abandoned is set to 1 and 0 is returned.
extern ACE_Export
int mutex_lock (ACE_mutex_t *m,
int &abandoned);
/**
* This method attempts to acquire a lock, but gives up if the lock
* has not been acquired by the given time. If the lock is not
* acquired within the given amount of time, then this method
* returns -1 with an @c ETIME errno on platforms that actually
* support timed mutexes. The timeout should be an absolute time.
* Note that the mutex should not be a recursive one, i.e., it
* should only be a standard mutex or an error checking mutex since
* some implementations of this method don't support recursive
* mutexes. If you want to use a recursive mutex see the methods
* below.
*/
extern ACE_Export
int mutex_lock (ACE_mutex_t *m,
const ACE_Time_Value &timeout);
/**
* If <timeout> == 0, calls <ACE_OS::mutex_lock(m)>. Otherwise,
* this method attempts to acquire a lock, but gives up if the lock
* has not been acquired by the given time, in which case it returns
* -1 with an @c ETIME errno on platforms that actually support timed
* mutexes. The timeout should be an absolute time. Note that the
* mutex should not be a recursive one, i.e., it should only be a
* standard mutex or an error checking mutex since some
* implementations of this method don't support recursive mutexes.
* If you want to use a recursive mutex see the methods below.
*/
ACE_NAMESPACE_INLINE_FUNCTION
int mutex_lock (ACE_mutex_t *m,
const ACE_Time_Value *timeout);
/// Handle asynchronous thread cancellation cleanup.
extern ACE_Export
void mutex_lock_cleanup (void *mutex);
/// Win32 note: Abandoned mutexes are not treated differently. 0 is
/// returned since the calling thread does get the ownership.
extern ACE_Export
int mutex_trylock (ACE_mutex_t *m);
/// This method is only implemented for Win32. For abandoned
/// mutexes, <abandoned> is set to 1 and 0 is returned.
extern ACE_Export
int mutex_trylock (ACE_mutex_t *m,
int &abandoned);
extern ACE_Export
int mutex_unlock (ACE_mutex_t *m);
//@}
/// Low-level interface to @c priocntl(2).
/**
* Can't call the following priocntl, because that's a macro on
* Solaris.
*/
ACE_NAMESPACE_INLINE_FUNCTION
long priority_control (ACE_idtype_t, ACE_id_t, int, void *);
//@{ @name A set of wrappers for recursive mutex locks.
// These two methods are primarily in support of
// ACE_Condition<ACE_Recursive_Thread_Mutex> and should probably not
// be called outside that context.
ACE_NAMESPACE_INLINE_FUNCTION
int recursive_mutex_cond_unlock (ACE_recursive_thread_mutex_t *m,
ACE_recursive_mutex_state &state);
ACE_NAMESPACE_INLINE_FUNCTION
void recursive_mutex_cond_relock (ACE_recursive_thread_mutex_t *m,
ACE_recursive_mutex_state &state);
ACE_NAMESPACE_INLINE_FUNCTION
int recursive_mutex_destroy (ACE_recursive_thread_mutex_t *m);
ACE_NAMESPACE_INLINE_FUNCTION
int recursive_mutex_init (ACE_recursive_thread_mutex_t *m,
const ACE_TCHAR *name = 0,
ACE_mutexattr_t *arg = 0,
LPSECURITY_ATTRIBUTES sa = 0);
ACE_NAMESPACE_INLINE_FUNCTION
int recursive_mutex_lock (ACE_recursive_thread_mutex_t *m);
ACE_NAMESPACE_INLINE_FUNCTION
int recursive_mutex_lock (ACE_recursive_thread_mutex_t *m,
const ACE_Time_Value &timeout);
ACE_NAMESPACE_INLINE_FUNCTION
int recursive_mutex_lock (ACE_recursive_thread_mutex_t *m,
const ACE_Time_Value *timeout);
ACE_NAMESPACE_INLINE_FUNCTION
int recursive_mutex_trylock (ACE_recursive_thread_mutex_t *m);
ACE_NAMESPACE_INLINE_FUNCTION
int recursive_mutex_unlock (ACE_recursive_thread_mutex_t *m);
//@}
//@{ @name A set of wrappers for readers/writer locks.
ACE_NAMESPACE_INLINE_FUNCTION
int rw_rdlock (ACE_rwlock_t *rw);
ACE_NAMESPACE_INLINE_FUNCTION
int rw_tryrdlock (ACE_rwlock_t *rw);
ACE_NAMESPACE_INLINE_FUNCTION
int rw_trywrlock (ACE_rwlock_t *rw);
ACE_NAMESPACE_INLINE_FUNCTION
int rw_trywrlock_upgrade (ACE_rwlock_t *rw);
ACE_NAMESPACE_INLINE_FUNCTION
int rw_unlock (ACE_rwlock_t *rw);
ACE_NAMESPACE_INLINE_FUNCTION
int rw_wrlock (ACE_rwlock_t *rw);
ACE_NAMESPACE_INLINE_FUNCTION
int rwlock_destroy (ACE_rwlock_t *rw);
extern ACE_Export
int rwlock_init (ACE_rwlock_t *rw,
int type = ACE_DEFAULT_SYNCH_TYPE,
const ACE_TCHAR *name = 0,
void *arg = 0);
//@}
//@{ @name Thread scheduler interface.
/// Set scheduling parameters. An id of ACE_SELF indicates, e.g.,
/// set the parameters on the calling thread.
extern ACE_Export
int sched_params (const ACE_Sched_Params &, ACE_id_t id = ACE_SELF);
//@}
/// Find the schedling class ID that corresponds to the class name.
extern ACE_Export
int scheduling_class (const char *class_name, ACE_id_t &);
//@{ @name A set of wrappers for semaphores.
ACE_NAMESPACE_INLINE_FUNCTION
int sema_destroy (ACE_sema_t *s);
ACE_NAMESPACE_INLINE_FUNCTION
int sema_init (ACE_sema_t *s,
u_int count,
int type = ACE_DEFAULT_SYNCH_TYPE,
const char *name = 0,
void *arg = 0,
int max = 0x7fffffff,
LPSECURITY_ATTRIBUTES sa = 0);
# if defined (ACE_HAS_WCHAR)
ACE_NAMESPACE_INLINE_FUNCTION
int sema_init (ACE_sema_t *s,
u_int count,
int type,
const wchar_t *name,
void *arg = 0,
int max = 0x7fffffff,
LPSECURITY_ATTRIBUTES sa = 0);
# endif /* ACE_HAS_WCHAR */
ACE_NAMESPACE_INLINE_FUNCTION
int sema_post (ACE_sema_t *s);
ACE_NAMESPACE_INLINE_FUNCTION
int sema_post (ACE_sema_t *s,
u_int release_count);
ACE_NAMESPACE_INLINE_FUNCTION
int sema_trywait (ACE_sema_t *s);
ACE_NAMESPACE_INLINE_FUNCTION
int sema_wait (ACE_sema_t *s);
ACE_NAMESPACE_INLINE_FUNCTION
int sema_wait (ACE_sema_t *s,
ACE_Time_Value &tv);
ACE_NAMESPACE_INLINE_FUNCTION
int sema_wait (ACE_sema_t *s,
ACE_Time_Value *tv);
//@}
//@{ @name A set of wrappers for System V semaphores.
ACE_NAMESPACE_INLINE_FUNCTION
int semctl (int int_id,
int semnum,
int cmd,
semun);
ACE_NAMESPACE_INLINE_FUNCTION
int semget (key_t key,
int nsems,
int flags);
ACE_NAMESPACE_INLINE_FUNCTION
int semop (int int_id,
struct sembuf *sops,
size_t nsops);
//@}
/// Friendly interface to @c priocntl(2).
extern ACE_Export
int set_scheduling_params (const ACE_Sched_Params &,
ACE_id_t id = ACE_SELF);
ACE_NAMESPACE_INLINE_FUNCTION
int sigtimedwait (const sigset_t *set,
siginfo_t *info,
const ACE_Time_Value *timeout);
ACE_NAMESPACE_INLINE_FUNCTION
int sigwait (sigset_t *set,
int *sig = 0);
ACE_NAMESPACE_INLINE_FUNCTION
int sigwaitinfo (const sigset_t *set,
siginfo_t *info);
ACE_NAMESPACE_INLINE_FUNCTION
int thr_cancel (ACE_thread_t t_id);
ACE_NAMESPACE_INLINE_FUNCTION
int thr_cmp (ACE_hthread_t t1,
ACE_hthread_t t2);
// These are non-portable since they use ACE_thread_t and
// ACE_hthread_t and will go away in a future release.
ACE_NAMESPACE_INLINE_FUNCTION
int thr_continue (ACE_hthread_t target_thread);
/*
* Creates a new thread having @a flags attributes and running @a func
* with @a args (if @a thread_adapter is non-0 then @a func and @a args
* are ignored and are obtained from @a thread_adapter). @a thr_id
* and @a t_handle are set to the thread's ID and handle (?),
* respectively. The thread runs at @a priority priority (see
* below).
*
* The @a flags are a bitwise-OR of the following:
* = BEGIN<INDENT>
* THR_CANCEL_DISABLE, THR_CANCEL_ENABLE, THR_CANCEL_DEFERRED,
* THR_CANCEL_ASYNCHRONOUS, THR_BOUND, THR_NEW_LWP, THR_DETACHED,
* THR_SUSPENDED, THR_DAEMON, THR_JOINABLE, THR_SCHED_FIFO,
* THR_SCHED_RR, THR_SCHED_DEFAULT, THR_EXPLICIT_SCHED,
* THR_SCOPE_SYSTEM, THR_SCOPE_PROCESS
* = END<INDENT>
*
* By default, or if @a priority is set to
* ACE_DEFAULT_THREAD_PRIORITY, an "appropriate" priority value for
* the given scheduling policy (specified in @a flags, e.g.,
* @c THR_SCHED_DEFAULT) is used. This value is calculated
* dynamically, and is the median value between the minimum and
* maximum priority values for the given policy. If an explicit
* value is given, it is used. Note that actual priority values are
* EXTREMEMLY implementation-dependent, and are probably best
* avoided.
*
* Note that @a thread_adapter is always deleted by @c thr_create,
* therefore it must be allocated with global operator new.
*
* At the moment for @a thr_name a valid string is passed then this
* will be used on VxWorks to set the task name. If we just pass a pointer
* the name of the task is returned
*/
extern ACE_Export
int thr_create (ACE_THR_FUNC func,
void *args,
long flags,
ACE_thread_t *thr_id,
ACE_hthread_t *t_handle = 0,
long priority = ACE_DEFAULT_THREAD_PRIORITY,
void *stack = 0,
size_t stacksize = ACE_DEFAULT_THREAD_STACKSIZE,
ACE_Base_Thread_Adapter *thread_adapter = 0,
const char** thr_name = 0);
ACE_NAMESPACE_INLINE_FUNCTION
int thr_equal (ACE_thread_t t1, ACE_thread_t t2);
extern ACE_Export
void thr_exit (ACE_THR_FUNC_RETURN status = 0);
ACE_NAMESPACE_INLINE_FUNCTION
int thr_getconcurrency (void);
ACE_NAMESPACE_INLINE_FUNCTION
int thr_getprio (ACE_hthread_t id,
int &priority);
ACE_NAMESPACE_INLINE_FUNCTION
int thr_getprio (ACE_hthread_t id,
int &priority,
int &policy);
# if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
ACE_NAMESPACE_INLINE_FUNCTION
/// for internal use only. Applications should call thr_getspecific
int thr_getspecific_native (ACE_OS_thread_key_t key, void **data);
# endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE */
ACE_NAMESPACE_INLINE_FUNCTION
int thr_getspecific (ACE_thread_key_t key, void **data);
#if defined (ACE_HAS_VXTHREADS)
extern ACE_Export
#else
ACE_NAMESPACE_INLINE_FUNCTION
#endif /* ACE_HAS_VXTHREADS */
int thr_join (ACE_hthread_t waiter_id, ACE_THR_FUNC_RETURN *status);
#if defined (ACE_HAS_VXTHREADS)
extern ACE_Export
#else
ACE_NAMESPACE_INLINE_FUNCTION
#endif /* ACE_HAS_VXTHREADS */
int thr_join (ACE_thread_t waiter_id,
ACE_thread_t *thr_id,
ACE_THR_FUNC_RETURN *status);
/**
* Get the thread affinity
*
* @param thr_id For NPTL-threads, when ACE_HAS_PTHREAD_SETAFFINITY_NP
* defined, this is the thread-id. For linux-threads, when
* ACE_HAS_SCHED_SETAFFINITY defined, it expects a process-id. Since for
* linux-threads a thread is seen as a process, it does the job.
* @param cpu_set_size The size of the cpu_mask, in bytes.
* @param cpu_mask Is a bitmask of CPUs to bind to, e.g value 1 binds the
* thread to the "CPU 0", etc
*/
extern ACE_Export
int thr_get_affinity (ACE_hthread_t thr_id,
size_t cpu_set_size,
cpu_set_t * cpu_mask);
/**
* Set the thread affinity
*
* @param thr_id For NPTL-threads, when ACE_HAS_PTHREAD_SETAFFINITY_NP
* defined, this is the thread-id. For linux-threads, when
* ACE_HAS_SCHED_SETAFFINITY defined, it expects a process-id. Since for
* linux-threads a thread is seen as a process, it does the job.
* @param cpu_set_size The size of the cpu_mask, in bytes.
* @param cpu_mask Is a bitmask of CPUs to bind to, e.g value 1 binds the
* thread to the "CPU 0", etc
*/
extern ACE_Export
int thr_set_affinity (ACE_hthread_t thr_id,
size_t cpu_set_size,
const cpu_set_t * cpu_mask);
extern ACE_Export
int thr_key_detach (ACE_thread_key_t key);
extern ACE_Export
int thr_key_used (ACE_thread_key_t key);
# if defined (ACE_HAS_THR_C_DEST)
# if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
/// @internal Applications should call thr_keycreate
extern ACE_Export
int thr_keycreate_native (ACE_OS_thread_key_t *key, ACE_THR_C_DEST);
# endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE */
extern ACE_Export
int thr_keycreate (ACE_thread_key_t *key, ACE_THR_C_DEST);
# else
# if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
/// @internal Applications should call thr_keycreate instead
extern ACE_Export
int thr_keycreate_native (ACE_OS_thread_key_t *key,
ACE_THR_DEST);
# endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE */
extern ACE_Export
int thr_keycreate (ACE_thread_key_t *key, ACE_THR_DEST);
# endif /* ACE_HAS_THR_C_DEST */
# if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
/// @internal Applications should call thr_keyfree instead
extern ACE_Export
int thr_keyfree_native (ACE_OS_thread_key_t key);
# endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE */
extern ACE_Export
int thr_keyfree (ACE_thread_key_t key);
ACE_NAMESPACE_INLINE_FUNCTION
int thr_kill (ACE_thread_t thr_id, int signum);
ACE_NAMESPACE_INLINE_FUNCTION
size_t thr_min_stack (void);
ACE_NAMESPACE_INLINE_FUNCTION
ACE_thread_t thr_self (void);
ACE_NAMESPACE_INLINE_FUNCTION
void thr_self (ACE_hthread_t &);
ACE_NAMESPACE_INLINE_FUNCTION
const char* thr_name (void);
/// State is THR_CANCEL_ENABLE or THR_CANCEL_DISABLE
ACE_NAMESPACE_INLINE_FUNCTION
int thr_setcancelstate (int new_state, int *old_state);
/// Type is THR_CANCEL_DEFERRED or THR_CANCEL_ASYNCHRONOUS
ACE_NAMESPACE_INLINE_FUNCTION
int thr_setcanceltype (int new_type, int *old_type);
ACE_NAMESPACE_INLINE_FUNCTION
int thr_setconcurrency (int hint);
ACE_NAMESPACE_INLINE_FUNCTION
int thr_setprio (ACE_hthread_t ht_id, int priority, int policy = -1);
extern ACE_Export
int thr_setprio (const ACE_Sched_Priority prio);
# if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
/// @internal Applications should call thr_setspecific
extern ACE_Export
int thr_setspecific_native (ACE_OS_thread_key_t key, void *data);
# endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE */
extern ACE_Export
int thr_setspecific (ACE_thread_key_t key, void *data);
ACE_NAMESPACE_INLINE_FUNCTION
int thr_sigsetmask (int how, const sigset_t *nsm, sigset_t *osm);
ACE_NAMESPACE_INLINE_FUNCTION
int thr_suspend (ACE_hthread_t target_thread);
ACE_NAMESPACE_INLINE_FUNCTION
void thr_testcancel (void);
ACE_NAMESPACE_INLINE_FUNCTION
void thr_yield (void);
//@{ @name A set of wrappers for mutex locks that only work within a single process.
ACE_NAMESPACE_INLINE_FUNCTION
int thread_mutex_destroy (ACE_thread_mutex_t *m);
ACE_NAMESPACE_INLINE_FUNCTION
int thread_mutex_init (ACE_thread_mutex_t *m,
int lock_type = 0,
const char *name = 0,
ACE_mutexattr_t *arg = 0);
#if defined (ACE_HAS_WCHAR)
ACE_NAMESPACE_INLINE_FUNCTION
int thread_mutex_init (ACE_thread_mutex_t *m,
int lock_type,
const wchar_t *name,
ACE_mutexattr_t *arg = 0);
#endif /* ACE_HAS_WCHAR */
ACE_NAMESPACE_INLINE_FUNCTION
int thread_mutex_lock (ACE_thread_mutex_t *m);
ACE_NAMESPACE_INLINE_FUNCTION
int thread_mutex_lock (ACE_thread_mutex_t *m,
const ACE_Time_Value &timeout);
ACE_NAMESPACE_INLINE_FUNCTION
int thread_mutex_lock (ACE_thread_mutex_t *m,
const ACE_Time_Value *timeout);
ACE_NAMESPACE_INLINE_FUNCTION
int thread_mutex_trylock (ACE_thread_mutex_t *m);
ACE_NAMESPACE_INLINE_FUNCTION
int thread_mutex_unlock (ACE_thread_mutex_t *m);
//@}
/**
* This method uses process id and object pointer to come up with a
* machine wide unique name. The process ID will provide uniqueness
* between processes on the same machine. The "this" pointer of the
* @a object will provide uniqueness between other "live" objects in
* the same process. The uniqueness of this name is therefore only
* valid for the life of @a object.
*/
extern ACE_Export
void unique_name (const void *object,
char *name,
size_t length);
#if defined (ACE_USES_WCHAR)
extern ACE_Export
void unique_name (const void *object,
wchar_t *name,
size_t length);
#endif /* ACE_USES_WCHAR */
} /* namespace ACE_OS */
ACE_END_VERSIONED_NAMESPACE_DECL
#if !defined (ACE_WIN32)
extern "C"
{
typedef struct
{
#if (defined (ACE_HAS_PTHREADS) && defined (_POSIX_THREAD_PROCESS_SHARED) && !defined (ACE_LACKS_CONDATTR_PSHARED)) || \
(!defined (ACE_USES_FIFO_SEM) && \
(!defined (ACE_HAS_POSIX_SEM) || !defined (ACE_HAS_POSIX_SEM_TIMEOUT) || defined (ACE_LACKS_NAMED_POSIX_SEM)))
/// Protect critical section.
ACE_mutex_t lock_;
/// Keeps track of waiters.
ACE_cond_t condition_;
#else
# if (defined (ACE_HAS_PTHREADS) && defined (_POSIX_THREAD_PROCESS_SHARED) && !defined (ACE_LACKS_MUTEXATTR_PSHARED)) || \
(!defined (ACE_USES_FIFO_SEM) && (!defined (ACE_HAS_POSIX_SEM) || defined (ACE_LACKS_NAMED_POSIX_SEM)))
/// Protect critical section.
ACE_mutex_t lock_;
# endif
#endif
/// Object type.
int type_;
/// Specifies if this is an auto- or manual-reset event.
int manual_reset_;
/// "True" if signaled.
int is_signaled_;
/// Special bool for auto_events alone
/**
* The semantics of auto events forces us to introduce this extra
* variable to ensure that the thread is not woken up
* spuriously. Please see event_wait and event_timedwait () to see
* how this is used for auto_events.
* @todo This is a hack that needs revisiting after x.4
*/
bool auto_event_signaled_;
/// Number of waiting threads.
unsigned long waiting_threads_;
/// Signal count
unsigned long signal_count_;
} ACE_eventdata_t;
}
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
/**
* @class ACE_event_t
*
* @brief Wrapper for NT events on UNIX.
*/
class ACE_Export ACE_event_t
{
friend int ACE_OS::event_init(ACE_event_t*, int, int, int, const char*, void*,int);
friend int ACE_OS::event_destroy(ACE_event_t*);
friend int ACE_OS::event_wait(ACE_event_t*);
friend int ACE_OS::event_timedwait(ACE_event_t*, ACE_Time_Value*, int);
friend int ACE_OS::event_signal(ACE_event_t*);
friend int ACE_OS::event_pulse(ACE_event_t*);
friend int ACE_OS::event_reset(ACE_event_t*);
protected:
/// Event name if process shared.
char* name_;
/// Event data
ACE_eventdata_t* eventdata_;
#if (!defined (ACE_HAS_PTHREADS) || !defined (_POSIX_THREAD_PROCESS_SHARED) || defined (ACE_LACKS_CONDATTR_PSHARED)) && \
(defined (ACE_USES_FIFO_SEM) || \
(defined (ACE_HAS_POSIX_SEM) && defined (ACE_HAS_POSIX_SEM_TIMEOUT) && !defined (ACE_LACKS_NAMED_POSIX_SEM)))
/// Keeps track of waiters.
ACE_sema_t semaphore_;
# if (!defined (ACE_HAS_PTHREADS) || !defined (_POSIX_THREAD_PROCESS_SHARED) || defined (ACE_LACKS_MUTEXATTR_PSHARED)) && \
(defined (ACE_USES_FIFO_SEM) || (defined (ACE_HAS_POSIX_SEM) && !defined (ACE_LACKS_NAMED_POSIX_SEM)))
/// Protect critical section.
ACE_sema_t lock_;
# endif
#endif
};
ACE_END_VERSIONED_NAMESPACE_DECL
#endif /* ACE_WIN32 */
#if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
/**
* @class ACE_OS_Thread_Mutex_Guard
*
* This data structure is meant to be used within an ACE_OS
* function. It performs automatic aquisition and release of
* an ACE_thread_mutex_t.
*
* If an object of this class is instantiated before ACE_Object_Manager is
* initialized, it will not do anything. This is because this class is
* used only with the ACE_OS_GUARD macro which is passing a reference to
* one of the preallocated Object Manager locks. If the object manager
* hasn't been initialized yet, the lock reference is bogus. This is an
* acceptable tradeoff since in cases where the lock reference is bogus,
* there isn't multithreaded access. Please see detailed comments in
* Object_Manager.h for further information.
*
* For internal use only by ACE_OS.
*/
class ACE_OS_Thread_Mutex_Guard
{
public:
/// Implicitly and automatically acquire the lock.
ACE_OS_Thread_Mutex_Guard (ACE_thread_mutex_t &m);
/// Implicitly release the lock.
~ACE_OS_Thread_Mutex_Guard (void);
/// Explicitly acquire the lock.
int acquire (void);
/// Explicitly release the lock.
int release (void);
protected:
/// Reference to the mutex.
ACE_thread_mutex_t &lock_;
/// Keeps track of whether we acquired the lock or failed.
int owner_;
// = Prevent assignment and initialization.
ACE_OS_Thread_Mutex_Guard &operator= (const ACE_OS_Thread_Mutex_Guard &);
ACE_OS_Thread_Mutex_Guard (const ACE_OS_Thread_Mutex_Guard &);
};
/**
* @class ACE_OS_Recursive_Thread_Mutex_Guard
*
* @brief For internal use only by ACE_OS.
*
* This data structure is meant to be used within an ACE_OS
* function. It performs automatic aquisition and release of
* an ACE_recursive_thread_mutex_t.
*
* If an object of this class is instantiated before ACE_Object_Manager is
* initialized, it will not do anything. This is because this class is
* used only with the ACE_TSS_GUARD macro which is passing a reference to
* one of the preallocated Object Manager locks. If the object manager
* hasn't been initialized yet, the lock reference is bogus. This is an
* acceptable tradeoff since in cases where the lock reference is bogus,
* there isn't multithreaded access. Please see detailed comments in
* Object_Manager.h for further information.
*/
class ACE_OS_Recursive_Thread_Mutex_Guard
{
public:
/// Implicitly and automatically acquire the lock.
ACE_OS_Recursive_Thread_Mutex_Guard (ACE_recursive_thread_mutex_t &m);
/// Implicitly release the lock.
~ACE_OS_Recursive_Thread_Mutex_Guard (void);
/// Explicitly acquire the lock.
int acquire (void);
/// Explicitly release the lock.
int release (void);
protected:
/// Reference to the mutex.
ACE_recursive_thread_mutex_t &lock_;
/// Keeps track of whether we acquired the lock or failed.
int owner_;
// = Prevent assignment and initialization.
ACE_OS_Recursive_Thread_Mutex_Guard &operator= (
const ACE_OS_Recursive_Thread_Mutex_Guard &);
ACE_OS_Recursive_Thread_Mutex_Guard (
const ACE_OS_Recursive_Thread_Mutex_Guard &);
};
ACE_END_VERSIONED_NAMESPACE_DECL
// used in time and unistd
# define ACE_OS_GUARD \
ACE_OS_Thread_Mutex_Guard ace_os_guard__ (*(ACE_thread_mutex_t *) \
ACE_OS_Object_Manager::preallocated_object[ \
ACE_OS_Object_Manager::ACE_OS_MONITOR_LOCK]);
// used in Thread
# define ACE_TSS_CLEANUP_GUARD \
ACE_OS_Recursive_Thread_Mutex_Guard ace_tss_cleanup_guard__ (*(ACE_recursive_thread_mutex_t *) \
ACE_OS_Object_Manager::preallocated_object[ \
ACE_OS_Object_Manager::ACE_TSS_CLEANUP_LOCK]);
// used in Thread
# define ACE_TSS_BASE_GUARD \
ACE_OS_Recursive_Thread_Mutex_Guard ace_tss_base_guard__ (*(ACE_recursive_thread_mutex_t *) \
ACE_OS_Object_Manager::preallocated_object[ \
ACE_OS_Object_Manager::ACE_TSS_BASE_LOCK]);
#else /* ! ACE_MT_SAFE */
# define ACE_OS_GUARD
# define ACE_TSS_CLEANUP_GUARD
# define ACE_TSS_BASE_GUARD
#endif /* ! ACE_MT_SAFE */
# if defined (ACE_HAS_INLINED_OSCALLS)
# if defined (ACE_INLINE)
# undef ACE_INLINE
# endif /* ACE_INLINE */
# define ACE_INLINE inline
# include "ace/OS_NS_Thread.inl"
# endif /* ACE_HAS_INLINED_OSCALLS */
# include /**/ "ace/post.h"
#endif /* ACE_OS_NS_THREAD_H */
|