Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/chrono/system_clocks.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //  boost/chrono/system_clocks.hpp  --------------------------------------------------------------//
0002 
0003 //  Copyright 2008 Howard Hinnant
0004 //  Copyright 2008 Beman Dawes
0005 //  Copyright 2009-2011 Vicente J. Botet Escriba
0006 
0007 //  Distributed under the Boost Software License, Version 1.0.
0008 //  See http://www.boost.org/LICENSE_1_0.txt
0009 
0010 /*
0011 
0012 This code was derived by Beman Dawes from Howard Hinnant's time2_demo prototype.
0013 Many thanks to Howard for making his code available under the Boost license.
0014 The original code was modified to conform to Boost conventions and to section
0015 20.9 Time utilities [time] of the C++ committee's working paper N2798.
0016 See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf.
0017 
0018 time2_demo contained this comment:
0019 
0020     Much thanks to Andrei Alexandrescu,
0021                    Walter Brown,
0022                    Peter Dimov,
0023                    Jeff Garland,
0024                    Terry Golubiewski,
0025                    Daniel Krugler,
0026                    Anthony Williams.
0027 */
0028 
0029 /*
0030 
0031 TODO:
0032 
0033   * Fully implement error handling, with test cases.
0034   * Consider issues raised by Michael Marcin:
0035 
0036     > In the past I've seen QueryPerformanceCounter give incorrect results,
0037     > especially with SpeedStep processors on laptops. This was many years ago and
0038     > might have been fixed by service packs and drivers.
0039     >
0040     > Typically you check the results of QPC against GetTickCount to see if the
0041     > results are reasonable.
0042     > http://support.microsoft.com/kb/274323
0043     >
0044     > I've also heard of problems with QueryPerformanceCounter in multi-processor
0045     > systems.
0046     >
0047     > I know some people SetThreadAffinityMask to 1 for the current thread call
0048     > their QueryPerformance* functions then restore SetThreadAffinityMask. This
0049     > seems horrible to me because it forces your program to jump to another
0050     > physical processor if it isn't already on cpu0 but they claim it worked well
0051     > in practice because they called the timing functions infrequently.
0052     >
0053     > In the past I have chosen to use timeGetTime with timeBeginPeriod(1) for
0054     > high resolution timers to avoid these issues.
0055 
0056 */
0057 
0058 #ifndef BOOST_CHRONO_SYSTEM_CLOCKS_HPP
0059 #define BOOST_CHRONO_SYSTEM_CLOCKS_HPP
0060 
0061 #include <boost/chrono/config.hpp>
0062 #include <boost/chrono/duration.hpp>
0063 #include <boost/chrono/time_point.hpp>
0064 #include <boost/chrono/detail/system.hpp>
0065 #include <boost/chrono/clock_string.hpp>
0066 #include <boost/ratio/config.hpp>
0067 
0068 #include <ctime>
0069 
0070 # if defined( BOOST_CHRONO_POSIX_API )
0071 #   if ! defined(CLOCK_REALTIME) && ! defined (__hpux__)
0072 #     error <time.h> does not supply CLOCK_REALTIME
0073 #   endif
0074 # endif
0075 
0076 #ifdef BOOST_CHRONO_WINDOWS_API
0077 // The system_clock tick is 100 nanoseconds
0078 # define BOOST_SYSTEM_CLOCK_DURATION boost::chrono::duration<boost::int_least64_t, ratio<BOOST_RATIO_INTMAX_C(1), BOOST_RATIO_INTMAX_C(10000000)> >
0079 #else
0080 # define BOOST_SYSTEM_CLOCK_DURATION boost::chrono::nanoseconds
0081 #endif
0082 
0083 // this must occur after all of the includes and before any code appears:
0084 #ifndef BOOST_CHRONO_HEADER_ONLY
0085 #include <boost/config/abi_prefix.hpp> // must be the last #include
0086 #endif
0087 
0088 
0089 //----------------------------------------------------------------------------//
0090 //                                                                            //
0091 //                        20.9 Time utilities [time]                          //
0092 //                                 synopsis                                   //
0093 //                                                                            //
0094 //----------------------------------------------------------------------------//
0095 
0096 namespace boost {
0097 namespace chrono {
0098 
0099   // Clocks
0100   class system_clock;
0101 #ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
0102   class steady_clock;
0103 #endif
0104 
0105 #ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
0106   typedef steady_clock high_resolution_clock;  // as permitted by [time.clock.hires]
0107 #else
0108   typedef system_clock high_resolution_clock;  // as permitted by [time.clock.hires]
0109 #endif
0110 
0111 //----------------------------------------------------------------------------//
0112 //                                                                            //
0113 //      20.9.5 Clocks [time.clock]                                            //
0114 //                                                                            //
0115 //----------------------------------------------------------------------------//
0116 
0117 // If you're porting, clocks are the system-specific (non-portable) part.
0118 // You'll need to know how to get the current time and implement that under now().
0119 // You'll need to know what units (tick period) and representation makes the most
0120 // sense for your clock and set those accordingly.
0121 // If you know how to map this clock to time_t (perhaps your clock is std::time, which
0122 // makes that trivial), then you can fill out system_clock's to_time_t() and from_time_t().
0123 
0124 //----------------------------------------------------------------------------//
0125 //      20.9.5.1 Class system_clock [time.clock.system]                       //
0126 //----------------------------------------------------------------------------//
0127 
0128   class BOOST_CHRONO_DECL system_clock
0129   {
0130   public:
0131       typedef BOOST_SYSTEM_CLOCK_DURATION          duration;
0132       typedef duration::rep                        rep;
0133       typedef duration::period                     period;
0134       typedef chrono::time_point<system_clock>     time_point;
0135       BOOST_STATIC_CONSTEXPR bool is_steady =             false;
0136 
0137       static BOOST_CHRONO_INLINE time_point  now() BOOST_NOEXCEPT;
0138 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
0139       static BOOST_CHRONO_INLINE time_point  now(system::error_code & ec);
0140 #endif
0141 
0142       static BOOST_CHRONO_INLINE std::time_t to_time_t(const time_point& t) BOOST_NOEXCEPT;
0143       static BOOST_CHRONO_INLINE time_point  from_time_t(std::time_t t) BOOST_NOEXCEPT;
0144   };
0145 
0146 //----------------------------------------------------------------------------//
0147 //      20.9.5.2 Class steady_clock [time.clock.steady]                 //
0148 //----------------------------------------------------------------------------//
0149 
0150 // As permitted  by [time.clock.steady]
0151 // The class steady_clock is conditionally supported.
0152 
0153 #ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
0154   class BOOST_CHRONO_DECL steady_clock
0155   {
0156   public:
0157       typedef nanoseconds                          duration;
0158       typedef duration::rep                        rep;
0159       typedef duration::period                     period;
0160       typedef chrono::time_point<steady_clock>  time_point;
0161       BOOST_STATIC_CONSTEXPR bool is_steady =             true;
0162 
0163       static BOOST_CHRONO_INLINE time_point  now() BOOST_NOEXCEPT;
0164 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
0165       static BOOST_CHRONO_INLINE time_point  now(system::error_code & ec);
0166 #endif
0167   };
0168 #endif
0169 //----------------------------------------------------------------------------//
0170 //      20.9.5.3 Class high_resolution_clock [time.clock.hires]               //
0171 //----------------------------------------------------------------------------//
0172 
0173 //  As permitted, steady_clock or system_clock is a typedef for high_resolution_clock.
0174 //  See synopsis.
0175 
0176 
0177   template<class CharT>
0178   struct clock_string<system_clock, CharT>
0179   {
0180     static std::basic_string<CharT> name()
0181     {
0182       static const CharT u[] =
0183       { 's', 'y', 's', 't', 'e', 'm', '_', 'c', 'l', 'o', 'c', 'k' };
0184       static const std::basic_string<CharT> str(u, u + sizeof(u)
0185           / sizeof(u[0]));
0186       return str;
0187     }
0188     static std::basic_string<CharT> since()
0189     {
0190       static const CharT
0191           u[] =
0192               { ' ', 's', 'i', 'n', 'c', 'e', ' ', 'J', 'a', 'n', ' ', '1', ',', ' ', '1', '9', '7', '0' };
0193       static const std::basic_string<CharT> str(u, u + sizeof(u)
0194           / sizeof(u[0]));
0195       return str;
0196     }
0197   };
0198 
0199 #ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
0200 
0201   template<class CharT>
0202   struct clock_string<steady_clock, CharT>
0203   {
0204     static std::basic_string<CharT> name()
0205     {
0206       static const CharT
0207           u[] =
0208               { 's', 't', 'e', 'a', 'd', 'y', '_', 'c', 'l', 'o', 'c', 'k' };
0209       static const std::basic_string<CharT> str(u, u + sizeof(u)
0210           / sizeof(u[0]));
0211       return str;
0212     }
0213     static std::basic_string<CharT> since()
0214     {
0215       const CharT u[] =
0216       { ' ', 's', 'i', 'n', 'c', 'e', ' ', 'b', 'o', 'o', 't' };
0217       const std::basic_string<CharT> str(u, u + sizeof(u) / sizeof(u[0]));
0218       return str;
0219     }
0220   };
0221 
0222 #endif
0223 
0224 } // namespace chrono
0225 } // namespace boost
0226 
0227 #ifndef BOOST_CHRONO_HEADER_ONLY
0228 // the suffix header occurs after all of our code:
0229 #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
0230 #else
0231 #include <boost/chrono/detail/inlined/chrono.hpp>
0232 #endif
0233 
0234 #endif // BOOST_CHRONO_SYSTEM_CLOCKS_HPP