Comma for all field separators; Overloaded procedures follow exportation rules

This commit is contained in:
Ginger Bill
2017-01-17 18:47:38 +00:00
parent 383f5b55ad
commit cb59c1cf08
14 changed files with 439 additions and 285 deletions
+18 -18
View File
@@ -2,14 +2,14 @@
#import "atomic.odin";
Semaphore :: struct {
handle: win32.HANDLE;
handle: win32.HANDLE,
}
Mutex :: struct {
semaphore: Semaphore;
counter: i32;
owner: i32;
recursion: i32;
semaphore: Semaphore,
counter: i32,
owner: i32,
recursion: i32,
}
current_thread_id :: proc() -> i32 {
@@ -36,8 +36,8 @@ semaphore_wait :: proc(s: ^Semaphore) {
mutex_init :: proc(m: ^Mutex) {
atomic.store32(^m.counter, 0);
atomic.store32(^m.owner, current_thread_id());
atomic.store(^m.counter, 0);
atomic.store(^m.owner, current_thread_id());
semaphore_init(^m.semaphore);
m.recursion = 0;
}
@@ -46,27 +46,27 @@ mutex_destroy :: proc(m: ^Mutex) {
}
mutex_lock :: proc(m: ^Mutex) {
thread_id := current_thread_id();
if atomic.fetch_add32(^m.counter, 1) > 0 {
if thread_id != atomic.load32(^m.owner) {
if atomic.fetch_add(^m.counter, 1) > 0 {
if thread_id != atomic.load(^m.owner) {
semaphore_wait(^m.semaphore);
}
}
atomic.store32(^m.owner, thread_id);
atomic.store(^m.owner, thread_id);
m.recursion += 1;
}
mutex_try_lock :: proc(m: ^Mutex) -> bool {
thread_id := current_thread_id();
if atomic.load32(^m.owner) == thread_id {
atomic.fetch_add32(^m.counter, 1);
if atomic.load(^m.owner) == thread_id {
atomic.fetch_add(^m.counter, 1);
} else {
expected: i32 = 0;
if atomic.load32(^m.counter) != 0 {
if atomic.load(^m.counter) != 0 {
return false;
}
if atomic.compare_exchange32(^m.counter, expected, 1) == 0 {
if atomic.compare_exchange(^m.counter, expected, 1) == 0 {
return false;
}
atomic.store32(^m.owner, thread_id);
atomic.store(^m.owner, thread_id);
}
m.recursion += 1;
return true;
@@ -74,15 +74,15 @@ mutex_try_lock :: proc(m: ^Mutex) -> bool {
mutex_unlock :: proc(m: ^Mutex) {
recursion: i32;
thread_id := current_thread_id();
assert(thread_id == atomic.load32(^m.owner));
assert(thread_id == atomic.load(^m.owner));
m.recursion -= 1;
recursion = m.recursion;
if recursion == 0 {
atomic.store32(^m.owner, thread_id);
atomic.store(^m.owner, thread_id);
}
if atomic.fetch_add32(^m.counter, -1) > 1 {
if atomic.fetch_add(^m.counter, -1) > 1 {
if recursion == 0 {
semaphore_release(^m.semaphore);
}