blob: 1a7a8750cd42069c405b1473a7a7981c96c51891 [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
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010011#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.com470e71d2011-07-07 08:21:25 +000015
pbos@webrtc.org8b062002013-07-12 08:28:10 +000016#include "webrtc/typedefs.h"
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000017#include "webrtc/base/scoped_ptr.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000018
19namespace webrtc {
20class Module;
21
tommi@webrtc.org03054482015-03-05 13:13:42 +000022class ProcessTask {
23 public:
24 ProcessTask() {}
25 virtual ~ProcessTask() {}
26
27 virtual void Run() = 0;
28};
29
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000030class ProcessThread {
31 public:
32 virtual ~ProcessThread();
niklase@google.com470e71d2011-07-07 08:21:25 +000033
stefan847855b2015-09-11 09:52:15 -070034 static rtc::scoped_ptr<ProcessThread> Create(const char* thread_name);
niklase@google.com470e71d2011-07-07 08:21:25 +000035
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000036 // Starts the worker thread. Must be called from the construction thread.
tommi@webrtc.org3985f012015-02-27 13:36:34 +000037 virtual void Start() = 0;
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000038
39 // Stops the worker thread. Must be called from the construction thread.
tommi@webrtc.org3985f012015-02-27 13:36:34 +000040 virtual void Stop() = 0;
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000041
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.org03054482015-03-05 13:13:42 +000049 // 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.org0c3e12b2015-02-06 09:44:12 +000057 // Adds a module that will start to receive callbacks on the worker thread.
58 // Can be called from any thread.
tommi@webrtc.org3985f012015-02-27 13:36:34 +000059 virtual void RegisterModule(Module* module) = 0;
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000060
61 // Removes a previously registered module.
62 // Can be called from any thread.
tommi@webrtc.org3985f012015-02-27 13:36:34 +000063 virtual void DeRegisterModule(Module* module) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000064};
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000065
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000066} // namespace webrtc
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000067
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010068#endif // WEBRTC_MODULES_UTILITY_INCLUDE_PROCESS_THREAD_H_