Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef PPAPI_UTILITY_THREADING_SIMPLE_THREAD_H_ | |
| 6 #define PPAPI_UTILITY_THREADING_SIMPLE_THREAD_H_ | |
| 7 | |
| 8 #ifdef WIN32 | |
| 9 #include <windows.h> | |
| 10 #else | |
| 11 #include <pthread.h> | |
| 12 #endif | |
| 13 | |
| 14 #include "ppapi/cpp/dev/message_loop_dev.h" | |
| 15 | |
| 16 namespace pp { | |
| 17 | |
| 18 // This class is a simple wrapper around a pthread that creates and runs a | |
| 19 // PPAPI message loop on that thread. | |
|
bbudge
2012/01/10 19:40:20
Comment doesn't seem right in the Windows case.
| |
| 20 class SimpleThread { | |
| 21 public: | |
| 22 #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
| |
| 23 typedef HANDLE ThreadHandle; | |
| 24 #else | |
| 25 typedef pthread_t ThreadHandle; | |
| 26 #endif | |
| 27 | |
| 28 typedef void (*ThreadFunc)(MessageLoop_Dev&, void* user_data); | |
| 29 | |
| 30 SimpleThread(Instance* instance); | |
| 31 ~SimpleThread(); | |
| 32 | |
| 33 bool Start(); | |
| 34 bool Join(); | |
| 35 | |
| 36 // Normally you can just use Start() to start a thread, and then post work to | |
| 37 // 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
| |
| 38 bool StartWithFunction(ThreadFunc func, void* user_data); | |
| 39 | |
| 40 MessageLoop_Dev& message_loop() { return message_loop_; } | |
| 41 ThreadHandle thread() const { return thread_; } | |
| 42 | |
| 43 private: | |
| 44 Instance* instance_; | |
| 45 MessageLoop_Dev message_loop_; | |
| 46 | |
| 47 ThreadHandle thread_; | |
| 48 | |
| 49 // Disallow (not implemented). | |
| 50 SimpleThread(const SimpleThread&); | |
| 51 SimpleThread& operator=(const SimpleThread&); | |
| 52 }; | |
| 53 | |
| 54 } // namespace pp | |
| 55 | |
| 56 #endif // PPAPI_UTILITY_THREADING_SIMPLE_THREAD_H_ | |
| 57 | |
| OLD | NEW |