Skip to content

Commit 43c0c8a

Browse files
committed
zephyr: sys: sync: Remove Clone from Mutex and Semaphore
Although these, in their current state, are safe to Clone, having these semantics will make it difficult for us to later add these types that are allocated from a pool. Uses that currently expect to clone can generally wrap these in an Arc, to allow for the sharing. Signed-off-by: David Brown <[email protected]>
1 parent 058740f commit 43c0c8a

File tree

3 files changed

+3
-7
lines changed

3 files changed

+3
-7
lines changed

samples/philosophers/src/semsync.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ use alloc::vec::Vec;
1111
use alloc::boxed::Box;
1212

1313
use zephyr::{
14-
kobj_define,
15-
sync::Arc,
16-
time::Forever,
14+
kobj_define, sync::Arc, sys::sync::Semaphore, time::Forever
1715
};
1816

1917
use crate::{ForkSync, NUM_PHIL};
@@ -22,7 +20,7 @@ use crate::{ForkSync, NUM_PHIL};
2220
pub struct SemSync {
2321
/// The forks for this philosopher. This is a big excessive, as we really don't need all of
2422
/// them, but the ForSync code uses the index here.
25-
forks: [zephyr::sys::sync::Semaphore; NUM_PHIL],
23+
forks: [Arc<Semaphore>; NUM_PHIL],
2624
}
2725

2826
impl ForkSync for SemSync {
@@ -39,7 +37,7 @@ impl ForkSync for SemSync {
3937
pub fn semaphore_sync() -> Vec<Arc<dyn ForkSync>> {
4038
let forks = SEMS.each_ref().map(|m| {
4139
// Each fork starts as taken.
42-
m.init_once((1, 1)).unwrap()
40+
Arc::new(m.init_once((1, 1)).unwrap())
4341
});
4442

4543
let syncers = (0..NUM_PHIL).map(|_| {

zephyr/src/sys/sync/mutex.rs

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ use crate::sys::K_FOREVER;
5252
/// type.
5353
///
5454
/// [`sync::Mutex`]: http://example.com/TODO
55-
#[derive(Clone)]
5655
pub struct Mutex {
5756
/// The raw Zephyr mutex.
5857
item: *mut k_mutex,

zephyr/src/sys/sync/semaphore.rs

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use crate::{
3131
pub use crate::raw::K_SEM_MAX_LIMIT;
3232

3333
/// A zephyr `k_sem` usable from safe Rust code.
34-
#[derive(Clone)]
3534
pub struct Semaphore {
3635
/// The raw Zephyr `k_sem`.
3736
item: *mut k_sem,

0 commit comments

Comments
 (0)