changeset 23758c97c227 in /z/repo/m5
details: http://repo.m5sim.org/m5?cmd=changeset;node=23758c97c227
description:
        Time: Add setTick and getTick functions to the Time class.

diffstat:

 src/base/time.cc |  14 ++++++++++++++
 src/base/time.hh |  14 ++++++++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)

diffs (62 lines):

diff -r 4ebff121cc0e -r 23758c97c227 src/base/time.cc
--- a/src/base/time.cc  Wed Jan 19 11:48:00 2011 -0800
+++ b/src/base/time.cc  Wed Jan 19 16:22:15 2011 -0800
@@ -33,6 +33,7 @@
 
 #include "base/time.hh"
 #include "config/use_posix_clock.hh"
+#include "sim/core.hh"
 
 using namespace std;
 
@@ -48,6 +49,19 @@
 #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
 Time::date(const string &format) const
 {
diff -r 4ebff121cc0e -r 23758c97c227 src/base/time.hh
--- a/src/base/time.hh  Wed Jan 19 11:48:00 2011 -0800
+++ b/src/base/time.hh  Wed Jan 19 16:22:15 2011 -0800
@@ -42,6 +42,8 @@
 #include <iosfwd>
 #include <string>
 
+#include "base/types.hh"
+
 class Time
 {
   protected:
@@ -99,6 +101,18 @@
      */
     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 &
     operator=(const Time &other)
     {
_______________________________________________
m5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/m5-dev

Reply via email to