Thread synchronization

#import "std/sync"

Multiplatform implementation of various thread synchronization tools.

TODO: Improve documentation.

std.Mutex

Mutex :: _sync_impl.Mutex

Mutex type.

File: sync.bl

std.Condition

Condition :: _sync_impl.Condition

File: sync.bl

std.Semaphore

Semaphore :: struct {
    mutex: Mutex;
    cond: Condition;
    value: u32;
}

File: sync.bl

std.mutex_init

mutex_init :: fn (mutex: *Mutex) Error #inline

Initialize mutex. Call mutex_terminate when mutex is no longer needed.

File: sync.bl

std.mutex_terminate

mutex_terminate :: fn (mutex: *Mutex) Error #inline

Terminate mutex.

File: sync.bl

std.mutex_lock

mutex_lock :: fn (mutex: *Mutex) Error #inline

Lock mutex and enter critical section.

File: sync.bl

std.mutex_try_lock

mutex_try_lock :: fn (mutex: *Mutex) (_0: bool, _1: Error) #inline

Try to lock the mutex. Returns true in case the mutex was locked or false if mutex is already locked or en error occurred.

File: sync.bl

std.mutex_unlock

mutex_unlock :: fn (mutex: *Mutex) Error #inline

Unlock previously locked mutex and leave critical section.

File: sync.bl

std.semaphore_init

semaphore_init :: fn (sem: *Semaphore, v : u32: 0) Error #inline

Initialize semaphore object with value.

File: sync.bl

std.semaphore_terminate

semaphore_terminate :: fn (sem: *Semaphore) Error #inline

Terminate semaphore object.

File: sync.bl

std.semaphore_wait

semaphore_wait :: fn (sem: *Semaphore) Error #inline

File: sync.bl

std.semaphore_post

semaphore_post :: fn (sem: *Semaphore) Error #inline

File: sync.bl

std.condition_init

condition_init :: fn (condition: *Condition) Error #inline

File: sync.bl

std.condition_terminate

condition_terminate :: fn (_: *Condition) Error #inline

File: sync.bl

std.condition_wait

condition_wait :: fn (condition: *Condition, mutex: *Mutex) Error #inline

File: sync.bl

std.condition_signal

condition_signal :: fn (condition: *Condition) Error #inline

File: sync.bl