pspsdk 0.0.2

A SDK for creating PSP modules, including both PRX plugins and regular homebrew apps.
Documentation
//! Non-poisoning synchronous locks.
//!
//! The difference from the locks in the [`poison`] module is that the locks in this module will not
//! become poisoned when a thread panics while holding a guard.
//!
//! [`poison`]: super::poison
use core::fmt;

mod mutex;
pub use mutex::{MappedMutexGuard, Mutex, MutexGuard};

mod reentrant_lock;
pub use reentrant_lock::{ReentrantLock, ReentrantLockGuard};

mod rwlock;
pub use rwlock::{
    MappedRwLockReadGuard, MappedRwLockWriteGuard, RwLock, RwLockReadGuard, RwLockWriteGuard,
};

pub use super::poison::Once;

mod once_lock;
pub use once_lock::OnceLock;

mod condvar;
pub use condvar::Condvar;

mod lazy_lock;
pub use lazy_lock::LazyLock;

mod barrier;
pub use barrier::{Barrier, BarrierWaitResult};

/// An enumeration of possible errors associated with a [`TryLockResult`] which
/// can occur while trying to acquire a lock, from the [`try_lock`] method on a
/// [`Mutex`] or the [`try_read`] and [`try_write`] methods on an [`RwLock`].
///
/// [`try_lock`]: crate::sync::nonpoison::Mutex::try_lock
/// [`try_read`]: crate::sync::nonpoison::RwLock::try_read
/// [`try_write`]: crate::sync::nonpoison::RwLock::try_write
/// [`Mutex`]: crate::sync::nonpoison::Mutex
/// [`RwLock`]: crate::sync::nonpoison::RwLock
pub enum TryLockError {
    /// The lock could not be acquired at this time because the operation would
    /// otherwise block.
    WouldBlock,
}

/// A type alias for the result of a nonblocking locking method.
///
/// For more information, see [`LockResult`]. A `TryLockResult` doesn't
/// necessarily hold the associated guard in the [`Err`] type as the lock might not
/// have been acquired for other reasons.
///
/// [`LockResult`]: crate::sync::poison::LockResult
pub type TryLockResult<Guard> = Result<Guard, TryLockError>;


impl fmt::Debug for TryLockError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match *self {
            TryLockError::WouldBlock => "WouldBlock".fmt(f),
        }
    }
}

impl fmt::Display for TryLockError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match *self {
            TryLockError::WouldBlock => "try_lock failed because the operation would block",
        }
        .fmt(f)
    }
}

impl core::error::Error for TryLockError {}