Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74595 - trunk/boost/chrono/detail/inlined/mac
From: vicente.botet_at_[hidden]
Date: 2011-09-27 19:05:17


Author: viboes
Date: 2011-09-27 19:05:15 EDT (Tue, 27 Sep 2011)
New Revision: 74595
URL: http://svn.boost.org/trac/boost/changeset/74595

Log:
Chrono: factor uses of tick_factor()
Text files modified:
   trunk/boost/chrono/detail/inlined/mac/process_cpu_clocks.hpp | 471 +++++++++++++++++----------------------
   1 files changed, 208 insertions(+), 263 deletions(-)

Modified: trunk/boost/chrono/detail/inlined/mac/process_cpu_clocks.hpp
==============================================================================
--- trunk/boost/chrono/detail/inlined/mac/process_cpu_clocks.hpp (original)
+++ trunk/boost/chrono/detail/inlined/mac/process_cpu_clocks.hpp 2011-09-27 19:05:15 EDT (Tue, 27 Sep 2011)
@@ -18,329 +18,274 @@
 #include <sys/times.h> //for times
 # include <unistd.h>
 
-
-namespace boost { namespace chrono {
-namespace chrono_detail {
-
- inline long tick_factor() // multiplier to convert ticks
- // to nanoseconds; -1 if unknown
+namespace boost
+{
+ namespace chrono
+ {
+ namespace chrono_detail
     {
+
+ inline long tick_factor() // multiplier to convert ticks
+ // to nanoseconds; -1 if unknown
+ {
         static long factor = 0;
- if ( !factor )
+ if (!factor)
         {
- if ( (factor = ::sysconf( _SC_CLK_TCK )) <= 0 )
- factor = -1;
- else
- {
- BOOST_ASSERT( factor <= 1000000l ); // doesn't handle large ticks
- factor = 1000000000l / factor; // compute factor
- if ( !factor ) factor = -1;
- }
+ if ((factor = ::sysconf(_SC_CLK_TCK)) <= 0)
+ factor = -1;
+ else
+ {
+ BOOST_ASSERT(factor <= 1000000000l); // doesn't handle large ticks
+ factor = 1000000000l / factor; // compute factor
+ if (!factor)
+ factor = -1;
+ }
         }
         return factor;
+ }
     }
-}
 
-process_real_cpu_clock::time_point process_real_cpu_clock::now() BOOST_CHRONO_NOEXCEPT
-{
-
- tms tm;
- clock_t c = ::times( &tm );
- if ( c == clock_t(-1) ) // error
- {
- BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
- }
- else
+ process_real_cpu_clock::time_point process_real_cpu_clock::now() BOOST_CHRONO_NOEXCEPT
     {
- if ( chrono_detail::tick_factor() != -1 )
+
+ tms tm;
+ clock_t c = ::times(&tm);
+ if (c == clock_t(-1)) // error
+ {
+ BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
+ } else
+ {
+ long factor = chrono_detail::tick_factor();
+ if (factor != -1)
         {
- return time_point(
- nanoseconds(c*chrono_detail::tick_factor()));
- }
- else
+ return time_point(nanoseconds(c * factor));
+ } else
         {
           BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
         }
+ }
+ return time_point();
     }
- return time_point();
-}
 
-process_real_cpu_clock::time_point process_real_cpu_clock::now(
- system::error_code & ec)
-{
-
- tms tm;
- clock_t c = ::times( &tm );
- if ( c == clock_t(-1) ) // error
+ process_real_cpu_clock::time_point process_real_cpu_clock::now(system::error_code & ec)
     {
+
+ tms tm;
+ clock_t c = ::times(&tm);
+ if (c == clock_t(-1)) // error
+ {
         if (BOOST_CHRONO_IS_THROWS(ec))
         {
- boost::throw_exception(
- system::system_error(
- errno,
- BOOST_CHRONO_SYSTEM_CATEGORY,
- "chrono::process_real_cpu_clock" ));
- }
- else
+ boost::throw_exception(system::system_error(errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_real_cpu_clock"));
+ } else
         {
- ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY );
- return time_point();
+ ec.assign(errno, BOOST_CHRONO_SYSTEM_CATEGORY);
+ return time_point();
         }
- }
- else
- {
- if ( chrono_detail::tick_factor() != -1 )
- {
- if (!BOOST_CHRONO_IS_THROWS(ec))
- {
- ec.clear();
- }
- return time_point(
- nanoseconds(c*chrono_detail::tick_factor()));
- }
- else
- {
- if (BOOST_CHRONO_IS_THROWS(ec))
- {
- boost::throw_exception(
- system::system_error(
- errno,
- BOOST_CHRONO_SYSTEM_CATEGORY,
- "chrono::process_real_cpu_clock" ));
- }
- else
- {
- ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY );
- return time_point();
- }
+ } else
+ {
+ long factor = chrono_detail::tick_factor();
+ if (factor != -1)
+ {
+ if (!BOOST_CHRONO_IS_THROWS(ec))
+ {
+ ec.clear();
+ }
+ return time_point(nanoseconds(c * factor));
+ } else
+ {
+ if (BOOST_CHRONO_IS_THROWS(ec))
+ {
+ boost::throw_exception(system::system_error(errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_real_cpu_clock"));
+ } else
+ {
+ ec.assign(errno, BOOST_CHRONO_SYSTEM_CATEGORY);
+ return time_point();
+ }
         }
+ }
     }
-}
-
 
-process_user_cpu_clock::time_point process_user_cpu_clock::now(
- system::error_code & ec)
-{
- tms tm;
- clock_t c = ::times( &tm );
- if ( c == clock_t(-1) ) // error
+ process_user_cpu_clock::time_point process_user_cpu_clock::now(system::error_code & ec)
     {
+ tms tm;
+ clock_t c = ::times(&tm);
+ if (c == clock_t(-1)) // error
+ {
         if (BOOST_CHRONO_IS_THROWS(ec))
         {
- boost::throw_exception(
- system::system_error(
- errno,
- BOOST_CHRONO_SYSTEM_CATEGORY,
- "chrono::process_user_cpu_clock" ));
- }
- else
+ boost::throw_exception(system::system_error(errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_user_cpu_clock"));
+ } else
         {
- ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY );
- return time_point();
+ ec.assign(errno, BOOST_CHRONO_SYSTEM_CATEGORY);
+ return time_point();
         }
- }
- else
- {
- if ( chrono_detail::tick_factor() != -1 )
- {
- if (!BOOST_CHRONO_IS_THROWS(ec))
- {
- ec.clear();
- }
- return time_point(
- nanoseconds((tm.tms_utime + tm.tms_cutime)*chrono_detail::tick_factor()));
- }
- else
- {
- if (BOOST_CHRONO_IS_THROWS(ec))
- {
- boost::throw_exception(
- system::system_error(
- errno,
- BOOST_CHRONO_SYSTEM_CATEGORY,
- "chrono::process_user_cpu_clock" ));
- }
- else
- {
- ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY );
- return time_point();
- }
+ } else
+ {
+ long factor = chrono_detail::tick_factor();
+ if (factor != -1)
+ {
+ if (!BOOST_CHRONO_IS_THROWS(ec))
+ {
+ ec.clear();
+ }
+ return time_point(nanoseconds((tm.tms_utime + tm.tms_cutime) * factor));
+ } else
+ {
+ if (BOOST_CHRONO_IS_THROWS(ec))
+ {
+ boost::throw_exception(system::system_error(errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_user_cpu_clock"));
+ } else
+ {
+ ec.assign(errno, BOOST_CHRONO_SYSTEM_CATEGORY);
+ return time_point();
+ }
         }
+ }
     }
-}
 
-process_user_cpu_clock::time_point process_user_cpu_clock::now() BOOST_CHRONO_NOEXCEPT
-{
- tms tm;
- clock_t c = ::times( &tm );
- if ( c == clock_t(-1) ) // error
- {
- BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
- }
- else
+ process_user_cpu_clock::time_point process_user_cpu_clock::now() BOOST_CHRONO_NOEXCEPT
     {
- if ( chrono_detail::tick_factor() != -1 )
- {
- return time_point(
- nanoseconds((tm.tms_utime + tm.tms_cutime)*chrono_detail::tick_factor()));
- }
- else
+ tms tm;
+ clock_t c = ::times(&tm);
+ if (c == clock_t(-1)) // error
+ {
+ BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
+ } else
+ {
+ long factor = chrono_detail::tick_factor();
+ if (factor != -1)
+ {
+ return time_point(nanoseconds((tm.tms_utime + tm.tms_cutime)
+ * factor));
+ } else
         {
           BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
         }
+ }
+ return time_point();
     }
- return time_point();
-}
-process_system_cpu_clock::time_point process_system_cpu_clock::now() BOOST_CHRONO_NOEXCEPT
-{
- tms tm;
- clock_t c = ::times( &tm );
- if ( c == clock_t(-1) ) // error
- {
- BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
- }
- else
+ process_system_cpu_clock::time_point process_system_cpu_clock::now() BOOST_CHRONO_NOEXCEPT
     {
- if ( chrono_detail::tick_factor() != -1 )
- {
- return time_point(
- nanoseconds((tm.tms_stime + tm.tms_cstime)*chrono_detail::tick_factor()));
- }
- else
+ tms tm;
+ clock_t c = ::times(&tm);
+ if (c == clock_t(-1)) // error
+ {
+ BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
+ } else
+ {
+ long factor = chrono_detail::tick_factor();
+ if (factor != -1)
+ {
+ return time_point(nanoseconds((tm.tms_stime + tm.tms_cstime)
+ * factor));
+ } else
         {
           BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
         }
+ }
+ return time_point();
     }
-return time_point();
-}
 
-process_system_cpu_clock::time_point process_system_cpu_clock::now(
- system::error_code & ec)
-{
- tms tm;
- clock_t c = ::times( &tm );
- if ( c == clock_t(-1) ) // error
+ process_system_cpu_clock::time_point process_system_cpu_clock::now(system::error_code & ec)
     {
+ tms tm;
+ clock_t c = ::times(&tm);
+ if (c == clock_t(-1)) // error
+ {
         if (BOOST_CHRONO_IS_THROWS(ec))
         {
- boost::throw_exception(
- system::system_error(
- errno,
- BOOST_CHRONO_SYSTEM_CATEGORY,
- "chrono::process_system_cpu_clock" ));
- }
- else
+ boost::throw_exception(system::system_error(errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_system_cpu_clock"));
+ } else
         {
- ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY );
- return time_point();
+ ec.assign(errno, BOOST_CHRONO_SYSTEM_CATEGORY);
+ return time_point();
         }
- }
- else
- {
- if ( chrono_detail::tick_factor() != -1 )
- {
- if (!BOOST_CHRONO_IS_THROWS(ec))
- {
- ec.clear();
- }
- return time_point(
- nanoseconds((tm.tms_stime + tm.tms_cstime)*chrono_detail::tick_factor()));
- }
- else
- {
- if (BOOST_CHRONO_IS_THROWS(ec))
- {
- boost::throw_exception(
- system::system_error(
- errno,
- BOOST_CHRONO_SYSTEM_CATEGORY,
- "chrono::process_system_cpu_clock" ));
- }
- else
- {
- ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY );
- return time_point();
- }
+ } else
+ {
+ long factor = chrono_detail::tick_factor();
+ if (factor != -1)
+ {
+ if (!BOOST_CHRONO_IS_THROWS(ec))
+ {
+ ec.clear();
+ }
+ return time_point(nanoseconds((tm.tms_stime + tm.tms_cstime) * factor));
+ } else
+ {
+ if (BOOST_CHRONO_IS_THROWS(ec))
+ {
+ boost::throw_exception(system::system_error(errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_system_cpu_clock"));
+ } else
+ {
+ ec.assign(errno, BOOST_CHRONO_SYSTEM_CATEGORY);
+ return time_point();
+ }
         }
+ }
     }
-}
 
-process_cpu_clock::time_point process_cpu_clock::now() BOOST_CHRONO_NOEXCEPT
-{
- tms tm;
- clock_t c = ::times( &tm );
- if ( c == clock_t(-1) ) // error
+ process_cpu_clock::time_point process_cpu_clock::now() BOOST_CHRONO_NOEXCEPT
     {
- BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
- }
- else
- {
- if ( chrono_detail::tick_factor() != -1 )
- {
- time_point::rep r(
- c*chrono_detail::tick_factor(),
- (tm.tms_utime + tm.tms_cutime)*chrono_detail::tick_factor(),
- (tm.tms_stime + tm.tms_cstime)*chrono_detail::tick_factor());
- return time_point(duration(r));
- }
- else
+ tms tm;
+ clock_t c = ::times(&tm);
+ if (c == clock_t(-1)) // error
+ {
+ BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
+ } else
+ {
+ long factor = chrono_detail::tick_factor();
+ if (factor != -1)
+ {
+ time_point::rep
+ r(c * factor, (tm.tms_utime + tm.tms_cutime) * factor, (tm.tms_stime
+ + tm.tms_cstime) * factor);
+ return time_point(duration(r));
+ } else
         {
           BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
         }
+ }
+ return time_point();
     }
- return time_point();
-}
-
-process_cpu_clock::time_point process_cpu_clock::now(
- system::error_code & ec )
-{
 
- tms tm;
- clock_t c = ::times( &tm );
- if ( c == clock_t(-1) ) // error
+ process_cpu_clock::time_point process_cpu_clock::now(system::error_code & ec)
     {
+
+ tms tm;
+ clock_t c = ::times(&tm);
+ if (c == clock_t(-1)) // error
+ {
         if (BOOST_CHRONO_IS_THROWS(ec))
         {
- boost::throw_exception(
- system::system_error(
- errno,
- BOOST_CHRONO_SYSTEM_CATEGORY,
- "chrono::process_clock" ));
- }
- else
+ boost::throw_exception(system::system_error(errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_clock"));
+ } else
         {
- ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY );
- return time_point();
+ ec.assign(errno, BOOST_CHRONO_SYSTEM_CATEGORY);
+ return time_point();
         }
- }
- else
- {
- if ( chrono_detail::tick_factor() != -1 )
- {
- time_point::rep r(
- c*chrono_detail::tick_factor(),
- (tm.tms_utime + tm.tms_cutime)*chrono_detail::tick_factor(),
- (tm.tms_stime + tm.tms_cstime)*chrono_detail::tick_factor());
- return time_point(duration(r));
- }
- else
- {
- if (BOOST_CHRONO_IS_THROWS(ec))
- {
- boost::throw_exception(
- system::system_error(
- errno,
- BOOST_CHRONO_SYSTEM_CATEGORY,
- "chrono::process_clock" ));
- }
- else
- {
- ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY );
- return time_point();
- }
+ } else
+ {
+ long factor = chrono_detail::tick_factor();
+ if (factor != -1)
+ {
+ time_point::rep
+ r(c * factor, (tm.tms_utime + tm.tms_cutime) * factor, (tm.tms_stime
+ + tm.tms_cstime) * factor);
+ return time_point(duration(r));
+ } else
+ {
+ if (BOOST_CHRONO_IS_THROWS(ec))
+ {
+ boost::throw_exception(system::system_error(errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_clock"));
+ } else
+ {
+ ec.assign(errno, BOOST_CHRONO_SYSTEM_CATEGORY);
+ return time_point();
+ }
         }
+ }
+
     }
-
-}
-}
+ }
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk