Skip to content

Commit

Permalink
Even better implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mdemoret-nv committed Jun 30, 2023
1 parent d77458d commit cfad09b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
25 changes: 22 additions & 3 deletions cpp/mrc/include/mrc/coroutines/ring_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,25 +158,44 @@ class RingBuffer
return (!m_stopped ? RingBufferOpStatus::Success : RingBufferOpStatus::Stopped);
}

WriteOperation& use_scheduling_policy(SchedulePolicy policy)
WriteOperation& use_scheduling_policy(SchedulePolicy policy) &
{
m_policy = policy;
return *this;
}

WriteOperation& resume_immediately()
WriteOperation use_scheduling_policy(SchedulePolicy policy) &&
{
m_policy = policy;
return std::move(*this);
}

WriteOperation& resume_immediately() &
{
m_policy = SchedulePolicy::Immediate;
return *this;
}

WriteOperation& resume_on(ThreadPool* thread_pool)
WriteOperation resume_immediately() &&
{
m_policy = SchedulePolicy::Immediate;
return std::move(*this);
}

WriteOperation& resume_on(ThreadPool* thread_pool) &
{
m_policy = SchedulePolicy::Reschedule;
set_resume_on_thread_pool(thread_pool);
return *this;
}

WriteOperation resume_on(ThreadPool* thread_pool) &&
{
m_policy = SchedulePolicy::Reschedule;
set_resume_on_thread_pool(thread_pool);
return std::move(*this);
}

private:
friend RingBuffer;

Expand Down
19 changes: 5 additions & 14 deletions cpp/mrc/tests/coroutines/test_ring_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,25 +216,16 @@ TEST_F(TestCoroRingBuffer, MultiProducerMultiConsumer)
{
switch (i % 3)
{
case 0: {
case 0:
co_await rb.write(i);
break;
}
case 1: {
// Must save this to a temporary to workaround compiler bug in GCC==11.3 (working in 11.2/11.4). See:
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103871#c10
auto& task = rb.write(i).resume_immediately();
co_await task;
case 1:
co_await rb.write(i).resume_immediately();
break;
}
case 2: {
// Must save this to a temporary to workaround compiler bug in GCC==11.3 (working in 11.2/11.4). See:
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103871#c10
auto& task = rb.write(i).resume_on(&tp);
co_await task;
case 2:
co_await rb.write(i).resume_on(&tp);
break;
}
}
}

producers_latch.count_down();
Expand Down

0 comments on commit cfad09b

Please sign in to comment.