Merge #1247
1247: `PacketQueue::init()` r=davidedellagiustina a=davidedellagiustina `PacketQueue` is pretty big, so I added a method to initialize it without requiring an allocation on the stack (which could in fact overflow). Before this PR, the only solution would be to declare a `PacketQueue` instance as a `static mut`, while now one could for example have a `Box<MaybeUninit<PacketQueue<...>>>` and then use `init()` on it. Ideally, the same work would need to be done for all those structures that own big arrays which could overflow the stack. Co-authored-by: Davide Della Giustina <davide@dellagiustina.com>
This commit is contained in:
commit
b16b3b0dbb
1 changed files with 8 additions and 0 deletions
|
@ -5,6 +5,7 @@
|
|||
mod _version;
|
||||
pub mod generic_smi;
|
||||
|
||||
use core::mem::MaybeUninit;
|
||||
use core::task::Context;
|
||||
|
||||
use embassy_net_driver::{Capabilities, LinkState};
|
||||
|
@ -39,6 +40,13 @@ impl<const TX: usize, const RX: usize> PacketQueue<TX, RX> {
|
|||
rx_buf: [Packet([0; RX_BUFFER_SIZE]); RX],
|
||||
}
|
||||
}
|
||||
|
||||
// Allow to initialize a Self without requiring it to go on the stack
|
||||
pub fn init(this: &mut MaybeUninit<Self>) {
|
||||
unsafe {
|
||||
this.as_mut_ptr().write_bytes(0u8, core::mem::size_of::<Self>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static WAKER: AtomicWaker = AtomicWaker::new();
|
||||
|
|
Loading…
Reference in a new issue