Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Unified Diff: base/cpp101/sleep.cc

Issue 23506012: Example solution for C++ 101 Exercise 3 (message loops) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync to 224002 Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/base.gyp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
+}
« no previous file with comments | « base/base.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698