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.  
  6. //  Distributed under the Boost Software License, Version 1.0.
  7. //  See http://www.boost.org/LICENSE_1_0.txt
  8.  
  9. //  See http://www.boost.org/libs/chrono for documentation.
  10.  
  11. //--------------------------------------------------------------------------------------//
  12.  
  13. #include <boost/chrono/config.hpp>
  14. #include <boost/chrono/thread_clock.hpp>
  15. #include <cassert>
  16.  
  17. #if !defined(__VXWORKS__)
  18. # include <sys/times.h>
  19. #endif
  20. # include <pthread.h>
  21. # include <unistd.h>
  22.  
  23. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost { namespace chrono {
  24.  
  25.     thread_clock::time_point thread_clock::now( ) BOOST_NOEXCEPT
  26.     {
  27.       struct timespec ts;
  28. #if defined CLOCK_THREAD_CPUTIME_ID
  29.         // get the timespec associated to the thread clock
  30.         if ( ::clock_gettime( CLOCK_THREAD_CPUTIME_ID, &ts ) )
  31. #else
  32.         // get the current thread
  33.         pthread_t pth=pthread_self();
  34.         // get the clock_id associated to the current thread
  35.         clockid_t clock_id;
  36.         pthread_getcpuclockid(pth, &clock_id);
  37.         // get the timespec associated to the thread clock
  38.         if ( ::clock_gettime( clock_id, &ts ) )
  39. #endif
  40.         {
  41.           BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
  42.         }
  43.  
  44.         // transform to nanoseconds
  45.         return time_point(duration(
  46.             static_cast<thread_clock::rep>( ts.tv_sec ) * 1000000000 + ts.tv_nsec));
  47.  
  48.     }
  49.  
  50. #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
  51.     thread_clock::time_point thread_clock::now( system::error_code & ec )
  52.     {
  53.       struct timespec ts;
  54. #if defined CLOCK_THREAD_CPUTIME_ID
  55.         // get the timespec associated to the thread clock
  56.         if ( ::clock_gettime( CLOCK_THREAD_CPUTIME_ID, &ts ) )
  57. #else
  58.         // get the current thread
  59.         pthread_t pth=pthread_self();
  60.         // get the clock_id associated to the current thread
  61.         clockid_t clock_id;
  62.         pthread_getcpuclockid(pth, &clock_id);
  63.         // get the timespec associated to the thread clock
  64.         if ( ::clock_gettime( clock_id, &ts ) )
  65. #endif
  66.         {
  67.             if (BOOST_CHRONO_IS_THROWS(ec))
  68.             {
  69.                 mars_boost::throw_exception(
  70.                         system::system_error(
  71.                                 errno,
  72.                                 BOOST_CHRONO_SYSTEM_CATEGORY,
  73.                                 "chrono::thread_clock" ));
  74.             }
  75.             else
  76.             {
  77.                 ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY );
  78.                 return time_point();
  79.             }
  80.         }
  81.         if (!BOOST_CHRONO_IS_THROWS(ec))
  82.         {
  83.             ec.clear();
  84.         }
  85.         // transform to nanoseconds
  86.         return time_point(duration(
  87.             static_cast<thread_clock::rep>( ts.tv_sec ) * 1000000000 + ts.tv_nsec));
  88.  
  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