process_system_cpu_clock::time_point process_system_cpu_clock::now( system::error_code & ec) { // note that Windows uses 100 nanosecond ticks for FILETIME boost::detail::win32::FILETIME_ creation, exit, user_time, system_time; if ( boost::detail::win32::GetProcessTimes( boost::detail::win32::GetCurrentProcess(), &creation, &exit, &system_time, &user_time ) ) { if (!BOOST_CHRONO_IS_THROWS(ec)) { ec.clear(); } return time_point(duration( ((static_cast<process_system_cpu_clock::rep>(system_time.dwHighDateTime) << 32) | system_time.dwLowDateTime) * 100 )); } else { boost::detail::win32::DWORD_ cause = boost::detail::win32::GetLastError(); if (BOOST_CHRONO_IS_THROWS(ec)) { boost::throw_exception( system::system_error( cause, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_system_cpu_clock" )); } else { ec.assign( cause, BOOST_CHRONO_SYSTEM_CATEGORY ); 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 { if (BOOST_CHRONO_IS_THROWS(ec)) { pdalboost::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)) { pdalboost::throw_exception(system::system_error(errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_clock")); } else { ec.assign(errno, BOOST_CHRONO_SYSTEM_CATEGORY); return time_point(); } } } }
// never throws and set ec static time_point now(boost::system::error_code & ec) { if (BOOST_CHRONO_IS_THROWS(ec)) { boost::throw_exception( boost::system::system_error( errno_, BOOST_CHRONO_SYSTEM_CATEGORY, "errored_clock" ) ); } ec.assign( errno_, BOOST_CHRONO_SYSTEM_CATEGORY ); return time_point(); };
/** * Start the stopwatch. * * Effects: Assign the error code if any internal error occur while retrieving the current time. * Effects: Gives the elapsed time since start time to the LapCollector if no internal error occurs. * * Throws: Any exception that the LapCollector can Throw. * * Post-conditions: !is_running() if no error occur. */ void stop( system::error_code & ec ) { if (is_running()) { time_point tmp = clock::now(ec); if (!BOOST_CHRONO_IS_THROWS(ec) && ec) return; laps_collector_.store(tmp - start_); start_ = time_point(duration::zero()); running_ = false; } }
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)) { mars_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)) { mars_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(); } } } }
/** * Elapsed time getter for the current lap. * * Effects: Assign the error code if any internal error occur while retrieving the current time. * * Returns: the elapsed time since the start if no internal error occur. * */ duration elapsed_current_lap( system::error_code & ec ) const { if (is_running()) { time_point tmp = clock::now(ec); if (!BOOST_CHRONO_IS_THROWS(ec) && ec) return duration::zero(); return tmp - start_; } else { return duration::zero(); } }
/** * Restart the stopwatch. * * Effects: Assign the error code if any internal error occur while retrieving the current time. * Effects: As if stop(); start() were called, but ensuring that the start time is the same as the stop time. * * Post-conditions: is_running() if no error occur. */ void restart( system::error_code & ec ) { time_point tmp = clock::now(ec); if (!BOOST_CHRONO_IS_THROWS(ec) && ec) return; if (is_running()) { laps_collector_.store(tmp - start_); } else { running_ = true; } start_ = tmp; }