#![no_main] #![cfg_attr(target_os = "none", no_std)] use rt::sync::event; const N: i32 = 10; rt::event!(EVENT); const EVENT_A: u32 = 1 << 0; const EVENT_B: u32 = 1 << 1; const EVENT_C: u32 = 1 << 2; const EVENT_D: u32 = 1 << 3; fn setter() { rt::task::drop_privilege(); for _ in 0..N { rt::task::sleep(3); EVENT.set(EVENT_A); rt::task::sleep(3); EVENT.set(EVENT_B); rt::task::sleep(4); EVENT.set(EVENT_C); } rt::task::sleep(20); EVENT.set(EVENT_A | EVENT_B | EVENT_C); } fn waiter_one_noclear() { rt::task::drop_privilege(); const WAIT: u32 = EVENT_B | EVENT_D | event::WAIT_NOCLEAR; for _ in 0..N { let bits = EVENT.timed_wait(WAIT, 15); assert!(event::bits_match(bits, WAIT), "wait timed out"); } } fn waiter_all() { rt::task::drop_privilege(); const WAIT: u32 = EVENT_A | EVENT_B | EVENT_C | event::WAIT_ALL; for _ in 0..N { let bits = EVENT.timed_wait(WAIT, 15); assert!(event::bits_match(bits, WAIT), "wait timed out"); } let bits = EVENT.timed_wait(WAIT, 10); assert!(!event::bits_match(bits, WAIT), "wait didn't time out"); rt::trap(); } const STACK_SIZE: usize = rt::stack::MIN * 2; rt::task!(setter, STACK_SIZE, 2); rt::task!(waiter_one_noclear, STACK_SIZE, 0); rt::task!(waiter_all, STACK_SIZE, 1);