Skip to content

Commit 4783c71

Browse files
committed
zephyr: kobj_define: Add sys Mutex and sys Condvar
Add support for declaring static instances and arrays of the sys Mutex and sys Condvar. Signed-off-by: David Brown <[email protected]>
1 parent 46113b1 commit 4783c71

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

zephyr/src/object.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,40 @@ macro_rules! _kobj_rule {
236236
unsafe { ::core::mem::zeroed() };
237237
};
238238

239+
// static NAME: StaticMutex
240+
($v:vis, $name:ident, StaticMutex) => {
241+
#[link_section = concat!("._k_mutex.static.", stringify!($name), ".", file!(), line!())]
242+
$v static $name: $crate::sys::sync::StaticMutex =
243+
$crate::sys::sync::StaticMutex::new();
244+
};
245+
246+
// static NAMES: [StaticMutex; COUNT];
247+
($v:vis, $name:ident, [StaticMutex; $size:expr]) => {
248+
#[link_section = concat!("._k_mutex.static.", stringify!($name), ".", file!(), line!())]
249+
$v static $name: [$crate::sys::sync::StaticMutex; $size] =
250+
// This isn't Copy, intentionally, so initialize the whole thing with zerored memory.
251+
// Relying on the atomic to be 0 for the uninitialized state.
252+
// [$crate::sys::sync::StaticMutex::new(); $size];
253+
unsafe { ::core::mem::zeroed() };
254+
};
255+
256+
// static NAME: StaticCondvar;
257+
($v:vis, $name:ident, StaticCondvar) => {
258+
#[link_section = concat!("._k_condvar.static.", stringify!($name), ".", file!(), line!())]
259+
$v static $name: $crate::sys::sync::StaticCondvar =
260+
$crate::sys::sync::StaticCondvar::new();
261+
};
262+
263+
// static NAMES: [StaticCondvar; COUNT];
264+
($v:vis, $name:ident, [StaticCondvar; $size:expr]) => {
265+
#[link_section = concat!("._k_condvar.static.", stringify!($name), ".", file!(), line!())]
266+
$v static $name: [$crate::sys::sync::StaticCondvar; $size] =
267+
// This isn't Copy, intentionally, so initialize the whole thing with zerored memory.
268+
// Relying on the atomic to be 0 for the uninitialized state.
269+
// [$crate::sys::sync::StaticMutex::new(); $size];
270+
unsafe { ::core::mem::zeroed() };
271+
};
272+
239273
// static THREAD: staticThread;
240274
($v:vis, $name:ident, StaticThread) => {
241275
// Since the static object has an atomic that we assume is initialized, we cannot use the

0 commit comments

Comments
 (0)