Time: Add setTick and getTick functions to the Time class.
This commit is contained in:
parent
a368fba7d4
commit
23bab6783b
2 changed files with 28 additions and 0 deletions
|
@ -33,6 +33,7 @@
|
||||||
|
|
||||||
#include "base/time.hh"
|
#include "base/time.hh"
|
||||||
#include "config/use_posix_clock.hh"
|
#include "config/use_posix_clock.hh"
|
||||||
|
#include "sim/core.hh"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -48,6 +49,19 @@ Time::_set(bool monotonic)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Time::setTick(Tick ticks)
|
||||||
|
{
|
||||||
|
uint64_t nsecs = ticks / SimClock::Int::ns;
|
||||||
|
set(nsecs / NSEC_PER_SEC, nsecs % NSEC_PER_SEC);
|
||||||
|
}
|
||||||
|
|
||||||
|
Tick
|
||||||
|
Time::getTick() const
|
||||||
|
{
|
||||||
|
return (nsec() + sec() * NSEC_PER_SEC) * SimClock::Int::ns;
|
||||||
|
}
|
||||||
|
|
||||||
string
|
string
|
||||||
Time::date(const string &format) const
|
Time::date(const string &format) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,6 +42,8 @@
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "base/types.hh"
|
||||||
|
|
||||||
class Time
|
class Time
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
@ -99,6 +101,18 @@ class Time
|
||||||
*/
|
*/
|
||||||
void set(time_t _sec, long _nsec) { sec(_sec); nsec(_nsec); }
|
void set(time_t _sec, long _nsec) { sec(_sec); nsec(_nsec); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the current time from a value measured in Ticks
|
||||||
|
* @param ticks Number of ticks to convert into a time.
|
||||||
|
*/
|
||||||
|
void setTick(Tick ticks);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current time from a value measured in Ticks
|
||||||
|
* @return Time value measured in Ticks.
|
||||||
|
*/
|
||||||
|
Tick getTick() const;
|
||||||
|
|
||||||
const Time &
|
const Time &
|
||||||
operator=(const Time &other)
|
operator=(const Time &other)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue