Remove thread stuff from sync2; Cleanup package thread

This commit is contained in:
gingerBill
2021-04-11 18:25:56 +01:00
parent 52c193316b
commit 1156bd9dd0
7 changed files with 103 additions and 570 deletions
+24
View File
@@ -213,3 +213,27 @@ recursive_benaphore_unlock :: proc(b: ^Recursive_Benaphore) {
}
// outside the lock
}
Once :: struct {
m: Mutex,
done: bool,
}
once_do :: proc(o: ^Once, fn: proc()) {
if intrinsics.atomic_load_acq(&o.done) == false {
_once_do_slow(o, fn);
}
}
_once_do_slow :: proc(o: ^Once, fn: proc()) {
mutex_lock(&o.m);
defer mutex_unlock(&o.m);
if !o.done {
fn();
intrinsics.atomic_store_rel(&o.done, true);
}
}