//===----------------------------------------------------------------------===// // DuckDB // // duckdb/parallel/event.hpp // // //===----------------------------------------------------------------------===// #pragma once #include "duckdb/common/atomic.hpp" #include "duckdb/common/common.hpp" #include "duckdb/common/vector.hpp" namespace duckdb { class Executor; class Task; class Event : public std::enable_shared_from_this { public: Event(Executor &executor); virtual ~Event() = default; public: virtual void Schedule() = 0; //! Called right after the event is finished virtual void FinishEvent() { } //! Called after the event is entirely finished virtual void FinalizeFinish() { } void FinishTask(); void Finish(); void AddDependency(Event &event); bool HasDependencies() const { return total_dependencies != 0; } const vector &GetParentsVerification() const; void CompleteDependency(); void SetTasks(vector> tasks); void InsertEvent(shared_ptr replacement_event); bool IsFinished() const { return finished; } virtual void PrintPipeline() { } protected: Executor &executor; //! The current threads working on the event atomic finished_tasks; //! The maximum amount of threads that can work on the event atomic total_tasks; //! The amount of completed dependencies //! The event can only be started after the dependencies have finished executing atomic finished_dependencies; //! The total amount of dependencies idx_t total_dependencies; //! The events that depend on this event to run vector> parents; //! Raw pointers to the parents (used for verification only) vector parents_raw; //! Whether or not the event is finished executing atomic finished; }; } // namespace duckdb