You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2014/01/30 03:05:25 UTC

[4/6] git commit: Updated the semantics of Clock::resume.

Updated the semantics of Clock::resume.

Now Clock::resume results in the resumption of time from the state
of Time when resume is called, rather than re-winding time back to
real time.

This requires an update to Time::create to take into account the
advanced state of time.

Review: https://reviews.apache.org/r/17480


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/84b86ff3
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/84b86ff3
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/84b86ff3

Branch: refs/heads/master
Commit: 84b86ff3381c79b76dc620eca60b9250366e519a
Parents: 035d913
Author: Benjamin Mahler <bm...@twitter.com>
Authored: Tue Jan 28 18:49:36 2014 -0800
Committer: Benjamin Mahler <bm...@twitter.com>
Committed: Wed Jan 29 17:12:28 2014 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/include/process/time.hpp | 10 +---------
 3rdparty/libprocess/src/process.cpp          | 18 +++++++++++++++++-
 2 files changed, 18 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/84b86ff3/3rdparty/libprocess/include/process/time.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/time.hpp b/3rdparty/libprocess/include/process/time.hpp
index 307fd2c..26cec3d 100644
--- a/3rdparty/libprocess/include/process/time.hpp
+++ b/3rdparty/libprocess/include/process/time.hpp
@@ -21,15 +21,7 @@ public:
   static Time EPOCH;
   static Time MAX;
 
-  static Try<Time> create(double secs)
-  {
-    Try<Duration> duration = Duration::create(secs);
-    if (duration.isSome()) {
-      return Time(duration.get());
-    } else {
-      return Error("Argument too large for Time: " + duration.error());
-    }
-  }
+  static Try<Time> create(double seconds);
 
   Duration duration() const { return sinceEpoch; }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/84b86ff3/3rdparty/libprocess/src/process.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/process.cpp b/3rdparty/libprocess/src/process.cpp
index 7d8f00f..1083a35 100644
--- a/3rdparty/libprocess/src/process.cpp
+++ b/3rdparty/libprocess/src/process.cpp
@@ -605,6 +605,8 @@ map<ProcessBase*, Time>* currents = new map<ProcessBase*, Time>();
 Time initial = Time::EPOCH;
 Time current = Time::EPOCH;
 
+Duration advanced = Duration::zero();
+
 bool paused = false;
 
 } // namespace clock {
@@ -640,7 +642,7 @@ Time Clock::now(ProcessBase* process)
 
   // TODO(benh): Versus ev_now()?
   double d = ev_time();
-  Try<Time> time = Time::create(d);
+  Try<Time> time = Time::create(d); // Compensates for clock::advanced.
 
   // TODO(xujyan): Move CHECK_SOME to libprocess and add CHECK_SOME
   // here.
@@ -696,6 +698,7 @@ void Clock::advance(const Duration& duration)
 {
   synchronized (timeouts) {
     if (clock::paused) {
+      clock::advanced += duration;
       clock::current += duration;
       VLOG(2) << "Clock advanced ("  << duration << ") to " << clock::current;
       if (!update_timer) {
@@ -726,6 +729,7 @@ void Clock::update(const Time& time)
   synchronized (timeouts) {
     if (clock::paused) {
       if (clock::current < time) {
+        clock::advanced += (time - clock::current);
         clock::current = Time(time);
         VLOG(2) << "Clock updated to " << clock::current;
         if (!update_timer) {
@@ -764,6 +768,18 @@ void Clock::settle()
 }
 
 
+Try<Time> Time::create(double seconds)
+{
+  Try<Duration> duration = Duration::create(seconds);
+  if (duration.isSome()) {
+    // In production code, clock::advanced will always be zero!
+    return Time(duration.get() + clock::advanced);
+  } else {
+    return Error("Argument too large for Time: " + duration.error());
+  }
+}
+
+
 static Message* encode(const UPID& from,
                        const UPID& to,
                        const string& name,