niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 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 | |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame^] | 11 | #ifndef WEBRTC_MODULES_UTILITY_INCLUDE_PROCESS_THREAD_H_ |
| 12 | #define WEBRTC_MODULES_UTILITY_INCLUDE_PROCESS_THREAD_H_ |
| 13 | |
| 14 | #pragma message("WARNING: utility/interface is DEPRECATED; use utility/include") |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 15 | |
pbos@webrtc.org | 8b06200 | 2013-07-12 08:28:10 +0000 | [diff] [blame] | 16 | #include "webrtc/typedefs.h" |
tommi@webrtc.org | 0c3e12b | 2015-02-06 09:44:12 +0000 | [diff] [blame] | 17 | #include "webrtc/base/scoped_ptr.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
| 20 | class Module; |
| 21 | |
tommi@webrtc.org | 0305448 | 2015-03-05 13:13:42 +0000 | [diff] [blame] | 22 | class ProcessTask { |
| 23 | public: |
| 24 | ProcessTask() {} |
| 25 | virtual ~ProcessTask() {} |
| 26 | |
| 27 | virtual void Run() = 0; |
| 28 | }; |
| 29 | |
tommi@webrtc.org | 0c3e12b | 2015-02-06 09:44:12 +0000 | [diff] [blame] | 30 | class ProcessThread { |
| 31 | public: |
| 32 | virtual ~ProcessThread(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | |
stefan | 847855b | 2015-09-11 09:52:15 -0700 | [diff] [blame] | 34 | static rtc::scoped_ptr<ProcessThread> Create(const char* thread_name); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | |
tommi@webrtc.org | 0c3e12b | 2015-02-06 09:44:12 +0000 | [diff] [blame] | 36 | // Starts the worker thread. Must be called from the construction thread. |
tommi@webrtc.org | 3985f01 | 2015-02-27 13:36:34 +0000 | [diff] [blame] | 37 | virtual void Start() = 0; |
tommi@webrtc.org | 0c3e12b | 2015-02-06 09:44:12 +0000 | [diff] [blame] | 38 | |
| 39 | // Stops the worker thread. Must be called from the construction thread. |
tommi@webrtc.org | 3985f01 | 2015-02-27 13:36:34 +0000 | [diff] [blame] | 40 | virtual void Stop() = 0; |
tommi@webrtc.org | 0c3e12b | 2015-02-06 09:44:12 +0000 | [diff] [blame] | 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 | |
tommi@webrtc.org | 0305448 | 2015-03-05 13:13:42 +0000 | [diff] [blame] | 49 | // Queues a task object to run on the worker thread. Ownership of the |
| 50 | // task object is transferred to the ProcessThread and the object will |
| 51 | // either be deleted after running on the worker thread, or on the |
| 52 | // construction thread of the ProcessThread instance, if the task did not |
| 53 | // get a chance to run (e.g. posting the task while shutting down or when |
| 54 | // the thread never runs). |
| 55 | virtual void PostTask(rtc::scoped_ptr<ProcessTask> task) = 0; |
| 56 | |
tommi@webrtc.org | 0c3e12b | 2015-02-06 09:44:12 +0000 | [diff] [blame] | 57 | // Adds a module that will start to receive callbacks on the worker thread. |
| 58 | // Can be called from any thread. |
tommi@webrtc.org | 3985f01 | 2015-02-27 13:36:34 +0000 | [diff] [blame] | 59 | virtual void RegisterModule(Module* module) = 0; |
tommi@webrtc.org | 0c3e12b | 2015-02-06 09:44:12 +0000 | [diff] [blame] | 60 | |
| 61 | // Removes a previously registered module. |
| 62 | // Can be called from any thread. |
tommi@webrtc.org | 3985f01 | 2015-02-27 13:36:34 +0000 | [diff] [blame] | 63 | virtual void DeRegisterModule(Module* module) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 64 | }; |
tommi@webrtc.org | 0c3e12b | 2015-02-06 09:44:12 +0000 | [diff] [blame] | 65 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 66 | } // namespace webrtc |
tommi@webrtc.org | 0c3e12b | 2015-02-06 09:44:12 +0000 | [diff] [blame] | 67 | |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame^] | 68 | #endif // WEBRTC_MODULES_UTILITY_INCLUDE_PROCESS_THREAD_H_ |