Skip to content

Relax restrictions on capacity of buffered_channel#341

Open
eoan-ermine wants to merge 1 commit into
boostorg:developfrom
eoan-ermine:issue/329
Open

Relax restrictions on capacity of buffered_channel#341
eoan-ermine wants to merge 1 commit into
boostorg:developfrom
eoan-ermine:issue/329

Conversation

@eoan-ermine
Copy link
Copy Markdown
Contributor

@eoan-ermine eoan-ermine commented May 30, 2026

Relax restrictions on capacity of buffered_channel (allow capacity that's not a power of two)

There's no reasons for such restriction since 0a6384d. Also implement tests for "capacity is not a power of two" case

Closes #329

…at's not a power of two)

There's no reasons for such restriction since 0a6384d. Also implement tests for "capacity is not a power of two" case
Copilot AI review requested due to automatic review settings May 30, 2026 20:55
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Relaxes the buffered_channel capacity precondition by removing the power-of-two requirement (only capacity >= 2 is now required), and updates the post/dispatch test suites to exercise channels with both power-of-two and non-power-of-two sizes via BOOST_PARAM_TEST_CASE.

Changes:

  • Drop the 0 == (capacity & (capacity-1)) check from buffered_channel's constructor and update the documentation accordingly.
  • Convert most buffered_channel post/dispatch tests to parameterized tests that take a channel_size argument, run against both {2,3} and {16,17}.
  • Adapt fill-up/timeout tests to push channel_size - 1 items before expecting full/timeout.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
include/boost/fiber/buffered_channel.hpp Loosens the capacity validity check to capacity >= 2.
doc/buffered_channel.qbk Documents the relaxed precondition / error condition.
test/test_buffered_channel_post.cpp Parameterizes tests over channel sizes and updates fill/timeout logic.
test/test_buffered_channel_dispatch.cpp Same parameterization for the dispatch-launch test variant.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +67 to 70
if ( BOOST_UNLIKELY( capacity_ < 2 ) ) {
throw fiber_error{ std::make_error_code( std::errc::invalid_argument),
"boost fiber: buffer capacity is invalid" };
}
Comment on lines +468 to 469
void test_rangefor(size_t channel_size) {
boost::fibers::buffered_channel< int > chan{ 2 };
Comment on lines +470 to 471
void test_rangefor(size_t channel_size) {
boost::fibers::buffered_channel< int > chan{ 4 };
Comment on lines +501 to +502
auto size_2 = { 2, 3 };
auto size_16 = { 16, 17 };
Comment on lines +82 to +87
void test_try_push_full(size_t channel_size) {
boost::fibers::buffered_channel< int > c ( channel_size);
for (int i = 1; i != static_cast<int>( channel_size); ++i) {
BOOST_CHECK( boost::fibers::channel_op_status::success == c.try_push( i) );
}
BOOST_CHECK( boost::fibers::channel_op_status::full == c.try_push( channel_size) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Does buffered_channel really need a power of two capacity ?

2 participants