BVB Source Codes

mars Show thread_clock.hpp Source code

Return Download mars: download thread_clock.hpp Source code - Download mars Source code - Type:.hpp
  1. //  boost thread_clock.cpp  -----------------------------------------------------------//
  2.  
  3. //  Copyright Beman Dawes 1994, 2006, 2008
  4. //  Copyright Vicente J. Botet Escriba 2009-2011
  5. //  Copyright Christopher Brown 2013
  6.  
  7. //  Distributed under the Boost Software License, Version 1.0.
  8. //  See http://www.boost.org/LICENSE_1_0.txt
  9.  
  10. //  See http://www.boost.org/libs/chrono for documentation.
  11.  
  12. //--------------------------------------------------------------------------------------//
  13.  
  14. #include <boost/chrono/config.hpp>
  15. #include <boost/chrono/thread_clock.hpp>
  16. #include <cassert>
  17.  
  18. # include <pthread.h>
  19. # include <mach/thread_act.h>
  20.  
  21. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost { namespace chrono {
  22.  
  23.     thread_clock::time_point thread_clock::now( ) BOOST_NOEXCEPT
  24.     {
  25.         // get the thread port (borrowing pthread's reference)
  26.         mach_port_t port = pthread_mach_thread_np(pthread_self());
  27.  
  28.         // get the thread info
  29.         thread_basic_info_data_t info;
  30.         mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT;
  31.         if ( thread_info(port, THREAD_BASIC_INFO, (thread_info_t)&info, &count) != KERN_SUCCESS )
  32.         {
  33.             BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
  34.             return time_point();
  35.         }
  36.  
  37.         // convert to nanoseconds
  38.         duration user = duration(
  39.                 static_cast<thread_clock::rep>( info.user_time.seconds ) * 1000000000
  40.                         + static_cast<thread_clock::rep>(info.user_time.microseconds ) * 1000);
  41.  
  42.         duration system = duration(
  43.                 static_cast<thread_clock::rep>( info.system_time.seconds ) * 1000000000
  44.                         + static_cast<thread_clock::rep>( info.system_time.microseconds ) * 1000);
  45.  
  46.         return time_point( user + system );
  47.     }
  48.  
  49. #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
  50.     thread_clock::time_point thread_clock::now( system::error_code & ec )
  51.     {
  52.         // get the thread port (borrowing pthread's reference)
  53.         mach_port_t port = pthread_mach_thread_np(pthread_self());
  54.  
  55.         // get the thread info
  56.         thread_basic_info_data_t info;
  57.         mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT;
  58.         if ( thread_info(port, THREAD_BASIC_INFO, (thread_info_t)&info, &count) != KERN_SUCCESS )
  59.         {
  60.             if (BOOST_CHRONO_IS_THROWS(ec))
  61.             {
  62.                 mars_boost::throw_exception(
  63.                         system::system_error(
  64.                                 EINVAL,
  65.                                 BOOST_CHRONO_SYSTEM_CATEGORY,
  66.                                 "chrono::thread_clock" ));
  67.             }
  68.             else
  69.             {
  70.                 ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY );
  71.                 return time_point();
  72.             }
  73.         }
  74.         if (!BOOST_CHRONO_IS_THROWS(ec))
  75.         {
  76.             ec.clear();
  77.         }
  78.  
  79.         // convert to nanoseconds
  80.         duration user = duration(
  81.                 static_cast<thread_clock::rep>( info.user_time.seconds ) * 1000000000
  82.                         + static_cast<thread_clock::rep>(info.user_time.microseconds ) * 1000);
  83.  
  84.         duration system = duration(
  85.                 static_cast<thread_clock::rep>( info.system_time.seconds ) * 1000000000
  86.                         + static_cast<thread_clock::rep>( info.system_time.microseconds ) * 1000);
  87.  
  88.         return time_point( user + system );
  89.     }
  90. #endif
  91. } }
  92.  
downloadthread_clock.hpp Source code - Download mars Source code
Related Source Codes/Software:
Hero - Elegant transition library for iOS & tvOS 2017-06-09
deep-photo-styletransfer - Code and data for paper "Deep Photo Style Transfer... 2017-06-09
mastodon - A GNU Social-compatible microblogging server ... 2017-06-09
plyr - A simple HTML5, YouTube and Vimeo player ... 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
Public-APIs - 2017-06-09
lottie-ios - An iOS library to natively render After Effects ve... 2017-06-09
Awesome-Hacking - A collection of various awesome lists for hackers,... 2017-06-09
algorithms - Minimal examples of data structures and algorithms... 2017-06-10
lectures - Oxford Deep NLP 2017 course 2017-06-10
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top