Skip to content

Commit

Permalink
zephyr: object: Reorder declarations
Browse files Browse the repository at this point in the history
Move the Wrapped trait above the StaticKernelObject so that the traits
are immediately declared after the type the apply to.

Signed-off-by: David Brown <[email protected]>
  • Loading branch information
d3zd3z committed Oct 22, 2024
1 parent 93448bf commit 058740f
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions zephyr/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,28 +91,6 @@ use crate::sync::atomic::{AtomicUsize, Ordering};
// the mutations happen from C code, so this is less important than the data being placed in the
// proper section. Many will have the link section overridden by the `kobj_define` macro.

/// A kernel object represented statically in Rust code.
///
/// These should not be declared directly by the user, as they generally need linker decorations to
/// be properly registered in Zephyr as kernel objects. The object has the underlying Zephyr type
/// T, and the wrapper type W.
///
/// Kernel objects will have their `StaticThing` implemented as `StaticKernelObject<kobj>` where
/// `kobj` is the type of the underlying Zephyr object. `Thing` will usually be a struct with a
/// single field, which is a `*mut kobj`.
///
/// TODO: Can we avoid the public fields with a const new method?
///
/// TODO: Handling const-defined alignment for these.
pub struct StaticKernelObject<T> {
#[allow(dead_code)]
/// The underlying zephyr kernel object.
pub value: UnsafeCell<T>,
/// Initialization status of this object. Most objects will start uninitialized and be
/// initialized manually.
pub init: AtomicUsize,
}

/// Define the Wrapping of a kernel object.
///
/// This trait defines the association between a static kernel object and the two associated Rust
Expand Down Expand Up @@ -154,6 +132,28 @@ pub const KOBJ_INITING: usize = 1;
/// take has been called. And shouldn't be allowed additional times.
pub const KOBJ_INITIALIZED: usize = 2;

/// A kernel object represented statically in Rust code.
///
/// These should not be declared directly by the user, as they generally need linker decorations to
/// be properly registered in Zephyr as kernel objects. The object has the underlying Zephyr type
/// T, and the wrapper type W.
///
/// Kernel objects will have their `StaticThing` implemented as `StaticKernelObject<kobj>` where
/// `kobj` is the type of the underlying Zephyr object. `Thing` will usually be a struct with a
/// single field, which is a `*mut kobj`.
///
/// TODO: Can we avoid the public fields with a const new method?
///
/// TODO: Handling const-defined alignment for these.
pub struct StaticKernelObject<T> {
#[allow(dead_code)]
/// The underlying zephyr kernel object.
pub value: UnsafeCell<T>,
/// Initialization status of this object. Most objects will start uninitialized and be
/// initialized manually.
pub init: AtomicUsize,
}

impl<T> StaticKernelObject<T>
where
StaticKernelObject<T>: Wrapped,
Expand Down

0 comments on commit 058740f

Please sign in to comment.