1627 static pthread_condattr_t _condAttr[1]; 1628 1629 // Shared mutexattr to explicitly set the type to PTHREAD_MUTEX_NORMAL as not 1630 // all systems (e.g. FreeBSD) map the default to "normal". 1631 static pthread_mutexattr_t _mutexAttr[1]; 1632 1633 // common basic initialization that is always supported 1634 static void pthread_init_common(void) { 1635 int status; 1636 if ((status = pthread_condattr_init(_condAttr)) != 0) { 1637 fatal("pthread_condattr_init: %s", os::strerror(status)); 1638 } 1639 if ((status = pthread_mutexattr_init(_mutexAttr)) != 0) { 1640 fatal("pthread_mutexattr_init: %s", os::strerror(status)); 1641 } 1642 if ((status = pthread_mutexattr_settype(_mutexAttr, PTHREAD_MUTEX_NORMAL)) != 0) { 1643 fatal("pthread_mutexattr_settype: %s", os::strerror(status)); 1644 } 1645 } 1646 1647 // Not all POSIX types and API's are available on all notionally "posix" 1648 // platforms. If we have build-time support then we will check for actual 1649 // runtime support via dlopen/dlsym lookup. This allows for running on an 1650 // older OS version compared to the build platform. But if there is no 1651 // build time support then there cannot be any runtime support as we do not 1652 // know what the runtime types would be (for example clockid_t might be an 1653 // int or int64_t). 1654 // 1655 #ifdef SUPPORTS_CLOCK_MONOTONIC 1656 1657 // This means we have clockid_t, clock_gettime et al and CLOCK_MONOTONIC 1658 1659 int (*os::Posix::_clock_gettime)(clockid_t, struct timespec *) = NULL; 1660 int (*os::Posix::_clock_getres)(clockid_t, struct timespec *) = NULL; 1661 1662 static int (*_pthread_condattr_setclock)(pthread_condattr_t *, clockid_t) = NULL; 1663 1664 static bool _use_clock_monotonic_condattr = false; 1665 1666 // Determine what POSIX API's are present and do appropriate 1737 " - changes to the time-of-day clock may have adverse affects"); 1738 } else { 1739 fatal("pthread_condattr_setclock: %s", os::strerror(status)); 1740 } 1741 } else { 1742 _use_clock_monotonic_condattr = true; 1743 } 1744 } 1745 #endif // !SOLARIS 1746 1747 } 1748 1749 void os::Posix::init_2(void) { 1750 #ifndef SOLARIS 1751 log_info(os)("Use of CLOCK_MONOTONIC is%s supported", 1752 (_clock_gettime != NULL ? "" : " not")); 1753 log_info(os)("Use of pthread_condattr_setclock is%s supported", 1754 (_pthread_condattr_setclock != NULL ? "" : " not")); 1755 log_info(os)("Relative timed-wait using pthread_cond_timedwait is associated with %s", 1756 _use_clock_monotonic_condattr ? "CLOCK_MONOTONIC" : "the default clock"); 1757 #endif // !SOLARIS 1758 } 1759 1760 #else // !SUPPORTS_CLOCK_MONOTONIC 1761 1762 void os::Posix::init(void) { 1763 pthread_init_common(); 1764 } 1765 1766 void os::Posix::init_2(void) { 1767 #ifndef SOLARIS 1768 log_info(os)("Use of CLOCK_MONOTONIC is not supported"); 1769 log_info(os)("Use of pthread_condattr_setclock is not supported"); 1770 log_info(os)("Relative timed-wait using pthread_cond_timedwait is associated with the default clock"); 1771 #endif // !SOLARIS 1772 } 1773 1774 #endif // SUPPORTS_CLOCK_MONOTONIC 1775 1776 // Utility to convert the given timeout to an absolute timespec 1777 // (based on the appropriate clock) to use with pthread_cond_timewait, 1778 // and sem_timedwait(). 1779 // The clock queried here must be the clock used to manage the 1780 // timeout of the condition variable or semaphore. 1781 // 1782 // The passed in timeout value is either a relative time in nanoseconds 1783 // or an absolute time in milliseconds. A relative timeout will be 1784 // associated with CLOCK_MONOTONIC if available, unless the real-time clock 1785 // is explicitly requested; otherwise, or if absolute, 1786 // the default time-of-day clock will be used. 1787 1788 // Given time is a 64-bit value and the time_t used in the timespec is 1789 // sometimes a signed-32-bit value we have to watch for overflow if times 1790 // way in the future are given. Further on Solaris versions | 1627 static pthread_condattr_t _condAttr[1]; 1628 1629 // Shared mutexattr to explicitly set the type to PTHREAD_MUTEX_NORMAL as not 1630 // all systems (e.g. FreeBSD) map the default to "normal". 1631 static pthread_mutexattr_t _mutexAttr[1]; 1632 1633 // common basic initialization that is always supported 1634 static void pthread_init_common(void) { 1635 int status; 1636 if ((status = pthread_condattr_init(_condAttr)) != 0) { 1637 fatal("pthread_condattr_init: %s", os::strerror(status)); 1638 } 1639 if ((status = pthread_mutexattr_init(_mutexAttr)) != 0) { 1640 fatal("pthread_mutexattr_init: %s", os::strerror(status)); 1641 } 1642 if ((status = pthread_mutexattr_settype(_mutexAttr, PTHREAD_MUTEX_NORMAL)) != 0) { 1643 fatal("pthread_mutexattr_settype: %s", os::strerror(status)); 1644 } 1645 } 1646 1647 #ifndef SOLARIS 1648 sigset_t sigs; 1649 struct sigaction sigact[NSIG]; 1650 1651 struct sigaction* os::Posix::get_preinstalled_handler(int sig) { 1652 if (sigismember(&sigs, sig)) { 1653 return &sigact[sig]; 1654 } 1655 return NULL; 1656 } 1657 1658 void os::Posix::save_preinstalled_handler(int sig, struct sigaction& oldAct) { 1659 assert(sig > 0 && sig < NSIG, "vm signal out of expected range"); 1660 sigact[sig] = oldAct; 1661 sigaddset(&sigs, sig); 1662 } 1663 #endif 1664 1665 // Not all POSIX types and API's are available on all notionally "posix" 1666 // platforms. If we have build-time support then we will check for actual 1667 // runtime support via dlopen/dlsym lookup. This allows for running on an 1668 // older OS version compared to the build platform. But if there is no 1669 // build time support then there cannot be any runtime support as we do not 1670 // know what the runtime types would be (for example clockid_t might be an 1671 // int or int64_t). 1672 // 1673 #ifdef SUPPORTS_CLOCK_MONOTONIC 1674 1675 // This means we have clockid_t, clock_gettime et al and CLOCK_MONOTONIC 1676 1677 int (*os::Posix::_clock_gettime)(clockid_t, struct timespec *) = NULL; 1678 int (*os::Posix::_clock_getres)(clockid_t, struct timespec *) = NULL; 1679 1680 static int (*_pthread_condattr_setclock)(pthread_condattr_t *, clockid_t) = NULL; 1681 1682 static bool _use_clock_monotonic_condattr = false; 1683 1684 // Determine what POSIX API's are present and do appropriate 1755 " - changes to the time-of-day clock may have adverse affects"); 1756 } else { 1757 fatal("pthread_condattr_setclock: %s", os::strerror(status)); 1758 } 1759 } else { 1760 _use_clock_monotonic_condattr = true; 1761 } 1762 } 1763 #endif // !SOLARIS 1764 1765 } 1766 1767 void os::Posix::init_2(void) { 1768 #ifndef SOLARIS 1769 log_info(os)("Use of CLOCK_MONOTONIC is%s supported", 1770 (_clock_gettime != NULL ? "" : " not")); 1771 log_info(os)("Use of pthread_condattr_setclock is%s supported", 1772 (_pthread_condattr_setclock != NULL ? "" : " not")); 1773 log_info(os)("Relative timed-wait using pthread_cond_timedwait is associated with %s", 1774 _use_clock_monotonic_condattr ? "CLOCK_MONOTONIC" : "the default clock"); 1775 sigemptyset(&sigs); 1776 #endif // !SOLARIS 1777 } 1778 1779 #else // !SUPPORTS_CLOCK_MONOTONIC 1780 1781 void os::Posix::init(void) { 1782 pthread_init_common(); 1783 } 1784 1785 void os::Posix::init_2(void) { 1786 #ifndef SOLARIS 1787 log_info(os)("Use of CLOCK_MONOTONIC is not supported"); 1788 log_info(os)("Use of pthread_condattr_setclock is not supported"); 1789 log_info(os)("Relative timed-wait using pthread_cond_timedwait is associated with the default clock"); 1790 sigemptyset(&sigs); 1791 #endif // !SOLARIS 1792 } 1793 1794 #endif // SUPPORTS_CLOCK_MONOTONIC 1795 1796 // Utility to convert the given timeout to an absolute timespec 1797 // (based on the appropriate clock) to use with pthread_cond_timewait, 1798 // and sem_timedwait(). 1799 // The clock queried here must be the clock used to manage the 1800 // timeout of the condition variable or semaphore. 1801 // 1802 // The passed in timeout value is either a relative time in nanoseconds 1803 // or an absolute time in milliseconds. A relative timeout will be 1804 // associated with CLOCK_MONOTONIC if available, unless the real-time clock 1805 // is explicitly requested; otherwise, or if absolute, 1806 // the default time-of-day clock will be used. 1807 1808 // Given time is a 64-bit value and the time_t used in the timespec is 1809 // sometimes a signed-32-bit value we have to watch for overflow if times 1810 // way in the future are given. Further on Solaris versions |