21#ifndef HEDGEHOG_DEFAULT_SCHEDULER_H
22#define HEDGEHOG_DEFAULT_SCHEDULER_H
29#include "../../core/abstractions/base/node/task_node_abstraction.h"
30#include "../../core/abstractions/base/node/execution_pipeline_node_abstraction.h"
31#include "../../core/abstractions/base/node/graph_node_abstraction.h"
40 std::unique_ptr<std::vector<std::thread>>
const
43 std::unique_ptr<std::vector<core::abstraction::GraphNodeAbstraction *>>
49 threads_(std::make_unique<std::vector<std::thread>>()),
50 innerGraphs_(std::make_unique<std::vector<core::abstraction::GraphNodeAbstraction *>>()) {}
57 [[nodiscard]] std::unique_ptr<Scheduler>
create()
const override {
return std::make_unique<DefaultScheduler>(); }
63 void spawnThreads(std::set<core::abstraction::NodeAbstraction *>
const &cores,
bool waitForInitialization)
override {
64 std::vector<core::abstraction::TaskNodeAbstraction *> taskExec{};
66 for (
auto &core : cores) {
70 taskExec.push_back(exec);
71 }
catch (std::exception
const &e) {
72 std::ostringstream oss;
73 oss <<
"Can not create thread for node \"" << core->name() <<
"\" because of error: " << e.what();
74 throw std::runtime_error(oss.str());
79 std::ostringstream oss;
81 <<
"Node " << core->name() <<
"/" << core->id()
82 <<
" does not derive from the right abstraction to be handled properly by the default scheduler.";
83 throw std::runtime_error(oss.str());
88 if (waitForInitialization) {
89 while (!std::all_of(taskExec.cbegin(), taskExec.cend(),
90 [](
auto const &exec) { return exec->isInitialized(); })) {}
97 std::for_each(
threads_->begin(),
threads_->end(), [](std::thread &t) { t.join(); });
99 innerGraph->joinThreads();
Default scheduler use in Hedgehog graph.
std::unique_ptr< std::vector< core::abstraction::GraphNodeAbstraction * > > innerGraphs_
Scheduler's graph.
~DefaultScheduler() override=default
Default destructor.
std::unique_ptr< Scheduler > create() const override
Definition of virtual constructor.
void joinAll() override
Wait for all inside nodes to join and join the threads of all inside graphs.
void spawnThreads(std::set< core::abstraction::NodeAbstraction * > const &cores, bool waitForInitialization) override
Spawn the threads for all graph's nodes.
DefaultScheduler()
Default constructor.
std::unique_ptr< std::vector< std::thread > > const threads_
Vector of threads for the graph nodes.
Scheduler abstraction to manage graph's threads.
Base graph node abstraction.
Task core abstraction used to define some method for task-like behaving cores like CoreExecutionPipel...
virtual void run()=0
Run method, called when thread is attached.