Skip to content

Commit

Permalink
samples: philosophers: Switch condsync to dynamic
Browse files Browse the repository at this point in the history
Use the simpler `new` methods instead of static allocaiton.

Signed-off-by: David Brown <[email protected]>
  • Loading branch information
d3zd3z committed Oct 24, 2024
1 parent 70e2710 commit 7758fe5
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions samples/philosophers/src/condsync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::{
ForkSync,
NUM_PHIL,
};
use zephyr::kobj_define;
use zephyr::sync::Mutex;
use zephyr::sync::Condvar;
// use zephyr::time::Forever;
Expand All @@ -26,12 +25,10 @@ pub struct CondSync {
impl CondSync {
#[allow(dead_code)]
pub fn new() -> CondSync {
let sys_mutex = MUTEX.init_once(()).unwrap();
let sys_condvar = CONDVAR.init_once(()).unwrap();

let lock = Mutex::new_from([false; NUM_PHIL], sys_mutex);
let cond = Condvar::new_from(sys_condvar);
CondSync { lock, cond }
CondSync {
lock: Mutex::new([false; NUM_PHIL]),
cond: Condvar::new(),
}
}
}

Expand All @@ -51,8 +48,3 @@ impl ForkSync for CondSync {
self.cond.notify_all();
}
}

kobj_define! {
static MUTEX: StaticMutex;
static CONDVAR: StaticCondvar;
}

0 comments on commit 7758fe5

Please sign in to comment.