blob: 451a5a301b5d2649c1e09c1b3410c0c818bef891 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
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
11#ifndef WEBRTC_MODULES_UTILITY_INTERFACE_PROCESS_THREAD_H_
12#define WEBRTC_MODULES_UTILITY_INTERFACE_PROCESS_THREAD_H_
13
pbos@webrtc.org8b062002013-07-12 08:28:10 +000014#include "webrtc/typedefs.h"
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000015#include "webrtc/base/scoped_ptr.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000016
17namespace webrtc {
18class Module;
19
tommi@webrtc.org03054482015-03-05 13:13:42 +000020class ProcessTask {
21 public:
22 ProcessTask() {}
23 virtual ~ProcessTask() {}
24
25 virtual void Run() = 0;
26};
27
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000028class ProcessThread {
29 public:
30 virtual ~ProcessThread();
niklase@google.com470e71d2011-07-07 08:21:25 +000031
stefan847855b2015-09-11 09:52:15 -070032 static rtc::scoped_ptr<ProcessThread> Create(const char* thread_name);
niklase@google.com470e71d2011-07-07 08:21:25 +000033
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000034 // Starts the worker thread. Must be called from the construction thread.
tommi@webrtc.org3985f012015-02-27 13:36:34 +000035 virtual void Start() = 0;
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000036
37 // Stops the worker thread. Must be called from the construction thread.
tommi@webrtc.org3985f012015-02-27 13:36:34 +000038 virtual void Stop() = 0;
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000039
40 // Wakes the thread up to give a module a chance to do processing right
41 // away. This causes the worker thread to wake up and requery the specified
42 // module for when it should be called back. (Typically the module should
43 // return 0 from TimeUntilNextProcess on the worker thread at that point).
44 // Can be called on any thread.
45 virtual void WakeUp(Module* module) = 0;
46
tommi@webrtc.org03054482015-03-05 13:13:42 +000047 // Queues a task object to run on the worker thread. Ownership of the
48 // task object is transferred to the ProcessThread and the object will
49 // either be deleted after running on the worker thread, or on the
50 // construction thread of the ProcessThread instance, if the task did not
51 // get a chance to run (e.g. posting the task while shutting down or when
52 // the thread never runs).
53 virtual void PostTask(rtc::scoped_ptr<ProcessTask> task) = 0;
54
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000055 // Adds a module that will start to receive callbacks on the worker thread.
56 // Can be called from any thread.
tommi@webrtc.org3985f012015-02-27 13:36:34 +000057 virtual void RegisterModule(Module* module) = 0;
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000058
59 // Removes a previously registered module.
60 // Can be called from any thread.
tommi@webrtc.org3985f012015-02-27 13:36:34 +000061 virtual void DeRegisterModule(Module* module) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000062};
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000063
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000064} // namespace webrtc
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000065
niklase@google.com470e71d2011-07-07 08:21:25 +000066#endif // WEBRTC_MODULES_UTILITY_INTERFACE_PROCESS_THREAD_H_