mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Remove unneeded semicolons from the core library
This commit is contained in:
@@ -11,36 +11,36 @@ Wait_Group :: struct {
|
||||
|
||||
wait_group_add :: proc(wg: ^Wait_Group, delta: int) {
|
||||
if delta == 0 {
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
mutex_lock(&wg.mutex);
|
||||
defer mutex_unlock(&wg.mutex);
|
||||
mutex_lock(&wg.mutex)
|
||||
defer mutex_unlock(&wg.mutex)
|
||||
|
||||
atomic_add(&wg.counter, delta);
|
||||
atomic_add(&wg.counter, delta)
|
||||
if wg.counter < 0 {
|
||||
panic("sync.Wait_Group negative counter");
|
||||
panic("sync.Wait_Group negative counter")
|
||||
}
|
||||
if wg.counter == 0 {
|
||||
cond_broadcast(&wg.cond);
|
||||
cond_broadcast(&wg.cond)
|
||||
if wg.counter != 0 {
|
||||
panic("sync.Wait_Group misuse: sync.wait_group_add called concurrently with sync.wait_group_wait");
|
||||
panic("sync.Wait_Group misuse: sync.wait_group_add called concurrently with sync.wait_group_wait")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wait_group_done :: proc(wg: ^Wait_Group) {
|
||||
wait_group_add(wg, -1);
|
||||
wait_group_add(wg, -1)
|
||||
}
|
||||
|
||||
wait_group_wait :: proc(wg: ^Wait_Group) {
|
||||
mutex_lock(&wg.mutex);
|
||||
defer mutex_unlock(&wg.mutex);
|
||||
mutex_lock(&wg.mutex)
|
||||
defer mutex_unlock(&wg.mutex)
|
||||
|
||||
if wg.counter != 0 {
|
||||
cond_wait(&wg.cond, &wg.mutex);
|
||||
cond_wait(&wg.cond, &wg.mutex)
|
||||
if wg.counter != 0 {
|
||||
panic("sync.Wait_Group misuse: sync.wait_group_add called concurrently with sync.wait_group_wait");
|
||||
panic("sync.Wait_Group misuse: sync.wait_group_add called concurrently with sync.wait_group_wait")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,29 +94,29 @@ Barrier :: struct {
|
||||
}
|
||||
|
||||
barrier_init :: proc(b: ^Barrier, thread_count: int) {
|
||||
b.index = 0;
|
||||
b.generation_id = 0;
|
||||
b.thread_count = thread_count;
|
||||
b.index = 0
|
||||
b.generation_id = 0
|
||||
b.thread_count = thread_count
|
||||
}
|
||||
|
||||
// Block the current thread until all threads have rendezvoused
|
||||
// Barrier can be reused after all threads rendezvoused once, and can be used continuously
|
||||
barrier_wait :: proc(b: ^Barrier) -> (is_leader: bool) {
|
||||
mutex_lock(&b.mutex);
|
||||
defer mutex_unlock(&b.mutex);
|
||||
local_gen := b.generation_id;
|
||||
b.index += 1;
|
||||
mutex_lock(&b.mutex)
|
||||
defer mutex_unlock(&b.mutex)
|
||||
local_gen := b.generation_id
|
||||
b.index += 1
|
||||
if b.index < b.thread_count {
|
||||
for local_gen == b.generation_id && b.index < b.thread_count {
|
||||
cond_wait(&b.cond, &b.mutex);
|
||||
cond_wait(&b.cond, &b.mutex)
|
||||
}
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
|
||||
b.index = 0;
|
||||
b.generation_id += 1;
|
||||
cond_broadcast(&b.cond);
|
||||
return true;
|
||||
b.index = 0
|
||||
b.generation_id += 1
|
||||
cond_broadcast(&b.cond)
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -129,23 +129,23 @@ Auto_Reset_Event :: struct {
|
||||
}
|
||||
|
||||
auto_reset_event_signal :: proc(e: ^Auto_Reset_Event) {
|
||||
old_status := atomic_load_relaxed(&e.status);
|
||||
old_status := atomic_load_relaxed(&e.status)
|
||||
for {
|
||||
new_status := old_status + 1 if old_status < 1 else 1;
|
||||
new_status := old_status + 1 if old_status < 1 else 1
|
||||
if _, ok := atomic_compare_exchange_weak_release(&e.status, old_status, new_status); ok {
|
||||
break;
|
||||
break
|
||||
}
|
||||
|
||||
if old_status < 0 {
|
||||
sema_post(&e.sema);
|
||||
sema_post(&e.sema)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto_reset_event_wait :: proc(e: ^Auto_Reset_Event) {
|
||||
old_status := atomic_sub_acquire(&e.status, 1);
|
||||
old_status := atomic_sub_acquire(&e.status, 1)
|
||||
if old_status < 1 {
|
||||
sema_wait(&e.sema);
|
||||
sema_wait(&e.sema)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,14 +157,14 @@ Ticket_Mutex :: struct {
|
||||
}
|
||||
|
||||
ticket_mutex_lock :: #force_inline proc(m: ^Ticket_Mutex) {
|
||||
ticket := atomic_add_relaxed(&m.ticket, 1);
|
||||
ticket := atomic_add_relaxed(&m.ticket, 1)
|
||||
for ticket != atomic_load_acquire(&m.serving) {
|
||||
cpu_relax();
|
||||
cpu_relax()
|
||||
}
|
||||
}
|
||||
|
||||
ticket_mutex_unlock :: #force_inline proc(m: ^Ticket_Mutex) {
|
||||
atomic_add_relaxed(&m.serving, 1);
|
||||
atomic_add_relaxed(&m.serving, 1)
|
||||
}
|
||||
|
||||
|
||||
@@ -176,18 +176,18 @@ Benaphore :: struct {
|
||||
|
||||
benaphore_lock :: proc(b: ^Benaphore) {
|
||||
if atomic_add_acquire(&b.counter, 1) > 1 {
|
||||
sema_wait(&b.sema);
|
||||
sema_wait(&b.sema)
|
||||
}
|
||||
}
|
||||
|
||||
benaphore_try_lock :: proc(b: ^Benaphore) -> bool {
|
||||
v, _ := atomic_compare_exchange_strong_acquire(&b.counter, 1, 0);
|
||||
return v == 0;
|
||||
v, _ := atomic_compare_exchange_strong_acquire(&b.counter, 1, 0)
|
||||
return v == 0
|
||||
}
|
||||
|
||||
benaphore_unlock :: proc(b: ^Benaphore) {
|
||||
if atomic_sub_release(&b.counter, 1) > 0 {
|
||||
sema_post(&b.sema);
|
||||
sema_post(&b.sema)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,43 +199,43 @@ Recursive_Benaphore :: struct {
|
||||
}
|
||||
|
||||
recursive_benaphore_lock :: proc(b: ^Recursive_Benaphore) {
|
||||
tid := current_thread_id();
|
||||
tid := current_thread_id()
|
||||
if atomic_add_acquire(&b.counter, 1) > 1 {
|
||||
if tid != b.owner {
|
||||
sema_wait(&b.sema);
|
||||
sema_wait(&b.sema)
|
||||
}
|
||||
}
|
||||
// inside the lock
|
||||
b.owner = tid;
|
||||
b.recursion += 1;
|
||||
b.owner = tid
|
||||
b.recursion += 1
|
||||
}
|
||||
|
||||
recursive_benaphore_try_lock :: proc(b: ^Recursive_Benaphore) -> bool {
|
||||
tid := current_thread_id();
|
||||
tid := current_thread_id()
|
||||
if b.owner == tid {
|
||||
atomic_add_acquire(&b.counter, 1);
|
||||
atomic_add_acquire(&b.counter, 1)
|
||||
}
|
||||
|
||||
if v, _ := atomic_compare_exchange_strong_acquire(&b.counter, 1, 0); v != 0 {
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
// inside the lock
|
||||
b.owner = tid;
|
||||
b.recursion += 1;
|
||||
return true;
|
||||
b.owner = tid
|
||||
b.recursion += 1
|
||||
return true
|
||||
}
|
||||
|
||||
recursive_benaphore_unlock :: proc(b: ^Recursive_Benaphore) {
|
||||
tid := current_thread_id();
|
||||
assert(tid == b.owner);
|
||||
b.recursion -= 1;
|
||||
recursion := b.recursion;
|
||||
tid := current_thread_id()
|
||||
assert(tid == b.owner)
|
||||
b.recursion -= 1
|
||||
recursion := b.recursion
|
||||
if recursion == 0 {
|
||||
b.owner = 0;
|
||||
b.owner = 0
|
||||
}
|
||||
if atomic_sub_release(&b.counter, 1) > 0 {
|
||||
if recursion == 0 {
|
||||
sema_post(&b.sema);
|
||||
sema_post(&b.sema)
|
||||
}
|
||||
}
|
||||
// outside the lock
|
||||
@@ -252,16 +252,16 @@ Once :: struct {
|
||||
|
||||
once_do :: proc(o: ^Once, fn: proc()) {
|
||||
if atomic_load_acquire(&o.done) == false {
|
||||
_once_do_slow(o, fn);
|
||||
_once_do_slow(o, fn)
|
||||
}
|
||||
}
|
||||
|
||||
@(cold)
|
||||
_once_do_slow :: proc(o: ^Once, fn: proc()) {
|
||||
mutex_lock(&o.m);
|
||||
defer mutex_unlock(&o.m);
|
||||
mutex_lock(&o.m)
|
||||
defer mutex_unlock(&o.m)
|
||||
if !o.done {
|
||||
fn();
|
||||
atomic_store_release(&o.done, true);
|
||||
fn()
|
||||
atomic_store_release(&o.done, true)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user