Function tryLock [src]
Acquires the Mutex without blocking the caller's thread.
Returns false if the calling thread would have to block to acquire it.
Otherwise, returns true and the caller should unlock() the Mutex to release it.
Prototype
pub fn tryLock(r: *Recursive) bool
Parameters
r: *Recursive
Source
pub fn tryLock(r: *Recursive) bool {
const current_thread_id = std.Thread.getCurrentId();
if (@atomicLoad(std.Thread.Id, &r.thread_id, .unordered) != current_thread_id) {
if (!r.mutex.tryLock()) return false;
assert(r.lock_count == 0);
@atomicStore(std.Thread.Id, &r.thread_id, current_thread_id, .unordered);
}
r.lock_count += 1;
return true;
}