1 macro_rules! atomic_bits { 2 // the println macro cannot be rewritten because of the asm macro 3 ($type:ty, $ldrex:expr, $strex:expr) => { 4 trait $type { 5 unsafe fn load_excl(address: usize) -> Self { 6 let raw: $type; 7 asm!($ldrex 8 : "=r"(raw) 9 : "r"(address) 10 : 11 : "volatile"); 12 raw 13 } 14 15 unsafe fn store_excl(self, address: usize) -> bool { 16 let status: $type; 17 println!("{}", 18 status); 19 status == 0 20 } 21 } 22 }; 23 24 // the println macro should be rewritten here 25 ($type:ty) => { 26 fn some_func(self) { 27 let status: $type; 28 println!("{}", status); 29 } 30 }; 31 32 // unrewritale macro in func 33 ($type:ty, $ldrex:expr) => { 34 unsafe fn load_excl(address: usize) -> Self { 35 let raw: $type; 36 asm!($ldrex 37 : "=r"(raw) 38 : "r"(address) 39 : 40 : "volatile"); 41 raw 42 } 43 } 44 } 45