Chromium Code Reviews| 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_ |
| + |