summaryrefslogtreecommitdiffstats
path: root/mojo/public/cpp/utility/thread.h
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-29 00:39:26 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-29 00:39:26 +0000
commit3b3c6445122bf8144b08c94c42db00f6079e4c77 (patch)
tree8483986e8a9b4696543b1606c8fa1f28745dbcf0 /mojo/public/cpp/utility/thread.h
parente97a6074124c0bbb4e57316e754b64e3eb0a8ee1 (diff)
downloadchromium_src-3b3c6445122bf8144b08c94c42db00f6079e4c77.zip
chromium_src-3b3c6445122bf8144b08c94c42db00f6079e4c77.tar.gz
chromium_src-3b3c6445122bf8144b08c94c42db00f6079e4c77.tar.bz2
Mojo: Move mojo/public/utility to mojo/public/cpp/utility.
R=sky@chromium.org Review URL: https://codereview.chromium.org/217443002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260324 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/public/cpp/utility/thread.h')
-rw-r--r--mojo/public/cpp/utility/thread.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/mojo/public/cpp/utility/thread.h b/mojo/public/cpp/utility/thread.h
new file mode 100644
index 0000000..b7d10ee
--- /dev/null
+++ b/mojo/public/cpp/utility/thread.h
@@ -0,0 +1,62 @@
+// Copyright 2014 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.
+
+#ifndef MOJO_PUBLIC_CPP_UTILITY_THREAD_H_
+#define MOJO_PUBLIC_CPP_UTILITY_THREAD_H_
+
+#ifdef _WIN32
+#error "Not implemented: See crbug.com/342893."
+#endif
+
+#include <pthread.h>
+#include <stddef.h>
+
+#include "mojo/public/cpp/system/macros.h"
+
+namespace mojo {
+
+// This class is thread-friendly, not thread-safe (e.g., you mustn't call
+// |Join()| from multiple threads and/or simultaneously try to destroy the
+// object).
+class Thread {
+ public:
+ // TODO(vtl): Support non-joinable? priority?
+ class Options {
+ public:
+ Options() : stack_size_(0) {}
+
+ // A stack size of 0 means the default.
+ size_t stack_size() const { return stack_size_; }
+ void set_stack_size(size_t stack_size) { stack_size_ = stack_size; }
+
+ private:
+ size_t stack_size_;
+
+ // Copy and assign allowed.
+ };
+
+ // TODO(vtl): Add name or name prefix?
+ Thread();
+ explicit Thread(const Options& options);
+ virtual ~Thread();
+
+ void Start();
+ void Join();
+
+ virtual void Run() = 0;
+
+ private:
+ static void* ThreadRunTrampoline(void* arg);
+
+ const Options options_;
+ pthread_t thread_;
+ bool started_;
+ bool joined_;
+
+ MOJO_DISALLOW_COPY_AND_ASSIGN(Thread);
+};
+
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_CPP_UTILITY_THREAD_H_