General Utility Library for C++14
2.12
|
Time-related functions.
Functions | |
std::chrono::steady_clock::time_point | gul14::tic () |
Return the current time as a std::chrono time_point. More... | |
template<class TimeUnitType = std::chrono::duration<double>> | |
auto | gul14::toc (std::chrono::steady_clock::time_point t0) |
Return the elapsed time in seconds (or a different unit) since the given time point. More... | |
template<class Rep , class Period > | |
bool | gul14::sleep (const std::chrono::duration< Rep, Period > &duration, const Trigger &trg) |
Sleep for at least the given time span, with the option of being woken up from another thread. More... | |
bool | gul14::sleep (double seconds, const Trigger &trg) |
Sleep for a given number of seconds, with the option of being woken up from another thread. More... | |
template<class Rep , class Period > | |
bool | gul14::sleep (const std::chrono::duration< Rep, Period > &duration) |
Sleep for a given time span. More... | |
bool | gul14::sleep (double seconds) |
Sleep for a given number of seconds. More... | |
bool gul14::sleep | ( | const std::chrono::duration< Rep, Period > & | duration | ) |
Sleep for a given time span.
This is equivalent to a call of std::this_thread::sleep_for(), which means that control is handed back to the operating system's task scheduler. This may result in a somewhat bigger effective delay than expected, especially where very small sleep times are requested and the system load is high.
Example:
duration | Time span to wait, as a std::chrono::duration type. |
bool gul14::sleep | ( | const std::chrono::duration< Rep, Period > & | duration, |
const Trigger & | trg | ||
) |
Sleep for at least the given time span, with the option of being woken up from another thread.
The sleep can be interrupted from another thread via a shared Trigger object.
Calling sleep() may lead to a context switch of the operation system. Under heavy load or resource contention, this can produce a delay that is longer than expected.
duration | Time span to wait, as a std::chrono::duration type. |
trg | Reference to a SleepInterrupt object that can be used to interrupt the delay. If such an interruption occurs, false is returned. |
References gul14::Trigger::wait_for().
Referenced by gul14::sleep().
|
inline |
Sleep for a given number of seconds.
This is equivalent to a call of std::this_thread::sleep_for(), which means that control is handed back to the operating system's task scheduler. This may result in a somewhat bigger effective delay than expected, especially where very small sleep times are requested and the system load is high.
Example:
seconds | Seconds to wait. |
References gul14::sleep().
|
inline |
Sleep for a given number of seconds, with the option of being woken up from another thread.
The sleep can be interrupted from another thread via a shared Trigger object.
Calling sleep() may lead to a context switch of the operation system. Under heavy load or resource contention, this can produce a delay that is longer than expected.
seconds | Seconds to wait. |
trg | Reference to a SleepInterrupt object that can be used to interrupt the delay. If such an interruption occurs, false is returned. |
References gul14::sleep().
|
inline |
Return the current time as a std::chrono time_point.
This function is intended to be used with the sister function toc() to measure elapsed time.
Referenced by gul14::toc().
auto gul14::toc | ( | std::chrono::steady_clock::time_point | t0 | ) |
Return the elapsed time in seconds (or a different unit) since the given time point.
This function is intended to be used with the sister function tic() to measure elapsed time. toc() is a function template that returns the elapsed seconds as a double value by default; by specifying a different chrono
type as a template parameter, it can also return other time units and other types.
TimeUnitType | The type to be used for calculating the elapsed time since t0. By default, this is std::chrono::duration<double>, which means that the elapsed time is returned as a double that represents seconds. |
t0 | A time point in the past that should be taken with tic(). |
References gul14::tic().