Struct kernel::sync::RwSemaphore
source · [−]pub struct RwSemaphore<T: ?Sized> { /* private fields */ }
Expand description
Exposes the kernel’s struct rw_semaphore
.
It’s a read/write mutex. That is, it allows multiple readers to acquire it concurrently, but only one writer at a time. On contention, waiters sleep.
A RwSemaphore
must first be initialised with a call to RwSemaphore::init_lock
before it
can be used. The rwsemaphore_init
macro is provided to automatically assign a new lock
class to an RwSemaphore
instance.
Since it may block, RwSemaphore
needs to be used with care in atomic contexts.
Implementations
sourceimpl<T> RwSemaphore<T>
impl<T> RwSemaphore<T>
sourcepub unsafe fn new(t: T) -> Self
pub unsafe fn new(t: T) -> Self
Constructs a new rw semaphore.
Safety
The caller must call RwSemaphore::init_lock
before using the rw semaphore.
Trait Implementations
sourceimpl<T: ?Sized> Lock<ReadLock> for RwSemaphore<T>
impl<T: ?Sized> Lock<ReadLock> for RwSemaphore<T>
type Inner = T
type Inner = T
The type of the data protected by the lock.
type GuardContext = EmptyGuardContext
type GuardContext = EmptyGuardContext
The type of context, if any, that needs to be stored in the guard.
sourcefn lock_noguard(&self) -> EmptyGuardContext
fn lock_noguard(&self) -> EmptyGuardContext
Acquires the lock, making the caller its owner.
sourceunsafe fn unlock(&self, _: &mut EmptyGuardContext)
unsafe fn unlock(&self, _: &mut EmptyGuardContext)
Releases the lock, giving up ownership of the lock. Read more
sourcefn locked_data(&self) -> &UnsafeCell<T>
fn locked_data(&self) -> &UnsafeCell<T>
Returns the data protected by the lock.
sourcefn relock(&self, ctx: &mut Self::GuardContext)
fn relock(&self, ctx: &mut Self::GuardContext)
Reacquires the lock, making the caller its owner. Read more
sourceimpl<T: ?Sized> Lock<WriteLock> for RwSemaphore<T>
impl<T: ?Sized> Lock<WriteLock> for RwSemaphore<T>
type Inner = T
type Inner = T
The type of the data protected by the lock.
type GuardContext = EmptyGuardContext
type GuardContext = EmptyGuardContext
The type of context, if any, that needs to be stored in the guard.
sourcefn lock_noguard(&self) -> EmptyGuardContext
fn lock_noguard(&self) -> EmptyGuardContext
Acquires the lock, making the caller its owner.
sourceunsafe fn unlock(&self, _: &mut EmptyGuardContext)
unsafe fn unlock(&self, _: &mut EmptyGuardContext)
Releases the lock, giving up ownership of the lock. Read more
sourcefn locked_data(&self) -> &UnsafeCell<T>
fn locked_data(&self) -> &UnsafeCell<T>
Returns the data protected by the lock.
sourcefn relock(&self, ctx: &mut Self::GuardContext)
fn relock(&self, ctx: &mut Self::GuardContext)
Reacquires the lock, making the caller its owner. Read more
sourceimpl<T> LockFactory for RwSemaphore<T>
impl<T> LockFactory for RwSemaphore<T>
type LockedType<U> = RwSemaphore<U>
type LockedType<U> = RwSemaphore<U>
The parametrised type of the mutual exclusion primitive that can be created by this factory.
sourceunsafe fn new_lock<U>(data: U) -> RwSemaphore<U>
unsafe fn new_lock<U>(data: U) -> RwSemaphore<U>
Constructs a new instance of the mutual exclusion primitive. Read more
sourceimpl<T> LockIniter for RwSemaphore<T>
impl<T> LockIniter for RwSemaphore<T>
impl<T: ?Sized + Send> Send for RwSemaphore<T>
impl<T: ?Sized + Send + Sync> Sync for RwSemaphore<T>
Auto Trait Implementations
impl<T> !RefUnwindSafe for RwSemaphore<T>
impl<T> !Unpin for RwSemaphore<T>
impl<T: ?Sized> UnwindSafe for RwSemaphore<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<L> NeedsLockClass for L where
L: LockIniter,
impl<L> NeedsLockClass for L where
L: LockIniter,
sourcefn init(
self: Pin<&mut L>,
name: &'static CStr,
key: &'static LockClassKey,
&'static LockClassKey
)
fn init(
self: Pin<&mut L>,
name: &'static CStr,
key: &'static LockClassKey,
&'static LockClassKey
)
Initialises the type instance so that it can be safely used. Read more