Skip to content

Implement Bounded channels #33

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

Merged
merged 14 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ jobs:
lscpu
df -h

west twister -M all -T samples -T tests -v --inline-logs --integration -j 4 \
../zephyr/scripts/twister -M all -T samples -T tests -v --inline-logs --integration -j 4 \
--timeout-multiplier 2 \
$(cat etc/platforms.txt)
9 changes: 9 additions & 0 deletions samples/philosophers/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,12 @@ choice
channels to synchronize.

endchoice

if SYNC_CHANNEL
config USE_BOUNDED_CHANNELS
bool "Should channel sync use bounded channels?"
default y
help
If set, the channel-based communication will use bounded channels with bounds calculated
to not ever block.
endif
9 changes: 8 additions & 1 deletion samples/philosophers/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@ tests:
min_ram: 32
extra_configs:
- CONFIG_SYNC_CONDVAR=y
sample.rust.philosopher.channel:
sample.rust.philosopher.channel_bounded:
tags: introduction
min_ram: 32
extra_configs:
- CONFIG_SYNC_CHANNEL=y
- CONFIG_USE_BOUNDED_CHANNELS=y
sample.rust.philosopher.channel_unbounded:
tags: introduction
min_ram: 32
extra_configs:
- CONFIG_SYNC_CHANNEL=y
- CONFIG_USE_BOUNDED_CHANNELS=n
20 changes: 16 additions & 4 deletions samples/philosophers/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,22 @@ impl ChannelSync {
/// Generate a syncer out of a ChannelSync.
#[allow(dead_code)]
pub fn get_channel_syncer() -> Vec<Arc<dyn ForkSync>> {
let (cq_send, cq_recv) = channel::unbounded();
let reply_queues = [(); NUM_PHIL].each_ref().map(|()| {
channel::unbounded()
});
let (cq_send, cq_recv);
let reply_queues;

if cfg!(CONFIG_USE_BOUNDED_CHANNELS) {
// Use only one message, so that send will block, to ensure that works.
(cq_send, cq_recv) = channel::bounded(1);
reply_queues = [(); NUM_PHIL].each_ref().map(|()| {
channel::bounded(1)
});
} else {
(cq_send, cq_recv) = channel::unbounded();
reply_queues = [(); NUM_PHIL].each_ref().map(|()| {
channel::unbounded()
});
}

let syncer = reply_queues.into_iter().map(|rqueue| {
let item = Box::new(ChannelSync::new(cq_send.clone(), rqueue))
as Box<dyn ForkSync>;
Expand Down
Loading