annotate DEPENDENCIES/generic/include/boost/chrono/detail/inlined/mac/thread_clock.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 // boost thread_clock.cpp -----------------------------------------------------------//
Chris@16 2
Chris@101 3 // Copyright Beman Dawes 1994, 2006, 2008
Chris@101 4 // Copyright Vicente J. Botet Escriba 2009-2011
Chris@101 5 // Copyright Christopher Brown 2013
Chris@16 6
Chris@16 7 // Distributed under the Boost Software License, Version 1.0.
Chris@16 8 // See http://www.boost.org/LICENSE_1_0.txt
Chris@16 9
Chris@16 10 // See http://www.boost.org/libs/chrono for documentation.
Chris@16 11
Chris@16 12 //--------------------------------------------------------------------------------------//
Chris@16 13
Chris@16 14 #include <boost/chrono/config.hpp>
Chris@101 15 #include <boost/chrono/thread_clock.hpp>
Chris@16 16 #include <cassert>
Chris@16 17
Chris@101 18 # include <pthread.h>
Chris@101 19 # include <mach/thread_act.h>
Chris@101 20
Chris@101 21 namespace boost { namespace chrono {
Chris@101 22
Chris@101 23 thread_clock::time_point thread_clock::now( ) BOOST_NOEXCEPT
Chris@101 24 {
Chris@101 25 // get the thread port (borrowing pthread's reference)
Chris@101 26 mach_port_t port = pthread_mach_thread_np(pthread_self());
Chris@101 27
Chris@101 28 // get the thread info
Chris@101 29 thread_basic_info_data_t info;
Chris@101 30 mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT;
Chris@101 31 if ( thread_info(port, THREAD_BASIC_INFO, (thread_info_t)&info, &count) != KERN_SUCCESS )
Chris@101 32 {
Chris@101 33 BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
Chris@101 34 return time_point();
Chris@101 35 }
Chris@101 36
Chris@101 37 // convert to nanoseconds
Chris@101 38 duration user = duration(
Chris@101 39 static_cast<thread_clock::rep>( info.user_time.seconds ) * 1000000000
Chris@101 40 + static_cast<thread_clock::rep>(info.user_time.microseconds ) * 1000);
Chris@101 41
Chris@101 42 duration system = duration(
Chris@101 43 static_cast<thread_clock::rep>( info.system_time.seconds ) * 1000000000
Chris@101 44 + static_cast<thread_clock::rep>( info.system_time.microseconds ) * 1000);
Chris@101 45
Chris@101 46 return time_point( user + system );
Chris@101 47 }
Chris@101 48
Chris@101 49 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
Chris@101 50 thread_clock::time_point thread_clock::now( system::error_code & ec )
Chris@101 51 {
Chris@101 52 // get the thread port (borrowing pthread's reference)
Chris@101 53 mach_port_t port = pthread_mach_thread_np(pthread_self());
Chris@101 54
Chris@101 55 // get the thread info
Chris@101 56 thread_basic_info_data_t info;
Chris@101 57 mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT;
Chris@101 58 if ( thread_info(port, THREAD_BASIC_INFO, (thread_info_t)&info, &count) != KERN_SUCCESS )
Chris@101 59 {
Chris@101 60 if (BOOST_CHRONO_IS_THROWS(ec))
Chris@101 61 {
Chris@101 62 boost::throw_exception(
Chris@101 63 system::system_error(
Chris@101 64 EINVAL,
Chris@101 65 BOOST_CHRONO_SYSTEM_CATEGORY,
Chris@101 66 "chrono::thread_clock" ));
Chris@101 67 }
Chris@101 68 else
Chris@101 69 {
Chris@101 70 ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY );
Chris@101 71 return time_point();
Chris@101 72 }
Chris@101 73 }
Chris@101 74 if (!BOOST_CHRONO_IS_THROWS(ec))
Chris@101 75 {
Chris@101 76 ec.clear();
Chris@101 77 }
Chris@101 78
Chris@101 79 // convert to nanoseconds
Chris@101 80 duration user = duration(
Chris@101 81 static_cast<thread_clock::rep>( info.user_time.seconds ) * 1000000000
Chris@101 82 + static_cast<thread_clock::rep>(info.user_time.microseconds ) * 1000);
Chris@101 83
Chris@101 84 duration system = duration(
Chris@101 85 static_cast<thread_clock::rep>( info.system_time.seconds ) * 1000000000
Chris@101 86 + static_cast<thread_clock::rep>( info.system_time.microseconds ) * 1000);
Chris@101 87
Chris@101 88 return time_point( user + system );
Chris@101 89 }
Chris@101 90 #endif
Chris@101 91 } }