Hiva::Time
- Hiva::BaseTime
The time base class implements the basic calculation interface. HivaTime, WallTime, and SteadyTime inherit BaseTime and support all calculation operations of BaseTime.
For details about the definition of the BaseDuration class, see Hiva::Duration.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
namespace Hiva { /* Base class for Time implementations. */ class BaseTime { public: BaseTime(); BaseTime(const uint32_t secVal, const uint32_t nsecVal); explicit BaseTime(const double doubleSec); virtual ~BaseTime() = default; double ToSec() const; bool FromSec(const double doubleSec); bool FromTimespec(const timespec &timeVal); uint64_t ToNSec() const; bool FromNSec(const uint64_t uint64Nsec); bool IsZero() const; BaseDuration operator-(const BaseTime &rhs) const; BaseTime operator+(const BaseDuration &rhs) const; BaseTime operator-(const BaseDuration &rhs) const; BaseTime &operator+=(const BaseDuration &rhs); BaseTime &operator-=(const BaseDuration &rhs); bool operator==(const BaseTime &rhs) const; bool operator!=(const BaseTime &rhs) const; bool operator<(const BaseTime &rhs) const; bool operator>(const BaseTime &rhs) const; bool operator<=(const BaseTime &rhs) const; bool operator>=(const BaseTime &rhs) const; uint32_t sec; uint32_t nsec; }; std::ostream &operator<<(std::ostream &outStream, const BaseTime &rhs); }
- Hiva::HivaTime
It inherits BaseTime and supports all calculation operations of BaseTime. When the simulation time is enabled, simulation time is used. When the simulation time is disabled, wall time is used.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
namespace Hiva { /* Time may either represent wall clock time or simulation time. */ class HivaTime : public BaseTime { public: HivaTime(); HivaTime(const uint32_t secVal, const uint32_t nsecVal) noexcept; explicit HivaTime(const double doubleSec) noexcept; HivaTime(const BaseTime &timeVal); ~HivaTime() override = default; static bool UseSystemTime(); static bool IsSimTime(); static bool IsSystemTime(); static HivaTime Now(); static void SetNow(const HivaTime &newSimTime); static void Init(); static void Shutdown(); static bool GetState(); static bool IsValid(); static bool WaitForValid(); static bool WaitForValid(const Hiva::WallDuration &timeout); static bool SleepUntil(const HivaTime &endTime); private: static bool stopped; static std::mutex simTimeMutex; static bool initialized; static bool useSimTime; static HivaTime simTime; }; }
- Hiva::WallTime
WallTime also refers to CLOCK_REALTIME. It inherits BaseTime and supports all calculation operations of BaseTime.
1 2 3 4 5 6 7 8 9 10 11 12 13
namespace Hiva { class WallTime : public BaseTime { public: WallTime(); WallTime(const uint32_t secVal, const uint32_t nsecVal); explicit WallTime(const double doubleSec); WallTime(const BaseTime &timeVal); ~WallTime() override = default; static WallTime Now(); static bool SleepUntil(const WallTime &endTime); static bool IsSystemTime(); }; }
- Hiva::SteadyTime
The monotonically increasing time also refers to CLOCK_MONOTONIC, which is not affected by time change. It inherits BaseTime and supports all calculation operations of BaseTime.
1 2 3 4 5 6 7 8 9 10 11 12 13
namespace Hiva { class SteadyTime : public BaseTime { public: SteadyTime(); SteadyTime(const uint32_t secVal, const uint32_t nsecVal); explicit SteadyTime(const double doubleSec); SteadyTime(const BaseTime &timeVal); ~SteadyTime() override = default; static SteadyTime Now(); static bool SleepUntil(const SteadyTime &endTime); static bool IsSystemTime(); }; }
Parent topic: OpenHiva FAQs