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"]
15
15
[dependencies ]
16
16
zephyr = " 3.7.0"
17
17
18
+ # Dependencies that are used by build.rs.
19
+ [build-dependencies ]
20
+ zephyr-build = " 3.7.0"
21
+
18
22
[profile .release ]
19
23
debug-assertions = true
20
24
overflow-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 {
27
27
}
28
28
29
29
impl CondSync {
30
+ #[ allow( dead_code) ]
30
31
pub fn new ( ) -> CondSync {
31
32
MUTEX . init ( ) ;
32
33
CONDVAR . init ( ) ;
Original file line number Diff line number Diff line change 3
3
4
4
#![ no_std]
5
5
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
+
6
11
extern crate alloc;
7
12
8
13
use alloc:: boxed:: Box ;
@@ -16,7 +21,10 @@ use zephyr::{
16
21
sync:: { Arc , Mutex } ,
17
22
} ;
18
23
24
+ // These are optional, based on Kconfig, so allow them to be unused.
25
+ #[ allow( unused_imports) ]
19
26
use crate :: condsync:: CondSync ;
27
+ #[ allow( unused_imports) ]
20
28
use crate :: sysmutex:: SysMutexSync ;
21
29
22
30
mod condsync;
@@ -86,8 +94,8 @@ extern "C" fn rust_main() {
86
94
}
87
95
}
88
96
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 > > {
91
99
// Simple mutex version.
92
100
let syncer = Box :: new ( SysMutexSync :: new ( ) )
93
101
as Box < dyn ForkSync > ;
@@ -99,6 +107,7 @@ fn get_syncerb() -> Vec<Arc<dyn ForkSync>> {
99
107
result
100
108
}
101
109
110
+ #[ cfg( CONFIG_SYNC_CONDVAR ) ]
102
111
fn get_syncer ( ) -> Vec < Arc < dyn ForkSync > > {
103
112
// Condvar version
104
113
let syncer = Box :: new ( CondSync :: new ( ) )
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ pub struct SysMutexSync {
28
28
}
29
29
30
30
impl SysMutexSync {
31
+ #[ allow( dead_code) ]
31
32
pub fn new ( ) -> SysMutexSync {
32
33
let locks = MUTEXES . each_ref ( ) . map ( |m| {
33
34
m. init ( ) ;
You can’t perform that action at this time.
0 commit comments