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

Unified Diff: ppapi/utility/threading/simple_thread.h

Issue 9097006: First pass at implementing the MessageLoop interface. This includes a simple (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 11 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
Index: ppapi/utility/threading/simple_thread.h
diff --git a/ppapi/utility/threading/simple_thread.h b/ppapi/utility/threading/simple_thread.h
new file mode 100644
index 0000000000000000000000000000000000000000..b40022d6d266987b0ab228c5bef16f653d9933af
--- /dev/null
+++ b/ppapi/utility/threading/simple_thread.h
@@ -0,0 +1,57 @@
+// Copyright (c) 2012 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 PPAPI_UTILITY_THREADING_SIMPLE_THREAD_H_
+#define PPAPI_UTILITY_THREADING_SIMPLE_THREAD_H_
+
+#ifdef WIN32
+#include <windows.h>
+#else
+#include <pthread.h>
+#endif
+
+#include "ppapi/cpp/dev/message_loop_dev.h"
+
+namespace pp {
+
+// This class is a simple wrapper around a pthread that creates and runs a
+// PPAPI message loop on that thread.
bbudge 2012/01/10 19:40:20 Comment doesn't seem right in the Windows case.
+class SimpleThread {
+ public:
+#ifdef WIN32
bbudge 2012/01/10 19:40:20 Is WIN32 our define for Windows in general?
brettw 2012/01/18 17:53:09 I think for the wrappers this is the best thing. F
+ typedef HANDLE ThreadHandle;
+#else
+ typedef pthread_t ThreadHandle;
+#endif
+
+ typedef void (*ThreadFunc)(MessageLoop_Dev&, void* user_data);
+
+ SimpleThread(Instance* instance);
+ ~SimpleThread();
+
+ bool Start();
+ bool Join();
+
+ // Normally you can just use Start() to start a thread, and then post work to
+ // it. In some cases you will want control over the message
bbudge 2012/01/10 19:40:20 period (.) Also, you should probably document that
+ bool StartWithFunction(ThreadFunc func, void* user_data);
+
+ MessageLoop_Dev& message_loop() { return message_loop_; }
+ ThreadHandle thread() const { return thread_; }
+
+ private:
+ Instance* instance_;
+ MessageLoop_Dev message_loop_;
+
+ ThreadHandle thread_;
+
+ // Disallow (not implemented).
+ SimpleThread(const SimpleThread&);
+ SimpleThread& operator=(const SimpleThread&);
+};
+
+} // namespace pp
+
+#endif // PPAPI_UTILITY_THREADING_SIMPLE_THREAD_H_
+

Powered by Google App Engine
This is Rietveld 408576698