diff options
author | Chanho Park <chanho61.park@samsung.com> | 2014-12-11 18:55:56 +0900 |
---|---|---|
committer | Chanho Park <chanho61.park@samsung.com> | 2014-12-11 18:55:56 +0900 |
commit | 08c1e93fa36a49f49325a07fe91ff92c964c2b6c (patch) | |
tree | 7a7053ceb8874b28ec4b868d4c49b500008a102e /boost/chrono/detail/inlined/mac | |
parent | bb4dd8289b351fae6b55e303f189127a394a1edd (diff) | |
download | boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.tar.gz boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.tar.bz2 boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.zip |
Imported Upstream version 1.57.0upstream/1.57.0
Diffstat (limited to 'boost/chrono/detail/inlined/mac')
-rw-r--r-- | boost/chrono/detail/inlined/mac/process_cpu_clocks.hpp | 43 | ||||
-rw-r--r-- | boost/chrono/detail/inlined/mac/thread_clock.hpp | 80 |
2 files changed, 112 insertions, 11 deletions
diff --git a/boost/chrono/detail/inlined/mac/process_cpu_clocks.hpp b/boost/chrono/detail/inlined/mac/process_cpu_clocks.hpp index 48753bdfc7..6d09e2cb3a 100644 --- a/boost/chrono/detail/inlined/mac/process_cpu_clocks.hpp +++ b/boost/chrono/detail/inlined/mac/process_cpu_clocks.hpp @@ -48,7 +48,7 @@ namespace boost process_real_cpu_clock::time_point process_real_cpu_clock::now() BOOST_NOEXCEPT { -#if 0 +#if 1 tms tm; clock_t c = ::times(&tm); if (c == clock_t(-1)) // error @@ -71,10 +71,18 @@ namespace boost if (c == clock_t(-1)) // error { BOOST_ASSERT(0 && "Boost::Chrono - Internal Error"); + } else + { + long factor = chrono_detail::tick_factor(); + if (factor != -1) + { + return time_point(nanoseconds(c * factor)); + } else + { + BOOST_ASSERT(0 && "Boost::Chrono - Internal Error"); + } } - return time_point( - duration(c*(1000000000l/CLOCKS_PER_SEC)) - ); + return time_point(); #endif } @@ -82,7 +90,7 @@ namespace boost process_real_cpu_clock::time_point process_real_cpu_clock::now(system::error_code & ec) { -#if 0 +#if 1 tms tm; clock_t c = ::times(&tm); if (c == clock_t(-1)) // error @@ -129,11 +137,28 @@ namespace boost ec.assign(errno, BOOST_CHRONO_SYSTEM_CATEGORY); return time_point(); } + } else + { + long factor = chrono_detail::tick_factor(); + if (factor != -1) + { + if (!BOOST_CHRONO_IS_THROWS(ec)) + { + ec.clear(); + } + return time_point(nanoseconds(c * factor)); + } else + { + if (BOOST_CHRONO_IS_THROWS(ec)) + { + boost::throw_exception(system::system_error(errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_real_cpu_clock")); + } else + { + ec.assign(errno, BOOST_CHRONO_SYSTEM_CATEGORY); + return time_point(); + } + } } - return time_point( - duration(c*(1000000000l/CLOCKS_PER_SEC)) - ); - #endif } diff --git a/boost/chrono/detail/inlined/mac/thread_clock.hpp b/boost/chrono/detail/inlined/mac/thread_clock.hpp index dad806e4e2..1a4406b83d 100644 --- a/boost/chrono/detail/inlined/mac/thread_clock.hpp +++ b/boost/chrono/detail/inlined/mac/thread_clock.hpp @@ -1,6 +1,8 @@ // boost thread_clock.cpp -----------------------------------------------------------// -// Copyright Vicente J. Botet Escriba 2010 +// Copyright Beman Dawes 1994, 2006, 2008 +// Copyright Vicente J. Botet Escriba 2009-2011 +// Copyright Christopher Brown 2013 // Distributed under the Boost Software License, Version 1.0. // See http://www.boost.org/LICENSE_1_0.txt @@ -10,6 +12,80 @@ //--------------------------------------------------------------------------------------// #include <boost/chrono/config.hpp> -#include <boost/chrono/detail/inlined/posix/thread_clock.hpp> +#include <boost/chrono/thread_clock.hpp> #include <cassert> +# include <pthread.h> +# include <mach/thread_act.h> + +namespace boost { namespace chrono { + + thread_clock::time_point thread_clock::now( ) BOOST_NOEXCEPT + { + // get the thread port (borrowing pthread's reference) + mach_port_t port = pthread_mach_thread_np(pthread_self()); + + // get the thread info + thread_basic_info_data_t info; + mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT; + if ( thread_info(port, THREAD_BASIC_INFO, (thread_info_t)&info, &count) != KERN_SUCCESS ) + { + BOOST_ASSERT(0 && "Boost::Chrono - Internal Error"); + return time_point(); + } + + // convert to nanoseconds + duration user = duration( + static_cast<thread_clock::rep>( info.user_time.seconds ) * 1000000000 + + static_cast<thread_clock::rep>(info.user_time.microseconds ) * 1000); + + duration system = duration( + static_cast<thread_clock::rep>( info.system_time.seconds ) * 1000000000 + + static_cast<thread_clock::rep>( info.system_time.microseconds ) * 1000); + + return time_point( user + system ); + } + +#if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING + thread_clock::time_point thread_clock::now( system::error_code & ec ) + { + // get the thread port (borrowing pthread's reference) + mach_port_t port = pthread_mach_thread_np(pthread_self()); + + // get the thread info + thread_basic_info_data_t info; + mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT; + if ( thread_info(port, THREAD_BASIC_INFO, (thread_info_t)&info, &count) != KERN_SUCCESS ) + { + if (BOOST_CHRONO_IS_THROWS(ec)) + { + boost::throw_exception( + system::system_error( + EINVAL, + BOOST_CHRONO_SYSTEM_CATEGORY, + "chrono::thread_clock" )); + } + else + { + ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY ); + return time_point(); + } + } + if (!BOOST_CHRONO_IS_THROWS(ec)) + { + ec.clear(); + } + + // convert to nanoseconds + duration user = duration( + static_cast<thread_clock::rep>( info.user_time.seconds ) * 1000000000 + + static_cast<thread_clock::rep>(info.user_time.microseconds ) * 1000); + + duration system = duration( + static_cast<thread_clock::rep>( info.system_time.seconds ) * 1000000000 + + static_cast<thread_clock::rep>( info.system_time.microseconds ) * 1000); + + return time_point( user + system ); + } +#endif +} } |