thread/core

sourcethread/core.sx

ThreadError

pub enum ThreadError = { OutOfMemory, CreateFailed, JoinFailed, DetachFailed, AlreadyJoined }

Variants

  • OutOfMemory
  • CreateFailed
  • JoinFailed
  • DetachFailed
  • AlreadyJoined

alloc_in

private
fn alloc_in[A: allocators.GeneralAllocator](ac: A, size: usize) option[ref void]

free_in

private
fn free_in[A: allocators.GeneralAllocator](ac: A, ptr: ref void) void

Thread

pub type Thread = { handle: ref void, joined: bool }

Opaque thread handle — wraps pthread_t on POSIX, HANDLE on Windows.

Fields

NameType
handleref void
joinedbool

pthread_create

when posixprivate
extern (C) fn pthread_create(thread: ref void, attr: ref void, start_routine: usize, arg: ref void) i32 = trust { ... } = "pthread_create"

pthread_join

when posixprivate
extern (C) fn pthread_join(thread: ref void, retval: ref void) i32 = trust { ... } = "pthread_join"

pthread_detach

when posixprivate
extern (C) fn pthread_detach(thread: ref void) i32 = trust { ... } = "pthread_detach"

pthread_self

when posixprivate
extern (C) fn pthread_self() ref void = trust { ... } = "pthread_self"

sched_yield

when posixprivate
extern (C) fn sched_yield() i32 = trust { ... } = "sched_yield"

CreateThread

when windowsprivate
extern (C) fn CreateThread(lpThreadAttributes: ref void, dwStackSize: usize, lpStartAddress: usize, lpParameter: ref void, dwCreationFlags: u32, lpThreadId: ref u32) ref void = trust { ... } = "CreateThread"

WaitForSingleObject

when windowsprivate
extern (C) fn WaitForSingleObject(hHandle: ref void, dwMilliseconds: u32) u32 = trust { ... } = "WaitForSingleObject"

CloseHandle

when windowsprivate
extern (C) fn CloseHandle(hObject: ref void) i32 = trust { ... } = "CloseHandle"

GetCurrentThreadId

when windowsprivate
extern (C) fn GetCurrentThreadId() u32 = trust { ... } = "GetCurrentThreadId"

SwitchToThread

when windowsprivate
extern (C) fn SwitchToThread() i32 = trust { ... } = "SwitchToThread"

new

pub fn (Thread) new[A: allocators.GeneralAllocator](ac: A, entry: fn(ref void) ref void, arg: ref void) result[ref void, ThreadError]

Create a new thread running `entry` with the given `arg`.

join

pub fn (Thread) join[A: allocators.GeneralAllocator](ac: A, thread: Thread) result[ref void, ThreadError]

detach

pub fn (Thread) detach[A: allocators.GeneralAllocator](ac: A, thread: Thread) result[void, ThreadError]

free

pub fn (Thread) free[A: allocators.GeneralAllocator](ac: A, thread: mut Thread) void

current_thread_id

pub fn current_thread_id() usize

yield_thread

pub fn yield_thread() void = trust { ... }

Mutex

pub type Mutex = { ptr: ref void }

Fields

NameType
ptrref void

pthread_mutex_init

when posixprivate
extern (C) fn pthread_mutex_init(mutex: ref void, attr: ref void) i32 = trust { ... } = "pthread_mutex_init"

pthread_mutex_destroy

when posixprivate
extern (C) fn pthread_mutex_destroy(mutex: ref void) i32 = trust { ... } = "pthread_mutex_destroy"

pthread_mutex_lock

when posixprivate
extern (C) fn pthread_mutex_lock(mutex: ref void) i32 = trust { ... } = "pthread_mutex_lock"

pthread_mutex_unlock

when posixprivate
extern (C) fn pthread_mutex_unlock(mutex: ref void) i32 = trust { ... } = "pthread_mutex_unlock"

InitializeCriticalSection

when windowsprivate
extern (C) fn InitializeCriticalSection(lpCriticalSection: ref void) void = trust { ... } = "InitializeCriticalSection"

DeleteCriticalSection

when windowsprivate
extern (C) fn DeleteCriticalSection(lpCriticalSection: ref void) void = trust { ... } = "DeleteCriticalSection"

EnterCriticalSection

when windowsprivate
extern (C) fn EnterCriticalSection(lpCriticalSection: ref void) void = trust { ... } = "EnterCriticalSection"

LeaveCriticalSection

when windowsprivate
extern (C) fn LeaveCriticalSection(lpCriticalSection: ref void) void = trust { ... } = "LeaveCriticalSection"

new

pub fn (Mutex) new[A: allocators.GeneralAllocator](ac: A) option[ref void]

lock

pub fn (Mutex) lock(m: Mutex) void

unlock

pub fn (Mutex) unlock(m: Mutex) void = trust { ... }

free

pub fn (Mutex) free[A: allocators.GeneralAllocator](ac: A, m: mut Mutex) void

thread_test_entry

private
fn thread_test_entry(arg: ref void) ref void