• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #ifndef WEBRTC_MODULES_UTILITY_INCLUDE_PROCESS_THREAD_H_
12 #define WEBRTC_MODULES_UTILITY_INCLUDE_PROCESS_THREAD_H_
13 
14 #include "webrtc/typedefs.h"
15 #include "webrtc/base/scoped_ptr.h"
16 
17 namespace webrtc {
18 class Module;
19 
20 class ProcessTask {
21  public:
ProcessTask()22   ProcessTask() {}
~ProcessTask()23   virtual ~ProcessTask() {}
24 
25   virtual void Run() = 0;
26 };
27 
28 class ProcessThread {
29  public:
30   virtual ~ProcessThread();
31 
32   static rtc::scoped_ptr<ProcessThread> Create(const char* thread_name);
33 
34   // Starts the worker thread.  Must be called from the construction thread.
35   virtual void Start() = 0;
36 
37   // Stops the worker thread.  Must be called from the construction thread.
38   virtual void Stop() = 0;
39 
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 
47   // 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 
55   // Adds a module that will start to receive callbacks on the worker thread.
56   // Can be called from any thread.
57   virtual void RegisterModule(Module* module) = 0;
58 
59   // Removes a previously registered module.
60   // Can be called from any thread.
61   virtual void DeRegisterModule(Module* module) = 0;
62 };
63 
64 }  // namespace webrtc
65 
66 #endif // WEBRTC_MODULES_UTILITY_INCLUDE_PROCESS_THREAD_H_
67