DoxigAlpha

tryLockShared

Attempts to obtain shared lock ownership. Returns true if the lock is obtained, false otherwise.

Function parameters

Parameters

#
rwl:*SingleThreadedRwLock

Single-threaded applications use this for deadlock checks in

Types

#
SingleThreadedRwLock
Single-threaded applications use this for deadlock checks in

Attempts to obtain exclusive lock ownership.

Functions

#
tryLock
Attempts to obtain exclusive lock ownership.
lock
Blocks until exclusive lock ownership is acquired.
unlock
Releases a held exclusive lock.
tryLockShared
Attempts to obtain shared lock ownership.
lockShared
Obtains shared lock ownership.
unlockShared
Releases a held shared lock.

Source

Implementation

#
pub fn tryLockShared(rwl: *SingleThreadedRwLock) bool {
    switch (rwl.state) {
        .unlocked => {
            rwl.state = .locked_shared;
            assert(rwl.shared_count == 0);
            rwl.shared_count = 1;
            return true;
        },
        .locked_shared => {
            rwl.shared_count += 1;
            return true;
        },
        .locked_exclusive => return false,
    }
}