mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bmah...@apache.org
Subject svn commit: r1467841 - in /incubator/mesos/trunk/third_party/libprocess/third_party/stout: include/stout/os.hpp tests/os_tests.cpp
Date Mon, 15 Apr 2013 00:35:26 GMT
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 <yan@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)));
+}



Mime
View raw message