blob: 5a42140faebf390316fd7713d2c033d6f9fd5fc0 [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_SOURCE_PROCESS_THREAD_IMPL_H_
12#define WEBRTC_MODULES_UTILITY_SOURCE_PROCESS_THREAD_IMPL_H_
13
henrike@webrtc.org79cf3ac2014-01-13 15:21:30 +000014#include <list>
15
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000016#include "webrtc/base/criticalsection.h"
17#include "webrtc/base/thread_checker.h"
pbos@webrtc.org8b062002013-07-12 08:28:10 +000018#include "webrtc/modules/utility/interface/process_thread.h"
pbos@webrtc.org8b062002013-07-12 08:28:10 +000019#include "webrtc/system_wrappers/interface/event_wrapper.h"
pbos@webrtc.org8b062002013-07-12 08:28:10 +000020#include "webrtc/system_wrappers/interface/thread_wrapper.h"
21#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000022
23namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000024
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000025class ProcessThreadImpl : public ProcessThread {
26 public:
27 ProcessThreadImpl();
28 ~ProcessThreadImpl() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000029
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000030 int32_t Start() override;
31 int32_t Stop() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000032
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000033 void WakeUp(Module* module) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000034
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000035 int32_t RegisterModule(Module* module);
36 int32_t DeRegisterModule(const Module* module);
niklase@google.com470e71d2011-07-07 08:21:25 +000037
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000038 protected:
39 static bool Run(void* obj);
40 bool Process();
41
42 private:
43 rtc::ThreadChecker thread_checker_;
44 const rtc::scoped_ptr<EventWrapper> wake_up_;
45 rtc::scoped_ptr<ThreadWrapper> thread_;
46
47 struct ModuleCallback {
48 ModuleCallback(Module* module) : module(module), next_callback(0) {}
49 bool operator==(const ModuleCallback& cb) const {
50 return cb.module == module;
51 }
52 Module* const module;
53 int64_t next_callback; // Absolute timestamp.
54 };
55
56 rtc::CriticalSection lock_; // Used to guard modules_ and stop_.
57 typedef std::list<ModuleCallback> ModuleList;
58 ModuleList modules_;
59 bool stop_;
niklase@google.com470e71d2011-07-07 08:21:25 +000060};
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000061
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000062} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000063
64#endif // WEBRTC_MODULES_UTILITY_SOURCE_PROCESS_THREAD_IMPL_H_