Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AsyncioRunnable #411

Merged
merged 51 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
06258e5
move pycoro to mrc
cwharris Oct 20, 2023
44c3575
python coroutine tests
cwharris Oct 20, 2023
49fc835
remove commented code
cwharris Oct 24, 2023
2b2363e
adjust indentation of `\`
cwharris Oct 24, 2023
5a807f6
fix styles
cwharris Oct 24, 2023
12e54fb
adjust styles
cwharris Oct 25, 2023
4822967
add back some timing and hit-count logic to coro tests
cwharris Oct 25, 2023
ff44453
remove unused namespace and rename pycoro
cwharris Oct 25, 2023
d54ca8f
fix styles
cwharris Oct 25, 2023
5412e76
fix styles
cwharris Oct 25, 2023
26fae58
add asynciorunnable
cwharris Oct 27, 2023
4ea145a
Merge branch 'branch-23.11' of github.com:nv-morpheus/MRC into fea-sh…
cwharris Oct 27, 2023
7eb5da7
remove unncessary using
cwharris Oct 27, 2023
622fbac
adjust includes for scheduler.cpp/hpp
cwharris Oct 27, 2023
a2a0938
remove unncessary bool return for await_suspend
cwharris Oct 27, 2023
64a346b
add copyright header
cwharris Oct 27, 2023
e157311
asyncio_runnable test
cwharris Oct 30, 2023
d964e00
fix imports
cwharris Oct 31, 2023
d456588
remove unused includes
cwharris Oct 31, 2023
222edcd
move exception catcher to MRC
cwharris Oct 31, 2023
fc49a12
rename and document BoostFutureAwaiter -> BoostFutureAwaitableOperation
cwharris Oct 31, 2023
5f5f7ae
remove unneccessary ireader and iwriter interfaces
cwharris Nov 1, 2023
48dad3d
simplify asyncio_runnable
cwharris Nov 1, 2023
521abc2
simplify asyncio_runnable
cwharris Nov 1, 2023
a0d136e
simplify asyncio_runnable
cwharris Nov 1, 2023
e1da112
simplify asyncio_runnable
cwharris Nov 1, 2023
2126de9
rename coroutinerunnable sink/source to async sink/source, add docs
cwharris Nov 1, 2023
1bf51c8
adjust comments
cwharris Nov 1, 2023
760c314
remove concurrency from asyncioscheduler
cwharris Nov 1, 2023
b835b24
move ownership of event loop out of asyncioscheduler
cwharris Nov 1, 2023
8be2867
add info log
cwharris Nov 1, 2023
efd7fe9
fix bug related to r-value reference and suspended coroutine
cwharris Nov 1, 2023
e509bbb
add python-coroutine-based test for asynciorunnable
cwharris Nov 1, 2023
2b2f26e
fix test_asyncio_runnable test class to support multiple test cases
cwharris Nov 1, 2023
df8feb8
refactor scheduler to be simpler
cwharris Nov 1, 2023
ce77e06
fix includes
cwharris Nov 1, 2023
e733106
add boost future awaitable operation test
cwharris Nov 1, 2023
ce7d371
fix tests
cwharris Nov 2, 2023
98e093a
add comments to scheduler and asyncio_scheduler
cwharris Nov 2, 2023
e650997
comment asyncio_runnable's functions
cwharris Nov 2, 2023
4b1999d
add exception test case for asyncio_runnable
cwharris Nov 2, 2023
1591e3d
add asyncgenerator failure test to asyncio_runnable
cwharris Nov 2, 2023
c2942c2
formatting
cwharris Nov 2, 2023
00253e6
remove inspect
cwharris Nov 2, 2023
a4e49f2
fix includes
cwharris Nov 2, 2023
7fa1f79
fix scheduler comment styles
cwharris Nov 2, 2023
519d0e7
fix asyncio_scheduler styles
cwharris Nov 2, 2023
229dd3a
fix styles
cwharris Nov 2, 2023
5dbfbe0
add copyright header to exception_catcher.hpp
cwharris Nov 2, 2023
6c070c8
styles
cwharris Nov 2, 2023
f2369db
fix exception_catch.cpp copyright header
cwharris Nov 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions cpp/mrc/include/mrc/coroutines/scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,14 @@

#pragma once

#include "mrc/coroutines/task.hpp"

#include <coroutine>
#include <cstddef>
#include <memory>
#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 +68,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 +93,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 +106,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
16 changes: 1 addition & 15 deletions cpp/mrc/src/public/coroutines/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@

#include "mrc/coroutines/scheduler.hpp"

#include "mrc/coroutines/task_container.hpp"

#include <glog/logging.h>

#include <memory>
#include <ostream>
#include <thread>
#include <utility>

namespace mrc::coroutines {

Expand All @@ -39,18 +35,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 +68,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