File tree Expand file tree Collapse file tree 3 files changed +33
-5
lines changed Expand file tree Collapse file tree 3 files changed +33
-5
lines changed Original file line number Diff line number Diff line change @@ -40,3 +40,12 @@ choice
40
40
channels to synchronize.
41
41
42
42
endchoice
43
+
44
+ if SYNC_CHANNEL
45
+ config USE_BOUNDED_CHANNELS
46
+ bool "Should channel sync use dounded channels?"
47
+ default y
48
+ help
49
+ If set, the channel-based communication will use bounded channels with bounds calculated
50
+ to not ever block.
51
+ endif
Original file line number Diff line number Diff line change @@ -32,8 +32,15 @@ tests:
32
32
min_ram : 32
33
33
extra_configs :
34
34
- CONFIG_SYNC_CONDVAR=y
35
- sample.rust.philosopher.channel :
35
+ sample.rust.philosopher.channel_bounded :
36
36
tags : introduction
37
37
min_ram : 32
38
38
extra_configs :
39
39
- CONFIG_SYNC_CHANNEL=y
40
+ - CONFIG_USE_BOUNDED_CHANNELS=y
41
+ sample.rust.philosopher.channel_unbounded :
42
+ tags : introduction
43
+ min_ram : 32
44
+ extra_configs :
45
+ - CONFIG_SYNC_CHANNEL=y
46
+ - CONFIG_USE_BOUNDED_CHANNELS=n
Original file line number Diff line number Diff line change @@ -112,10 +112,22 @@ impl ChannelSync {
112
112
/// Generate a syncer out of a ChannelSync.
113
113
#[ allow( dead_code) ]
114
114
pub fn get_channel_syncer ( ) -> Vec < Arc < dyn ForkSync > > {
115
- let ( cq_send, cq_recv) = channel:: unbounded ( ) ;
116
- let reply_queues = [ ( ) ; NUM_PHIL ] . each_ref ( ) . map ( |( ) | {
117
- channel:: unbounded ( )
118
- } ) ;
115
+ let ( cq_send, cq_recv) ;
116
+ let reply_queues;
117
+
118
+ if cfg ! ( CONFIG_USE_BOUNDED_CHANNELS ) {
119
+ // Use only one message, so that send will block, to ensure that works.
120
+ ( cq_send, cq_recv) = channel:: bounded ( 1 ) ;
121
+ reply_queues = [ ( ) ; NUM_PHIL ] . each_ref ( ) . map ( |( ) | {
122
+ channel:: bounded ( 1 )
123
+ } ) ;
124
+ } else {
125
+ ( cq_send, cq_recv) = channel:: unbounded ( ) ;
126
+ reply_queues = [ ( ) ; NUM_PHIL ] . each_ref ( ) . map ( |( ) | {
127
+ channel:: unbounded ( )
128
+ } ) ;
129
+ }
130
+
119
131
let syncer = reply_queues. into_iter ( ) . map ( |rqueue| {
120
132
let item = Box :: new ( ChannelSync :: new ( cq_send. clone ( ) , rqueue) )
121
133
as Box < dyn ForkSync > ;
You can’t perform that action at this time.
0 commit comments