pool!: accept attributes

This commit is contained in:
Jorge Aparicio 2019-05-03 21:03:04 +02:00
parent 6938d75622
commit 087aa5feed
2 changed files with 9 additions and 4 deletions

View File

@ -14,7 +14,11 @@
//! use heapless::{pool, pool::singleton::Box}; //! use heapless::{pool, pool::singleton::Box};
//! //!
//! // instantiate a memory pool of `[u8; 128]` blocks as a global singleton //! // instantiate a memory pool of `[u8; 128]` blocks as a global singleton
//! pool!(A: [u8; 128]); //! pool!(
//! // attributes can be used here
//! // #[link_section = ".ccram.A"]
//! A: [u8; 128]
//! );
//! //!
//! #[entry] //! #[entry]
//! fn main() -> ! { //! fn main() -> ! {

View File

@ -18,16 +18,17 @@ use super::{Init, Uninit};
#[cfg(any(armv7m, armv7r, test))] #[cfg(any(armv7m, armv7r, test))]
#[macro_export] #[macro_export]
macro_rules! pool { macro_rules! pool {
($ident:ident: $ty:ty) => { ($(#[$($attr:tt)*])* $ident:ident: $ty:ty) => {
pub struct $ident; pub struct $ident;
impl $crate::pool::singleton::Pool for $ident { impl $crate::pool::singleton::Pool for $ident {
type Data = $ty; type Data = $ty;
fn ptr() -> &'static $crate::pool::Pool<$ty> { fn ptr() -> &'static $crate::pool::Pool<$ty> {
static POOL: $crate::pool::Pool<$ty> = $crate::pool::Pool::new(); $(#[$($attr)*])*
static $ident: $crate::pool::Pool<$ty> = $crate::pool::Pool::new();
&POOL &$ident
} }
} }
}; };