diff --git a/boost/chrono/config.hpp b/boost/chrono/config.hpp index 1045ba3a..84eed72c 100644 --- a/boost/chrono/config.hpp +++ b/boost/chrono/config.hpp @@ -84,6 +84,9 @@ # include //to check for CLOCK_REALTIME and CLOCK_MONOTONIC and _POSIX_THREAD_CPUTIME # if defined(CLOCK_MONOTONIC) # define BOOST_CHRONO_HAS_CLOCK_STEADY +# elif defined(__GNUC__) && defined(__hpux) +# define BOOST_CHRONO_HAS_GETHRTIME +# define BOOST_CHRONO_HAS_CLOCK_STEADY # endif # if defined(_POSIX_THREAD_CPUTIME) && !defined(BOOST_DISABLE_THREADS) # define BOOST_CHRONO_HAS_THREAD_CLOCK diff --git a/boost/chrono/detail/inlined/posix/chrono.hpp b/boost/chrono/detail/inlined/posix/chrono.hpp index c4c8a6ad..4046d0e1 100644 --- a/boost/chrono/detail/inlined/posix/chrono.hpp +++ b/boost/chrono/detail/inlined/posix/chrono.hpp @@ -74,6 +74,11 @@ namespace chrono steady_clock::time_point steady_clock::now() BOOST_NOEXCEPT { +#ifdef BOOST_CHRONO_HAS_GETHRTIME + hrtime_t hrt = gethrtime(); + BOOST_ASSERT(hrt >= 0); + return time_point(nanoseconds(hrt)); +#else timespec ts; if ( ::clock_gettime( CLOCK_MONOTONIC, &ts ) ) { @@ -82,11 +87,33 @@ namespace chrono return time_point(duration( static_cast( ts.tv_sec ) * 1000000000 + ts.tv_nsec)); +#endif } #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING steady_clock::time_point steady_clock::now(system::error_code & ec) { +#ifdef BOOST_CHRONO_HAS_GETHRTIME + hrtime_t hrt = gethrtime(); + if (hrt < 0) + { + boost::throw_exception( + system::system_error( + EFAULT, + BOOST_CHRONO_SYSTEM_CATEGORY, + "chrono::steady_clock" )); + } + else + { + ec.assign( EFAULT, BOOST_CHRONO_SYSTEM_CATEGORY ); + return time_point(); + } + if (!BOOST_CHRONO_IS_THROWS(ec)) + { + ec.clear(); + } + return time_point(nanoseconds(hrt)); +#else timespec ts; if ( ::clock_gettime( CLOCK_MONOTONIC, &ts ) ) { @@ -111,6 +138,7 @@ namespace chrono } return time_point(duration( static_cast( ts.tv_sec ) * 1000000000 + ts.tv_nsec)); +#endif } #endif #endif