Skip to content

Commit

Permalink
add asynciorunnable
Browse files Browse the repository at this point in the history
  • Loading branch information
cwharris committed Oct 27, 2023
1 parent 5412e76 commit 26fae58
Show file tree
Hide file tree
Showing 4 changed files with 513 additions and 29 deletions.
18 changes: 0 additions & 18 deletions cpp/mrc/include/mrc/coroutines/scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,8 @@
#include <mutex>
#include <string>

// IWYU thinks this is needed, but it's not
// IWYU pragma: no_include "mrc/coroutines/task_container.hpp"

namespace mrc::coroutines {

class TaskContainer; // IWYU pragma: keep

/**
* @brief Scheduler base class
*
Expand Down Expand Up @@ -75,9 +70,6 @@ class Scheduler : public std::enable_shared_from_this<Scheduler>
*/
[[nodiscard]] virtual auto schedule() -> Operation;

// Enqueues a message without waiting for it. Must return void since the caller will not get the return value
virtual void schedule(Task<void>&& task);

/**
* Schedules any coroutine handle that is ready to be resumed.
* @param handle The coroutine handle to schedule.
Expand All @@ -103,13 +95,6 @@ class Scheduler : public std::enable_shared_from_this<Scheduler>
protected:
virtual auto on_thread_start(std::size_t) -> void;

/**
* @brief Get the task container object
*
* @return TaskContainer&
*/
TaskContainer& get_task_container() const;

private:
/**
* @brief When co_await schedule() is called, this function will be executed by the awaiter. Each scheduler
Expand All @@ -123,9 +108,6 @@ class Scheduler : public std::enable_shared_from_this<Scheduler>

mutable std::mutex m_mutex;

// Maintains the lifetime of fire-and-forget tasks scheduled with schedule(Task<void>&& task)
std::unique_ptr<TaskContainer> m_task_container;

thread_local static Scheduler* m_thread_local_scheduler;
thread_local static std::size_t m_thread_id;
};
Expand Down
12 changes: 1 addition & 11 deletions cpp/mrc/src/public/coroutines/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,13 @@ std::coroutine_handle<> Scheduler::Operation::await_suspend(std::coroutine_handl
return m_scheduler.schedule_operation(this);
}

Scheduler::Scheduler() : m_task_container(new TaskContainer(*this)) {}
Scheduler::Scheduler() = default;

auto Scheduler::schedule() -> Operation
{
return Operation{*this};
}

void Scheduler::schedule(Task<void>&& task)
{
return m_task_container->start(std::move(task));
}

auto Scheduler::yield() -> Operation
{
return schedule();
Expand All @@ -77,9 +72,4 @@ auto Scheduler::on_thread_start(std::size_t thread_id) -> void
m_thread_local_scheduler = this;
}

TaskContainer& Scheduler::get_task_container() const
{
return *m_task_container;
}

} // namespace mrc::coroutines
Loading

0 comments on commit 26fae58

Please sign in to comment.