pub struct EventGroup(/* private fields */);Expand description
Event group synchronization primitives. POSIX event group: a shared, thread-safe bit field with blocking waits.
See the module-level docs above for a full example and rationale.
Implementations§
Source§impl EventGroup
impl EventGroup
Sourcepub const MAX_MASK: EventBits
pub const MAX_MASK: EventBits
Largest usable bit mask: the top byte of EventBits is reserved
for bookkeeping (mirroring FreeRTOS, which reserves its own event
group bits the same way), so only the lower bits may be used as
application flags.
§Examples
use osal_rs::os::EventGroup;
use osal_rs::os::types::EventBits;
// A normal flag bit always falls within the usable mask...
let flag: EventBits = 1 << 3;
assert_eq!(EventGroup::MAX_MASK & flag, flag);
// ...but the reserved top byte does not.
let reserved_bit: EventBits = !EventGroup::MAX_MASK;
assert_eq!(EventGroup::MAX_MASK & reserved_bit, 0);Sourcepub fn wait_with_to_tick(
&self,
mask: EventBits,
timeout_ticks: impl ToTick,
) -> EventBits
pub fn wait_with_to_tick( &self, mask: EventBits, timeout_ticks: impl ToTick, ) -> EventBits
Blocks like EventGroup::wait, but accepts any ToTick timeout
(e.g. a core::time::Duration) instead of a raw tick count.
§Examples
use osal_rs::os::*;
use core::time::Duration;
let events = EventGroup::new().unwrap();
events.set(1);
let bits = events.wait_with_to_tick(1, Duration::from_millis(50));
assert_eq!(bits & 1, 1);Methods from Deref<Target = EventGroupHandle>§
Trait Implementations§
Source§impl Debug for EventGroup
impl Debug for EventGroup
Source§impl Deref for EventGroup
impl Deref for EventGroup
Source§impl Display for EventGroup
impl Display for EventGroup
Source§impl Drop for EventGroup
impl Drop for EventGroup
Source§impl EventGroup for EventGroup
impl EventGroup for EventGroup
Source§fn is_null(&self) -> bool
fn is_null(&self) -> bool
Returns true if this event group is never-initialized-or-already-deleted.
Unlike crate::os::SemaphoreFn::is_null, the bits themselves are not
part of this check: an event group legitimately sits at 0 bits
whenever nothing has been set yet, so that can’t be used to detect
deletion.
§Examples
use osal_rs::os::*;
let mut events = EventGroup::new().unwrap();
assert!(!events.is_null());
events.delete();
assert!(events.is_null());Source§fn set(&self, bits: EventBits) -> EventBits
fn set(&self, bits: EventBits) -> EventBits
Sets bits in the group (OR’d into the current value) and wakes any
thread blocked in EventGroup::wait whose mask may now be
satisfied. Returns the resulting bits after the update.
§Examples
use osal_rs::os::*;
let events = EventGroup::new().unwrap();
let bits = events.set(0b101);
assert_eq!(bits, 0b101);
let bits = events.set(0b010);
assert_eq!(bits, 0b111);Source§fn set_from_isr(&self, bits: EventBits) -> Result<()>
fn set_from_isr(&self, bits: EventBits) -> Result<()>
ISR-safe variant of EventGroup::set. POSIX has no interrupt
context of its own, so this never blocks (trylock instead of
lock); it fails with Error::QueueFull if the mutex happens to be
contended rather than waiting for it.
§Examples
use osal_rs::os::*;
let events = EventGroup::new().unwrap();
events.set_from_isr(0b1).unwrap();
assert_eq!(events.get(), 0b1);Source§fn get(&self) -> EventBits
fn get(&self) -> EventBits
Returns the currently set bits, without waiting for any of them.
§Examples
use osal_rs::os::*;
let events = EventGroup::new().unwrap();
assert_eq!(events.get(), 0);
events.set(0b11);
assert_eq!(events.get(), 0b11);Source§fn get_from_isr(&self) -> EventBits
fn get_from_isr(&self) -> EventBits
ISR-safe variant of EventGroup::get. Falls back to a racy,
unlocked read if the mutex happens to be contended, rather than
blocking the “interrupt”.
§Examples
use osal_rs::os::*;
let events = EventGroup::new().unwrap();
events.set(0b111);
assert_eq!(events.get_from_isr(), 0b111);Source§fn clear(&self, bits: EventBits) -> EventBits
fn clear(&self, bits: EventBits) -> EventBits
Clears bits in the group and returns the value the bits held
before clearing.
§Examples
use osal_rs::os::*;
let events = EventGroup::new().unwrap();
events.set(0b111);
let previous = events.clear(0b010);
assert_eq!(previous, 0b111);
assert_eq!(events.get(), 0b101);Source§fn clear_from_isr(&self, bits: EventBits) -> Result<()>
fn clear_from_isr(&self, bits: EventBits) -> Result<()>
ISR-safe variant of EventGroup::clear. Fails with
Error::QueueFull instead of blocking if the mutex is contended.
§Examples
use osal_rs::os::*;
let events = EventGroup::new().unwrap();
events.set(0b11);
events.clear_from_isr(0b01).unwrap();
assert_eq!(events.get(), 0b10);Source§fn wait(&self, mask: EventBits, timeout_ticks: TickType) -> EventBits
fn wait(&self, mask: EventBits, timeout_ticks: TickType) -> EventBits
Blocks until every bit in mask is set, or timeout_ticks elapses
(pass TickType::MAX to wait forever), whichever comes first.
Always returns the bits actually observed, whether or not they
satisfy mask - check the return value to tell a timeout apart from
success.
§Examples
use osal_rs::os::*;
let events = EventGroup::new().unwrap();
events.set(0b01);
// Only bit 0 is set, so waiting on bit 1 too times out...
let bits = events.wait(0b11, 10);
assert_ne!(bits & 0b11, 0b11);
// ...but waiting on just the bit that's already set succeeds immediately.
let bits = events.wait(0b01, 10);
assert_eq!(bits & 0b01, 0b01);Source§fn delete(&mut self)
fn delete(&mut self)
Destroys the underlying pthread objects and resets this event group
to its “null” state. Safe to call more than once - a second call is a
no-op - and called automatically on Drop if not called explicitly.
§Examples
use osal_rs::os::*;
let mut events = EventGroup::new().unwrap();
events.delete();
assert!(events.is_null());
events.delete(); // no-op, does not panic