| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 |
| 11 | #ifndef MODULES_UTILITY_INCLUDE_PROCESS_THREAD_H_ |
| 12 | #define MODULES_UTILITY_INCLUDE_PROCESS_THREAD_H_ |
| 13 |
| 14 | #include <memory> |
| 15 |
| 16 | #include "api/task_queue/queued_task.h" |
| 17 | #include "api/task_queue/task_queue_base.h" |
| 18 |
| 19 | namespace rtc { |
| 20 | class Location; |
| 21 | } |
| 22 |
| 23 | namespace webrtc { |
| 24 | class Module; |
| 25 |
| 26 | // TODO(tommi): ProcessThread probably doesn't need to be a virtual |
| 27 | // interface. There exists one override besides ProcessThreadImpl, |
| 28 | // MockProcessThread, but when looking at how it is used, it seems |
| 29 | // a nullptr might suffice (or simply an actual ProcessThread instance). |
| 30 | class ProcessThread : public TaskQueueBase { |
| 31 | public: |
| 32 | ~ProcessThread() override; |
| 33 |
| 34 | static std::unique_ptr<ProcessThread> Create(const char* thread_name); |
| 35 |
| 36 | // Starts the worker thread. Must be called from the construction thread. |
| 37 | virtual void Start() = 0; |
| 38 |
| 39 | // Stops the worker thread. Must be called from the construction thread. |
| 40 | virtual void Stop() = 0; |
| 41 |
| 42 | // Wakes the thread up to give a module a chance to do processing right |
| 43 | // away. This causes the worker thread to wake up and requery the specified |
| 44 | // module for when it should be called back. (Typically the module should |
| 45 | // return 0 from TimeUntilNextProcess on the worker thread at that point). |
| 46 | // Can be called on any thread. |
| 47 | virtual void WakeUp(Module* module) = 0; |
| 48 |
| 49 | // Adds a module that will start to receive callbacks on the worker thread. |
| 50 | // Can be called from any thread. |
| 51 | virtual void RegisterModule(Module* module, const rtc::Location& from) = 0; |
| 52 |
| 53 | // Removes a previously registered module. |
| 54 | // Can be called from any thread. |
| 55 | virtual void DeRegisterModule(Module* module) = 0; |
| 56 | }; |
| 57 |
| 58 | } // namespace webrtc |
| 59 |
| 60 | #endif // MODULES_UTILITY_INCLUDE_PROCESS_THREAD_H_ |
| 61 |