Function lock [src]

Acquires the Mutex, blocking the current thread while the mutex is already held by another thread. The Mutex can be held multiple times by the same thread. Once acquired, call unlock on the Mutex to release it, regardless of whether the lock was already held by the same thread.

Prototype

pub fn lock(r: *Recursive) void

Parameters

r: *Recursive

Source

pub fn lock(r: *Recursive) void { const current_thread_id = std.Thread.getCurrentId(); if (@atomicLoad(std.Thread.Id, &r.thread_id, .unordered) != current_thread_id) { r.mutex.lock(); assert(r.lock_count == 0); @atomicStore(std.Thread.Id, &r.thread_id, current_thread_id, .unordered); } r.lock_count += 1; }