Struct glock::GLock

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

Represents a granular lock object. A GLock is used to protect a data value of type T, which can only be accessed with a mutable reference after calling lock_exclusive(), try_lock_exclusive(), lock_exclusive_using_parent() or try_lock_exclusive_using_parent().

Each GLock can have zero or more child GLocks, which can be nested (i.e. placed inside the protected data) or non-nested. The same locking rules apply in both cases.

When locking a child GLock, first you need to lock its parent GLock, then lock it by calling lock_using_parent(), try_lock_using_parent(), lock_exclusive_using_parent() or lock_exclusive_using_parent(), and passing a reference to the parent’s GLockGuard.

If you do not lock the parent and proceed to lock the child GLock directly using lock(), try_lock(), lock_exclusive() or try_lock_exclusive(), an implicit lock will be acquired for the parent GLock that will be release when dropping this lock’s GLockGuard.

Implementations§

Creates a new root GLockBuilder. This is similar to calling GLockBuilder::new_root_builder().

Creates a new root GLock protecting the specified data.

Creates a GLockBuilder for a lock that is a child of the current GLock.

Creates a GLock that is a child of the current GLock, protecting the specified data.

Acquires a lock of the specified type on the current GLock. If the lock is busy, it will block until it is ready. If this is a child GLock, it will implicitly acquire the appropriate lock on its parent GLock.

If you are trying to acquire an Exclusive lock, it is better to use lock_exclusive(), because the GLockGuard returned by lock() will not allow mutation of protected data.

Attempts to acquire a lock of the specified type on the current GLock. If the lock is busy, it will return a LockError::LockBusy error. If this is a child GLock, it will implicitly attempt to acquire the appropriate lock on its parent GLock.

If you are trying to acquire an Exclusive lock, it is better to use try_lock_exclusive(), because the GLockGuard returned by try_lock() will not allow mutation of protected data.

Acquires a lock of the specified type on the current child GLock, using the specified GLockGuard of the parent GLock. If the lock is busy, it will block until it is ready.

If you are trying to acquire an Exclusive lock, it is better to use lock_exclusive_using_parent(), because the GLockGuard returned by lock_using_parent() will not allow mutation of protected data.

Attempts to acquire a lock of the specified type on the current child GLock, using the specified GLockGuard of the parent GLock. If the lock is busy, it will return a LockError::LockBusy error.

If you are trying to acquire an Exclusive lock, it is better to use try_lock_exclusive_using_parent(), because the GLockGuard returned by try_lock_using_parent() will not allow mutation of protected data.

Acquires an Exclusive lock on the current GLock. If the lock is busy, it will block until it is ready. If this is a child GLock, it will implicitly acquire the appropriate lock on its parent GLock.

The returned GLockGuardMut allows mutating the protected data.

Attempts to acquire an Exclusive lock on the current GLock. If the lock is busy, it will return a LockError::LockBusy error. If this is a child GLock, it will implicitly attempt to acquire the appropriate lock on its parent GLock.

The returned GLockGuardMut allows mutating the protected data.

Acquires an Exclusive lock on the current child GLock, using the specified GLockGuard of the parent GLock. If the lock is busy, it will block until it is ready.

The returned GLockGuardMut allows mutating the protected data.

Attempts to acquire an Exclusive lock on the current child GLock, using the specified GLockGuard of the parent GLock. If the lock is busy, it will return a LockError::LockBusy error.

The returned GLockGuardMut allows mutating the protected data.

Trait Implementations§

Formats the value using the given formatter. Read more
Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.