fn lock() *Thread 74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93 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;
}
}
}