2011-07-07 08:21:25 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef WEBRTC_MODULES_UTILITY_SOURCE_PROCESS_THREAD_IMPL_H_
|
|
|
|
|
#define WEBRTC_MODULES_UTILITY_SOURCE_PROCESS_THREAD_IMPL_H_
|
|
|
|
|
|
2014-01-13 15:21:30 +00:00
|
|
|
#include <list>
|
2016-03-17 09:17:43 -07:00
|
|
|
#include <memory>
|
2015-03-05 13:13:42 +00:00
|
|
|
#include <queue>
|
2014-01-13 15:21:30 +00:00
|
|
|
|
2015-02-06 09:44:12 +00:00
|
|
|
#include "webrtc/base/criticalsection.h"
|
2015-11-23 14:47:56 -08:00
|
|
|
#include "webrtc/base/platform_thread.h"
|
2015-02-06 09:44:12 +00:00
|
|
|
#include "webrtc/base/thread_checker.h"
|
2015-11-04 08:31:52 +01:00
|
|
|
#include "webrtc/modules/utility/include/process_thread.h"
|
2015-10-28 18:17:40 +01:00
|
|
|
#include "webrtc/system_wrappers/include/event_wrapper.h"
|
2013-07-12 08:28:10 +00:00
|
|
|
#include "webrtc/typedefs.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2015-02-06 09:44:12 +00:00
|
|
|
class ProcessThreadImpl : public ProcessThread {
|
|
|
|
|
public:
|
2015-09-11 09:52:15 -07:00
|
|
|
explicit ProcessThreadImpl(const char* thread_name);
|
2015-02-06 09:44:12 +00:00
|
|
|
~ProcessThreadImpl() override;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-02-27 13:36:34 +00:00
|
|
|
void Start() override;
|
|
|
|
|
void Stop() override;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-02-06 09:44:12 +00:00
|
|
|
void WakeUp(Module* module) override;
|
2016-05-28 14:57:15 -07:00
|
|
|
void PostTask(std::unique_ptr<rtc::QueuedTask> task) override;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-02-27 13:36:34 +00:00
|
|
|
void RegisterModule(Module* module) override;
|
|
|
|
|
void DeRegisterModule(Module* module) override;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-02-06 09:44:12 +00:00
|
|
|
protected:
|
|
|
|
|
static bool Run(void* obj);
|
|
|
|
|
bool Process();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
struct ModuleCallback {
|
2015-02-08 00:48:10 +00:00
|
|
|
ModuleCallback() : module(nullptr), next_callback(0) {}
|
|
|
|
|
ModuleCallback(const ModuleCallback& cb)
|
|
|
|
|
: module(cb.module), next_callback(cb.next_callback) {}
|
2015-02-06 09:44:12 +00:00
|
|
|
ModuleCallback(Module* module) : module(module), next_callback(0) {}
|
|
|
|
|
bool operator==(const ModuleCallback& cb) const {
|
|
|
|
|
return cb.module == module;
|
|
|
|
|
}
|
2015-02-08 00:48:10 +00:00
|
|
|
|
2015-02-06 09:44:12 +00:00
|
|
|
Module* const module;
|
|
|
|
|
int64_t next_callback; // Absolute timestamp.
|
2015-02-08 00:48:10 +00:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
ModuleCallback& operator=(ModuleCallback&);
|
2015-02-06 09:44:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef std::list<ModuleCallback> ModuleList;
|
2015-02-08 00:48:10 +00:00
|
|
|
|
|
|
|
|
// Warning: For some reason, if |lock_| comes immediately before |modules_|
|
|
|
|
|
// with the current class layout, we will start to have mysterious crashes
|
|
|
|
|
// on Mac 10.9 debug. I (Tommi) suspect we're hitting some obscure alignemnt
|
|
|
|
|
// issues, but I haven't figured out what they are, if there are alignment
|
|
|
|
|
// requirements for mutexes on Mac or if there's something else to it.
|
|
|
|
|
// So be careful with changing the layout.
|
2015-03-05 13:13:42 +00:00
|
|
|
rtc::CriticalSection lock_; // Used to guard modules_, tasks_ and stop_.
|
2015-02-08 00:48:10 +00:00
|
|
|
|
|
|
|
|
rtc::ThreadChecker thread_checker_;
|
2016-03-17 09:17:43 -07:00
|
|
|
const std::unique_ptr<EventWrapper> wake_up_;
|
|
|
|
|
// TODO(pbos): Remove unique_ptr and stop recreating the thread.
|
|
|
|
|
std::unique_ptr<rtc::PlatformThread> thread_;
|
2015-02-08 00:48:10 +00:00
|
|
|
|
2015-02-06 09:44:12 +00:00
|
|
|
ModuleList modules_;
|
2016-05-28 14:57:15 -07:00
|
|
|
std::queue<rtc::QueuedTask*> queue_;
|
2015-02-06 09:44:12 +00:00
|
|
|
bool stop_;
|
2015-09-14 07:53:38 -07:00
|
|
|
const char* thread_name_;
|
2011-07-07 08:21:25 +00:00
|
|
|
};
|
2015-02-06 09:44:12 +00:00
|
|
|
|
2013-07-03 15:12:26 +00:00
|
|
|
} // namespace webrtc
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
#endif // WEBRTC_MODULES_UTILITY_SOURCE_PROCESS_THREAD_IMPL_H_
|