38template <
class F,
class Tid,
class Tuple, std::size_t... I>
40 std::index_sequence<I...>) {
41 return std::invoke(std::forward<F>(f), std::forward<Tid>(tid),
42 std::get<I>(std::forward<Tuple>(t))...);
45template <
class F,
class Tid,
class Tuple, std::size_t... I>
48 std::forward<F>(f), std::forward<Tid>(tid), std::forward<Tuple>(t),
49 std::make_index_sequence<std::tuple_size_v<std::decay_t<Tuple>>>{});
54template <
typename FType,
typename... Args>
61 auto task_delay = schedule->get_task_delay();
72 using Decayed_FType = std::decay_t<FType>;
73 auto task_shared = std::make_shared<Decayed_FType>(std::forward<FType>(task));
75 constexpr bool may_error_out =
requires(Decayed_FType & t) { t.is_error(); };
77 std::tuple<Args...> tuple_args =
78 std::forward_as_tuple(std::forward<Args>(args)...);
80 auto repeatable_lambda = [
this, schedule, task_shared,
81 tuple_args = std::move(tuple_args)](
83 auto &time_exec_stat =
89 if constexpr (may_error_out) {
95 auto repeatable_task = std::make_shared<Repeatable_task_state>(
98 auto exec_task = [
this, schedule, task_delay, repeatable_task](
105 Scheduled_task scheduled(schedule->get_id(), std::move(exec_task),
106 repeatable_task, schedule, schedule->get_phase_id());
107 if (!schedule->is_finished()) {
116template <
typename Repeatable_task_type>
119 std::shared_ptr<Repeatable_task_type> repeatable_task,
120 unsigned int current_thread_id,
unsigned int phase_id) {
121 auto &phase_clock = schedule->get_phase_clock(phase_id);
124 auto phase_delay = schedule->get_phase_delay(phase_id);
125 [[maybe_unused]]
auto subscribed =
126 phase_clock->add_time(schedule->get_id(), phase_delay);
130 auto phase_task = [
this, schedule, task_delay, repeatable_task,
139 if (schedule->get_phase_clock(phase_id)->get_type() ==
148 Scheduled_task scheduled(schedule->get_id(), std::move(phase_task),
149 repeatable_task, schedule, phase_id);
158 phase_queue.push(std::move(scheduled));
167template <
typename Repeatable_task_type>
170 bool task_error, std::shared_ptr<Repeatable_task_type> repeatable_task,
171 unsigned int current_thread_id) {
176 if (schedule->next()) {
177 if (!schedule->is_enqueued_by_scheduler()) {
178 [[maybe_unused]]
auto enqueued =
180 current_thread_id, schedule->get_phase_id());
185 schedule->set_phase_ready();
189 auto id = schedule->get_id();
190 auto unblocked_tasks =
m_dependencies->mark_dependency_met(
id,
true);
191 for (
auto &entry_id : unblocked_tasks) {
195 if (time_advanced || !unblocked_tasks.empty()) {
203template <
typename FType,
typename... Args>
206 const auto &task_id = schedule->get_id();
207 [[maybe_unused]]
bool activated =
m_dependencies->activate_task(task_id);
210 std::forward<Args>(args)...);
214template <
typename FType,
typename... Args>
218 const auto &task_id = schedule->get_id();
219 [[maybe_unused]]
bool activated =
m_dependencies->activate_task(task_id);
221 [[maybe_unused]]
auto dep_registered =
add_dependency(predecessor, task_id);
222 assert(dep_registered);
224 std::forward<Args>(args)...);
void unlock()
Unblocks access to a critical section for other threads.
Definition: mutex_wrapper.cpp:38
void lock() noexcept
Acquire a lock, blocks access to a critical section until "unlock" is called.
Definition: mutex_wrapper.cpp:32
Represents task that is scheduled in the priority queue.
Definition: scheduled_task.h:87
void set_enqueued_by_scheduler()
Sets the repeatable task and marks as enqueued by scheduler.
Definition: scheduled_task.h:120
uint64_t Time_point_t
Definition: scheduler_clock.h:54
Scheduler_clock_ptr m_scheduler_clock
Scheduler clock.
Definition: scheduler.h:354
Task_result callback(Task_schedule_ptr schedule, Scheduler_clock::Time_point_t task_delay, bool task_error, std::shared_ptr< Repeatable_task_type > repeatable_task, unsigned int current_thread_id)
Function used to notify that task ended its execution.
Definition: scheduler_impl.hpp:168
void notify_scheduler()
Function used to notify scheduler thread by the other thread (enqueueing thread / worker poll thread)
Definition: scheduler.cpp:382
container::Integrals_lockfree_queue< uint64_t > m_notified_tasks
Lock-free queue of task IDs that are ready for execution.
Definition: scheduler.h:336
Dependency_tracker_ptr m_dependencies
Task dependencies, used mainly to implement dependencies between events in one transaction or between...
Definition: scheduler.h:371
bool is_error() const
Internal function to check on whether error has been set.
Definition: scheduler.cpp:252
std::atomic< std::size_t > m_scheduled_tasks_cnt
The number of scheduled tasks.
Definition: scheduler.h:351
bool enqueue_helper(Scheduled_task &&task)
Enqueue helper.
Definition: scheduler.cpp:310
Task_result callback_phase(Task_schedule_ptr schedule, bool task_error, unsigned int phase_id)
Function used to notify that task phase ended its execution.
Definition: scheduler.cpp:390
bool add_dependency(const Task_id &predecessor, const Task_id &successor)
add_dependency
Definition: scheduler.cpp:86
Statistics_instance_monitor_ref m_stat_monitor
Statistics monitoring object for the current instance.
Definition: scheduler.h:381
std::atomic< std::size_t > m_allowed_task_count
Maximum allowed number of tasks active in the scheduler.
Definition: scheduler.h:384
void synchronize_partial(bool print_checkpoint=false)
Waits for percent of tasks to finish.
Definition: scheduler.cpp:376
std::atomic< bool > m_stop_now
Variable that instructs scheduler to withdraw all work and stop.
Definition: scheduler.h:348
bool enqueue_internal(Task_schedule_ptr schedule, FType &&task, Args &&...args)
Enqueues a task identified by the task_id.
Definition: scheduler_impl.hpp:55
bool enqueue_phase(Task_schedule_ptr schedule, Scheduler_clock::Time_point_t task_delay, std::shared_ptr< Repeatable_task_type > repeatable_task, unsigned int current_thread_id, unsigned int phase_id)
Function that enqueues next task phase.
Definition: scheduler_impl.hpp:117
Mutex_type m_mutex_phases
This mutex protect access to phase.
Definition: scheduler.h:316
bool enqueue(Task_schedule_ptr schedule, FType &&task, Args &&...args)
Enqueues a task.
Definition: scheduler_impl.hpp:204
Scheduler_psi m_psi
PSI parameters.
Definition: scheduler.h:393
void handle_error()
Worker error handling function.
Definition: scheduler.cpp:276
bool enqueue_after(const Task_id &predecessor, Task_schedule_ptr schedule, FType &&task, Args &&...args)
Enqueues a task that should execute after a predecessor task finishes.
Definition: scheduler_impl.hpp:215
Task_queue_type & get_phase_queue(Scheduler_clock_ptr phase_clock)
Definition: scheduler.cpp:281
static constexpr auto sched_task_exec_time
Definition: statistics_map.h:48
Represents the identifier of a task ingested by the scheduler,.
Definition: task_id.h:41
#define F
Definition: jit_executor_value.cc:374
static my_thread_id thread_id
Definition: my_thr_init.cc:60
Definition: packet_based_table_with_cursor.h:36
void set_stage(auto key)
Definition: stage.h:41
constexpr decltype(auto) apply_with_thread_id_impl(F &&f, Tid &&tid, Tuple &&t, std::index_sequence< I... >)
Definition: scheduler_impl.hpp:39
constexpr decltype(auto) apply_with_thread_id(F &&f, Tid &&tid, Tuple &&t)
Definition: scheduler_impl.hpp:46
Definition: base_dependency_tracker.h:41
Task_result
Acceptable task state after its execution.
Definition: task_result.h:32
@ fatal_error
Fatal error which we cannot recover and need to stop.
@ success
Task executed successfully.
std::shared_ptr< Task_schedule > Task_schedule_ptr
Definition: task_schedule.h:41
static constexpr unsigned int scheduler_thread_id
Scheduler thread id constant, used by the scheduler thread (max)
Definition: constants.h:40
concurrency::Stage_key key_stage_wait_clock_queue
stage: waiting for clock (cannot handle more dependencies)
Definition: scheduler_psi.h:66
concurrency::Stage_key key_reached_max_task_limit
stage: synchronizing scheduler - reached max task limit
Definition: scheduler_psi.h:68