Update processor
This commit is contained in:
parent
b97baae06d
commit
81be95db12
|
@ -59,11 +59,10 @@ void Processor::SetProcessCallback(ProcessCallback callback) {
|
||||||
callback_ = std::move(callback);
|
callback_ = std::move(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Processor::Activate() {
|
void Processor::Activate(bool tree) {
|
||||||
if (activated_)
|
if (activated_)
|
||||||
return;
|
return;
|
||||||
activated_ = true;
|
if (tree) {
|
||||||
{
|
|
||||||
// Activate all parents
|
// Activate all parents
|
||||||
Processor *parent = parent_;
|
Processor *parent = parent_;
|
||||||
while (parent != nullptr) {
|
while (parent != nullptr) {
|
||||||
|
@ -71,13 +70,20 @@ void Processor::Activate() {
|
||||||
parent = parent->parent_;
|
parent = parent->parent_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
activated_ = true;
|
||||||
thread_ = std::thread(&Processor::Run, this);
|
thread_ = std::thread(&Processor::Run, this);
|
||||||
// thread_.detach();
|
// thread_.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Processor::Deactivate() {
|
void Processor::Deactivate(bool tree) {
|
||||||
if (!activated_)
|
if (!activated_)
|
||||||
return;
|
return;
|
||||||
|
if (tree) {
|
||||||
|
// Deactivate all childs
|
||||||
|
iterate_processors(GetChilds(), [](std::shared_ptr<Processor> proc) {
|
||||||
|
proc->Deactivate();
|
||||||
|
});
|
||||||
|
}
|
||||||
activated_ = false;
|
activated_ = false;
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lk(mtx_input_ready_);
|
std::lock_guard<std::mutex> lk(mtx_input_ready_);
|
||||||
|
|
|
@ -39,8 +39,8 @@ class Processor /*: public std::enable_shared_from_this<Processor>*/ {
|
||||||
void SetPostProcessCallback(PostProcessCallback callback);
|
void SetPostProcessCallback(PostProcessCallback callback);
|
||||||
void SetProcessCallback(ProcessCallback callback);
|
void SetProcessCallback(ProcessCallback callback);
|
||||||
|
|
||||||
void Activate();
|
void Activate(bool tree = false);
|
||||||
void Deactivate();
|
void Deactivate(bool tree = false);
|
||||||
bool IsActivated();
|
bool IsActivated();
|
||||||
|
|
||||||
bool IsIdle();
|
bool IsIdle();
|
||||||
|
@ -93,6 +93,15 @@ class Processor /*: public std::enable_shared_from_this<Processor>*/ {
|
||||||
std::thread thread_;
|
std::thread thread_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void iterate_processors(
|
||||||
|
const T &processors, std::function<void(std::shared_ptr<Processor>)> fn) {
|
||||||
|
for (auto &&proc : processors) {
|
||||||
|
fn(proc);
|
||||||
|
iterate_processors(proc->GetChilds(), fn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MYNTEYE_END_NAMESPACE
|
MYNTEYE_END_NAMESPACE
|
||||||
|
|
||||||
#endif // MYNTEYE_PROCESSOR_H_ NOLINT
|
#endif // MYNTEYE_PROCESSOR_H_ NOLINT
|
||||||
|
|
Loading…
Reference in New Issue
Block a user