File tree Expand file tree Collapse file tree 6 files changed +49
-2
lines changed Expand file tree Collapse file tree 6 files changed +49
-2
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,10 @@ crate-type = ["staticlib"]
1515[dependencies ]
1616zephyr = " 3.7.0"
1717
18+ # Dependencies that are used by build.rs.
19+ [build-dependencies ]
20+ zephyr-build = " 3.7.0"
21+
1822[profile .release ]
1923debug-assertions = true
2024overflow-checks = true
Original file line number Diff line number Diff line change 1+ # Copyright (c) 2024 Linaro LTD
2+ # SPDX-License-Identifier: Apache-2.0
3+
4+ mainmenu "Rust Dining Philosphers"
5+
6+ source "Kconfig.zephyr"
7+
8+ choice
9+ prompt "Select Synchronization implementation"
10+ default SYNC_CONDVAR
11+
12+ config SYNC_SYS_MUTEX
13+ bool "Use sys::Mutex to synchronize forks"
14+ help
15+ Use to have the dining philosophers sample use sys::Mutex, with one per fork, to
16+ synchronize.
17+
18+ config SYNC_CONDVAR
19+ bool "Use sync::Condvar and sync::Mutex to synchronize forks"
20+ help
21+ Use to have the dining philosophers sample use a single data structure, protected
22+ by a sync::Mutex and coordinated with a sync::Condvar, to synchronize.
23+ endchoice
Original file line number Diff line number Diff line change 1+ // Copyright (c) 2023 Linaro LTD
2+ // SPDX-License-Identifier: Apache-2.0
3+
4+ // This crate needs access to kconfig variables. This is an example of how to do that. The
5+ // zephyr-build must be a build dependency.
6+
7+ fn main ( ) {
8+ zephyr_build:: export_bool_kconfig ( ) ;
9+ }
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ pub struct CondSync {
2727}
2828
2929impl CondSync {
30+ #[ allow( dead_code) ]
3031 pub fn new ( ) -> CondSync {
3132 MUTEX . init ( ) ;
3233 CONDVAR . init ( ) ;
Original file line number Diff line number Diff line change 33
44#![ no_std]
55
6+ // Cargo tries to detect configs that have typos in them. Unfortunately, the Zephyr Kconfig system
7+ // uses a large number of Kconfigs and there is no easy way to know which ones might conceivably be
8+ // valid. This prevents a warning about each cfg that is used.
9+ #![ allow( unexpected_cfgs) ]
10+
611extern crate alloc;
712
813use alloc:: boxed:: Box ;
@@ -16,7 +21,10 @@ use zephyr::{
1621 sync:: { Arc , Mutex } ,
1722} ;
1823
24+ // These are optional, based on Kconfig, so allow them to be unused.
25+ #[ allow( unused_imports) ]
1926use crate :: condsync:: CondSync ;
27+ #[ allow( unused_imports) ]
2028use crate :: sysmutex:: SysMutexSync ;
2129
2230mod condsync;
@@ -86,8 +94,8 @@ extern "C" fn rust_main() {
8694 }
8795}
8896
89- #[ allow ( dead_code ) ]
90- fn get_syncerb ( ) -> Vec < Arc < dyn ForkSync > > {
97+ #[ cfg ( CONFIG_SYNC_SYS_MUTEX ) ]
98+ fn get_syncer ( ) -> Vec < Arc < dyn ForkSync > > {
9199 // Simple mutex version.
92100 let syncer = Box :: new ( SysMutexSync :: new ( ) )
93101 as Box < dyn ForkSync > ;
@@ -99,6 +107,7 @@ fn get_syncerb() -> Vec<Arc<dyn ForkSync>> {
99107 result
100108}
101109
110+ #[ cfg( CONFIG_SYNC_CONDVAR ) ]
102111fn get_syncer ( ) -> Vec < Arc < dyn ForkSync > > {
103112 // Condvar version
104113 let syncer = Box :: new ( CondSync :: new ( ) )
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ pub struct SysMutexSync {
2828}
2929
3030impl SysMutexSync {
31+ #[ allow( dead_code) ]
3132 pub fn new ( ) -> SysMutexSync {
3233 let locks = MUTEXES . each_ref ( ) . map ( |m| {
3334 m. init ( ) ;
You can’t perform that action at this time.
0 commit comments