pub use implementation::{Barrier, BarrierWaitResult};
#[cfg(feature = "std")]
use std::sync as implementation;
#[cfg(not(feature = "std"))]
mod implementation {
use core::fmt;
pub struct Barrier {
inner: spin::Barrier,
}
impl Barrier {
#[must_use]
pub const fn new(n: usize) -> Self {
Self {
inner: spin::Barrier::new(n),
}
}
pub fn wait(&self) -> BarrierWaitResult {
BarrierWaitResult {
inner: self.inner.wait(),
}
}
}
impl fmt::Debug for Barrier {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Barrier").finish_non_exhaustive()
}
}
pub struct BarrierWaitResult {
inner: spin::barrier::BarrierWaitResult,
}
impl BarrierWaitResult {
#[must_use]
pub fn is_leader(&self) -> bool {
self.inner.is_leader()
}
}
impl fmt::Debug for BarrierWaitResult {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("BarrierWaitResult")
.field("is_leader", &self.is_leader())
.finish()
}
}
}