BVB Source Codes

mars Show chrono.hpp Source code

Return Download mars: download chrono.hpp Source code - Download mars Source code - Type:.hpp
  1. //  win/chrono.cpp  --------------------------------------------------------------//
  2.  
  3. //  Copyright Beman Dawes 2008
  4. //  Copyright 2009-2010 Vicente J. Botet Escriba
  5.  
  6. //  Distributed under the Boost Software License, Version 1.0.
  7. //  See http://www.boost.org/LICENSE_1_0.txt
  8.  
  9. //----------------------------------------------------------------------------//
  10. //                                Windows                                     //
  11. //----------------------------------------------------------------------------//
  12. #ifndef BOOST_CHRONO_DETAIL_INLINED_WIN_CHRONO_HPP
  13. #define BOOST_CHRONO_DETAIL_INLINED_WIN_CHRONO_HPP
  14.  
  15. #include <boost/detail/winapi/time.hpp>
  16. #include <boost/detail/winapi/timers.hpp>
  17. #include <boost/detail/winapi/GetLastError.hpp>
  18.  
  19. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost
  20. {
  21. namespace chrono
  22. {
  23. namespace chrono_detail
  24. {
  25.  
  26.   BOOST_CHRONO_INLINE double get_nanosecs_per_tic() BOOST_NOEXCEPT
  27.   {
  28.       mars_boost::detail::winapi::LARGE_INTEGER_ freq;
  29.       if ( !mars_boost::detail::winapi::QueryPerformanceFrequency( &freq ) )
  30.           return 0.0L;
  31.       return double(1000000000.0L / freq.QuadPart);
  32.   }
  33.  
  34. }
  35.  
  36.   steady_clock::time_point steady_clock::now() BOOST_NOEXCEPT
  37.   {
  38.     double nanosecs_per_tic = chrono_detail::get_nanosecs_per_tic();
  39.  
  40.     mars_boost::detail::winapi::LARGE_INTEGER_ pcount;
  41.     if ( nanosecs_per_tic <= 0.0L )
  42.     {
  43.       BOOST_ASSERT(0 && "Boost::Chrono - get_nanosecs_per_tic Internal Error");
  44.       return steady_clock::time_point();
  45.     }
  46.     unsigned times=0;
  47.     while ( ! mars_boost::detail::winapi::QueryPerformanceCounter( &pcount ) )
  48.     {
  49.       if ( ++times > 3 )
  50.       {
  51.         BOOST_ASSERT(0 && "Boost::Chrono - QueryPerformanceCounter Internal Error");
  52.         return steady_clock::time_point();
  53.       }
  54.     }
  55.  
  56.     return steady_clock::time_point(steady_clock::duration(
  57.       static_cast<steady_clock::rep>((nanosecs_per_tic) * pcount.QuadPart)));
  58.   }
  59.  
  60.  
  61. #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
  62.   steady_clock::time_point steady_clock::now( system::error_code & ec )
  63.   {
  64.     double nanosecs_per_tic = chrono_detail::get_nanosecs_per_tic();
  65.  
  66.     mars_boost::detail::winapi::LARGE_INTEGER_ pcount;
  67.     if ( (nanosecs_per_tic <= 0.0L)
  68.             || (!mars_boost::detail::winapi::QueryPerformanceCounter( &pcount )) )
  69.     {
  70.         mars_boost::detail::winapi::DWORD_ cause =
  71.             ((nanosecs_per_tic <= 0.0L)
  72.                     ? ERROR_NOT_SUPPORTED
  73.                     : mars_boost::detail::winapi::GetLastError());
  74.         if (BOOST_CHRONO_IS_THROWS(ec)) {
  75.             mars_boost::throw_exception(
  76.                     system::system_error(
  77.                             cause,
  78.                             BOOST_CHRONO_SYSTEM_CATEGORY,
  79.                             "chrono::steady_clock" ));
  80.         }
  81.         else
  82.         {
  83.             ec.assign( cause, BOOST_CHRONO_SYSTEM_CATEGORY );
  84.             return steady_clock::time_point(duration(0));
  85.         }
  86.     }
  87.  
  88.     if (!BOOST_CHRONO_IS_THROWS(ec))
  89.     {
  90.         ec.clear();
  91.     }
  92.     return time_point(duration(
  93.       static_cast<steady_clock::rep>(nanosecs_per_tic * pcount.QuadPart)));
  94.   }
  95. #endif
  96.  
  97.   BOOST_CHRONO_INLINE
  98.   system_clock::time_point system_clock::now() BOOST_NOEXCEPT
  99.   {
  100.     mars_boost::detail::winapi::FILETIME_ ft;
  101.     mars_boost::detail::winapi::GetSystemTimeAsFileTime( &ft );  // never fails
  102.     return system_clock::time_point(
  103.       system_clock::duration(
  104.         ((static_cast<__int64>( ft.dwHighDateTime ) << 32) | ft.dwLowDateTime)
  105.        - 116444736000000000LL
  106.        //- (134775LL*864000000000LL)
  107.       )
  108.     );
  109.   }
  110.  
  111. #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
  112.   BOOST_CHRONO_INLINE
  113.   system_clock::time_point system_clock::now( system::error_code & ec )
  114.   {
  115.     mars_boost::detail::winapi::FILETIME_ ft;
  116.     mars_boost::detail::winapi::GetSystemTimeAsFileTime( &ft );  // never fails
  117.     if (!BOOST_CHRONO_IS_THROWS(ec))
  118.     {
  119.         ec.clear();
  120.     }
  121.     return system_clock::time_point(
  122.       system_clock::duration(
  123.        ((static_cast<__int64>( ft.dwHighDateTime ) << 32) | ft.dwLowDateTime)
  124.        - 116444736000000000LL
  125.        //- (134775LL*864000000000LL)
  126.        ));
  127.   }
  128. #endif
  129.  
  130.   BOOST_CHRONO_INLINE
  131.   std::time_t system_clock::to_time_t(const system_clock::time_point& t) BOOST_NOEXCEPT
  132.   {
  133.       __int64 temp = t.time_since_epoch().count();
  134.       temp /= 10000000;
  135.       return static_cast<std::time_t>( temp );
  136.   }
  137.  
  138.   BOOST_CHRONO_INLINE
  139.   system_clock::time_point system_clock::from_time_t(std::time_t t) BOOST_NOEXCEPT
  140.   {
  141.       __int64 temp = t;
  142.       temp *= 10000000;
  143.       return time_point(duration(temp));
  144.   }
  145.  
  146. }  // namespace chrono
  147. }  // namespace mars_boost
  148.  
  149. #endif
  150.  
downloadchrono.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