lock
= .{ .alloc = alloc, .resize = resize, .remap = remap, .free = free, }
Values
- vtable
- = .{ .alloc = alloc, .resize = resize, .remap = remap, .free = free, }
Source
Implementation
fn lock() *Thread {
var index = thread_index;
{
const t = &global.threads[index];
if (t.mutex.tryLock()) {
@branchHint(.likely);
return t;
}
}
const cpu_count = getCpuCount();
assert(cpu_count != 0);
while (true) {
index = (index + 1) % cpu_count;
const t = &global.threads[index];
if (t.mutex.tryLock()) {
thread_index = index;
return t;
}
}
}