Re: [Boost-bugs] [Boost C++ Libraries] #9379: 'boost::chrono::steady_clock' has not been declared" on boost 1.55, hp-ux 11.23 IA, gcc 4.6

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #9379: 'boost::chrono::steady_clock' has not been declared" on boost 1.55, hp-ux 11.23 IA, gcc 4.6
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-01-25 14:19:14


#9379: 'boost::chrono::steady_clock' has not been declared" on boost 1.55, hp-ux
11.23 IA, gcc 4.6
-------------------------------+--------------------------
  Reporter: gengyonghui@… | Owner: viboes
      Type: Bugs | Status: reopened
 Milestone: To Be Determined | Component: chrono
   Version: Boost 1.55.0 | Severity: Problem
Resolution: | Keywords: steady_clock
-------------------------------+--------------------------

Comment (by 20313412@…):

 following code for chrono.hpp works fine!
 {{{


 #include <time.h> // for clock_gettime

 namespace boost
 {
 namespace chrono
 {

   system_clock::time_point system_clock::now() BOOST_NOEXCEPT
   {
     timespec ts;
     if ( ::clock_gettime( CLOCK_REALTIME, &ts ) )
     {
       BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
     }

     return time_point(duration(
       static_cast<system_clock::rep>( ts.tv_sec ) * 1000000000 +
 ts.tv_nsec));
   }

 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
   system_clock::time_point system_clock::now(system::error_code & ec)
   {
     timespec ts;
     if ( ::clock_gettime( CLOCK_REALTIME, &ts ) )
     {
         if (BOOST_CHRONO_IS_THROWS(ec))
         {
             boost::throw_exception(
                     system::system_error(
                             errno,
                             BOOST_CHRONO_SYSTEM_CATEGORY,
                             "chrono::system_clock" ));
         }
         else
         {
             ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY );
             return time_point();
         }
     }

     if (!BOOST_CHRONO_IS_THROWS(ec))
     {
         ec.clear();
     }
     return time_point(duration(
       static_cast<system_clock::rep>( ts.tv_sec ) * 1000000000 +
 ts.tv_nsec));
   }
 #endif

   std::time_t system_clock::to_time_t(const system_clock::time_point& t)
 BOOST_NOEXCEPT
   {
       return static_cast<std::time_t>( t.time_since_epoch().count() /
 1000000000 );
   }

   system_clock::time_point system_clock::from_time_t(std::time_t t)
 BOOST_NOEXCEPT
   {
       return time_point(duration(static_cast<system_clock::rep>(t) *
 1000000000));
   }

 #ifdef BOOST_CHRONO_HAS_CLOCK_STEADY

   steady_clock::time_point steady_clock::now() BOOST_NOEXCEPT
   {
 #ifdef BOOST_CHRONO_HAS_GETHRTIME
     hrtime_t hrt = gethrtime();
     BOOST_ASSERT(hrt>=0);
     return time_point(nanoseconds(hrt));
 #else
     timespec ts;
     if ( ::clock_gettime( CLOCK_MONOTONIC, &ts ) )
     {
       BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
     }

     return time_point(duration(
       static_cast<steady_clock::rep>( ts.tv_sec ) * 1000000000 +
 ts.tv_nsec));
 #endif
   }

 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
   steady_clock::time_point steady_clock::now(system::error_code & ec)
   {
 #ifdef BOOST_CHRONO_HAS_GETHRTIME
     hrtime_t hrt = gethrtime();
     if (hrt<0)
     {
         boost::throw_exception(
                 system::system_error(
                         EFAULT,
                         BOOST_CHRONO_SYSTEM_CATEGORY,
                         "chrono::steady_clock" ));
     }
     else
     {
         ec.assign( EFAULT, BOOST_CHRONO_SYSTEM_CATEGORY );
         return time_point();
     }
     if (!BOOST_CHRONO_IS_THROWS(ec))
     {
         ec.clear();
     }
     return time_point(nanoseconds(hrt));
 #else
     timespec ts;
     if ( ::clock_gettime( CLOCK_MONOTONIC, &ts ) )
     {
         if (BOOST_CHRONO_IS_THROWS(ec))
         {
             boost::throw_exception(
                     system::system_error(
                             errno,
                             BOOST_CHRONO_SYSTEM_CATEGORY,
                             "chrono::steady_clock" ));
         }
         else
         {
             ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY );
             return time_point();
         }
     }

     if (!BOOST_CHRONO_IS_THROWS(ec))
     {
         ec.clear();
     }
     return time_point(duration(
       static_cast<steady_clock::rep>( ts.tv_sec ) * 1000000000 +
 ts.tv_nsec));
 #endif
   }
 #endif
 #endif

 } // namespace chrono
 } // namespace boost




 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/9379#comment:21>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:17 UTC