Index: base/cpp101/sleep.cc |
diff --git a/base/cpp101/sleep.cc b/base/cpp101/sleep.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ad2f29cc5c0b06606bc058d0978cd51c2ca86cea |
--- /dev/null |
+++ b/base/cpp101/sleep.cc |
@@ -0,0 +1,40 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include <stdio.h> |
+ |
+#include "base/at_exit.h" |
+#include "base/location.h" |
+#include "base/message_loop/message_loop.h" |
+#include "base/run_loop.h" |
+#include "base/strings/string_number_conversions.h" |
+#include "base/time/time.h" |
+ |
+int main(int argc, char* argv[]) { |
+ base::AtExitManager exit_manager; |
+ |
+ if (argc <= 1) { |
+ printf("%s: missing operand\n", argv[0]); |
+ return -1; |
+ } |
+ |
+ int duration_seconds = 0; |
+ if (!base::StringToInt(argv[1], &duration_seconds) || |
+ duration_seconds < 0) { |
+ printf("%s: invalid time interval `%s'\n", argv[0], argv[1]); |
+ return -1; |
+ } |
+ |
+ base::TimeDelta duration = base::TimeDelta::FromSeconds(duration_seconds); |
+ |
+ base::MessageLoop main_loop; |
+ |
+ base::RunLoop run_loop; |
+ |
+ main_loop.PostDelayedTask(FROM_HERE, run_loop.QuitClosure(), duration); |
+ |
+ run_loop.Run(); |
+ |
+ return 0; |
+} |