Struct qutex::QrwLock

source ·
pub struct QrwLock<T> { /* private fields */ }
Expand description

A queue-backed read/write data lock.

As with any queue-backed system, deadlocks must be carefully avoided when interoperating with other queues.

Implementations§

source§

impl<T> QrwLock<T>

source

pub fn new(val: T) -> QrwLock<T>

Creates and returns a new QrwLock.

source

pub fn read(self) -> FutureReadGuard<T>

Returns a new FutureReadGuard which can be used as a future and will resolve into a ReadGuard.

source

pub fn write(self) -> FutureWriteGuard<T>

Returns a new FutureWriteGuard which can be used as a future and will resolve into a WriteGuard.

source

pub unsafe fn enqueue_lock_request(&self, req: QrwRequest)

Pushes a lock request onto the queue.

source

pub fn get_mut(&mut self) -> Option<&mut T>

Returns a mutable reference to the inner Vec if there are currently no other copies of this QrwLock.

Since this call borrows the inner lock mutably, no actual locking needs to take place—the mutable borrow statically guarantees no locks exist.

source

pub fn as_ptr(&self) -> *const T

Returns a reference to the inner value.

source

pub fn as_mut_ptr(&self) -> *mut T

Returns a mutable reference to the inner value.

source

pub unsafe fn process_queues(&self)

Pops the next lock request in the queue if possible.

source

pub unsafe fn upgrade_read_lock(&self) -> Result<(), Receiver<()>>

Converts a single read lock (read count of ‘1’) into a write lock.

Returns an error containing a oneshot receiver if there is currently more than one read lock. When the read count reaches one, the receiver channel will be completed (i.e. poll it).

Panics if there are no read locks.

Do not call this method directly unless you are using a custom guard or are otherwise managing the lock state manually. Use ReadGuard::upgrade instead.

source

pub unsafe fn downgrade_write_lock(&self)

Converts a write lock into a read lock then processes the queue, allowing additional read requests to acquire locks.

Use WriteGuard::downgrade rather than calling this directly.

source

pub unsafe fn release_read_lock(&self)

Decreases the reader count by one and unparks the next requester task in the queue if possible.

If a reader is waiting to be upgraded and the read lock count reaches 1, the upgrade sender will be completed.

source

pub unsafe fn release_write_lock(&self)

Unlocks this (the caller’s) lock and unparks the next requester task in the queue if possible.

Trait Implementations§

source§

impl<T> Clone for QrwLock<T>

source§

fn clone(&self) -> QrwLock<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for QrwLock<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Default> Default for QrwLock<T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<T> From<T> for QrwLock<T>

source§

fn from(val: T) -> QrwLock<T>

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T> Freeze for QrwLock<T>

§

impl<T> !RefUnwindSafe for QrwLock<T>

§

impl<T> Send for QrwLock<T>
where T: Send,

§

impl<T> Sync for QrwLock<T>
where T: Send,

§

impl<T> Unpin for QrwLock<T>

§

impl<T> !UnwindSafe for QrwLock<T>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<!> for T

source§

fn from(t: !) -> T

Converts to this type from the input type.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.