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 2013/04/15 02:35:26 UTC

svn commit: r1467841 - in /incubator/mesos/trunk/third_party/libprocess/third_party/stout: include/stout/os.hpp tests/os_tests.cpp

Author: bmahler
Date: Mon Apr 15 00:35:26 2013
New Revision: 1467841

URL: http://svn.apache.org/r1467841
Log:
Changed os::sleep() to take a Duration instead of a double.

From: Jiang Yan Xu <ya...@jxu.me>
Review: https://reviews.apache.org/r/10231

Modified:
    incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/os.hpp
    incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/os_tests.cpp

Modified: incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/os.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/os.hpp?rev=1467841&r1=1467840&r2=1467841&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/os.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/os.hpp Mon Apr 15 00:35:26 2013
@@ -37,6 +37,7 @@
 #include <sstream>
 #include <string>
 
+#include "duration.hpp"
 #include "error.hpp"
 #include "foreach.hpp"
 #include "none.hpp"
@@ -856,6 +857,26 @@ inline Try<int> shell(std::ostream* os, 
 }
 
 
+// Suspends execution for the given duration.
+inline Try<Nothing> sleep(const Duration& duration)
+{
+  timespec remaining;
+  remaining.tv_sec = static_cast<long>(duration.secs());
+  Duration nanos = Seconds(duration.secs() - remaining.tv_sec);
+  remaining.tv_nsec = static_cast<long>(nanos.ns());
+
+  while (nanosleep(&remaining, &remaining) == -1) {
+    if (errno == EINTR) {
+      continue;
+    } else {
+      return ErrnoError();
+    }
+  }
+
+  return Nothing();
+}
+
+
 // Creates a tar 'archive' with gzip compression, of the given 'path'.
 inline Try<Nothing> tar(const std::string& path, const std::string& archive)
 {

Modified: incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/os_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/os_tests.cpp?rev=1467841&r1=1467840&r2=1467841&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/os_tests.cpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/os_tests.cpp Mon Apr 15 00:35:26 2013
@@ -9,6 +9,7 @@
 #include <stout/gtest.hpp>
 #include <stout/hashset.hpp>
 #include <stout/os.hpp>
+#include <stout/stopwatch.hpp>
 #include <stout/try.hpp>
 #include <stout/uuid.hpp>
 
@@ -194,3 +195,14 @@ TEST_F(OsTest, release)
   ASSERT_SOME(info);
 }
 
+
+TEST_F(OsTest, sleep)
+{
+  Duration duration = Milliseconds(10);
+  Stopwatch stopwatch;
+  stopwatch.start();
+  ASSERT_SOME(os::sleep(duration));
+  ASSERT_LE(duration, stopwatch.elapsed());
+
+  ASSERT_ERROR(os::sleep(Milliseconds(-10)));
+}