Barrelfish
Macros | Functions
threads.h File Reference

Threads. More...

Macros

#define THREADS_DEFAULT_STACK_BYTES   (64 * 1024)
 Default size of a thread's stack.
 

Functions

struct threadthread_create (thread_func_t start_func, void *data)
 Creates a new thread, and makes it runnable. More...
 
struct threadthread_create_varstack (thread_func_t start_func, void *arg, size_t stacksize)
 Creates a new thread, and makes it runnable. More...
 
void thread_yield (void)
 Yield the calling thread. More...
 
void thread_yield_dispatcher (struct capref endpoint)
 Yield both the calling thread, and the dispatcher to another domain. More...
 
void thread_exit (int status)
 Terminate the calling thread.
 
struct threadthread_self (void)
 Returns the thread pointer to the currently-running thread.
 
errval_t thread_join (struct thread *thread, int *retval)
 Wait for termination of another thread. More...
 
errval_t thread_detach (struct thread *thread)
 Detach a thread. Free its state when it terminates. More...
 
void thread_pause (struct thread *thread)
 Pause (suspend execution of) the given thread. More...
 
void thread_pause_and_capture_state (struct thread *thread, arch_registers_state_t **ret_regs, arch_registers_fpu_state_t **ret_fpuregs)
 Pause (suspend execution of) the given thread, and optionally capture its register state. More...
 
void thread_resume (struct thread *thread)
 Resume execution of a thread previously suspended by thread_pause()
 
void thread_mutex_init (struct thread_mutex *mutex)
 Initialise a mutex. More...
 
void thread_mutex_lock (struct thread_mutex *mutex)
 Lock a mutex. More...
 
bool thread_mutex_trylock (struct thread_mutex *mutex)
 Try to lock a mutex. More...
 
void thread_mutex_lock_nested (struct thread_mutex *mutex)
 Lock a mutex. More...
 
void thread_mutex_unlock (struct thread_mutex *mutex)
 Unlock a mutex. More...
 
struct threadthread_mutex_unlock_disabled (dispatcher_handle_t handle, struct thread_mutex *mutex)
 Unlock a mutex, while disabled. More...
 
void thread_cond_init (struct thread_cond *cond)
 Initialise a condition variable. More...
 
void thread_cond_signal (struct thread_cond *cond)
 Signal a condition variable. More...
 
void thread_cond_broadcast (struct thread_cond *cond)
 Broadcast signal a condition variable. More...
 
void thread_cond_wait (struct thread_cond *cond, struct thread_mutex *mutex)
 Wait for a condition variable. More...
 
void thread_set_tls (void *)
 Set old-style thread-local storage pointer. More...
 
void * thread_get_tls (void)
 Return old-style thread-local storage pointer. More...
 
void thread_set_local_trigger (struct waitset_chanstate *trigger)
 Set/get a local trigger for currently processed event channel.
 
void thread_store_recv_slot (struct capref recv_slot)
 Store receive slot provided by rpc in thread state.
 
void thread_set_status (int status)
 Set a thread's exit status. More...
 

Detailed Description

Threads.

Function Documentation

void thread_cond_broadcast ( struct thread_cond *  cond)

Broadcast signal a condition variable.

This function signals the condition variable, and wakes up all threads waiting on it.

Parameters
condCondition variable pointer
void thread_cond_init ( struct thread_cond *  cond)

Initialise a condition variable.

Parameters
condCondition variable pointer
void thread_cond_signal ( struct thread_cond *  cond)

Signal a condition variable.

This function signals the condition variable, and wakes up one thread waiting on it.

Parameters
condCondition variable pointer
void thread_cond_wait ( struct thread_cond *  cond,
struct thread_mutex *  mutex 
)

Wait for a condition variable.

This function waits for the given condition variable to be signalled (through thread_cond_signal() or thread_cond_broadcast()) before returning, while atomically unlocking the mutex pointed to by 'mutex'.

Parameters
condCondition variable pointer
mutexOptional pointer to mutex to unlock.
struct thread* thread_create ( thread_func_t  start_func,
void *  arg 
)

Creates a new thread, and makes it runnable.

Parameters
start_funcFunction to run on the new thread
argArgument to pass to function
Returns
Thread pointer on success, NULL on failure
struct thread* thread_create_varstack ( thread_func_t  start_func,
void *  arg,
size_t  stacksize 
)

Creates a new thread, and makes it runnable.

Parameters
start_funcFunction to run on the new thread
argArgument to pass to function
stacksizeSize of stack, in bytes
Returns
Thread pointer on success, NULL on failure
errval_t thread_detach ( struct thread thread)

Detach a thread. Free its state when it terminates.

Parameters
threadPointer to thread to detach
Returns
SYS_ERR_OK on success.
void* thread_get_tls ( void  )

Return old-style thread-local storage pointer.

Returns
User's pointer, previously passed to thread_set_tls()
errval_t thread_join ( struct thread thread,
int *  retval 
)

Wait for termination of another thread.

Parameters
threadPointer to thread to wait for
retvalPointer to variable to hold return value of thread, or NULL
Returns
SYS_ERR_OK on success, error code on error.
void thread_mutex_init ( struct thread_mutex *  mutex)

Initialise a mutex.

Parameters
mutexMutex pointer
void thread_mutex_lock ( struct thread_mutex *  mutex)

Lock a mutex.

This blocks until the given mutex is unlocked, and then atomically locks it.

Parameters
mutexMutex pointer
void thread_mutex_lock_nested ( struct thread_mutex *  mutex)

Lock a mutex.

This blocks until the given mutex is unlocked, and then atomically locks it.

Parameters
mutexMutex pointer
bool thread_mutex_trylock ( struct thread_mutex *  mutex)

Try to lock a mutex.

If the given mutex is unlocked, this atomically locks it and returns true, otherwise it returns false immediately.

Parameters
mutexMutex pointer
Returns
true if lock acquired, false otherwise
void thread_mutex_unlock ( struct thread_mutex *  mutex)

Unlock a mutex.

This unlocks the given mutex.

Parameters
mutexMutex pointer
struct thread* thread_mutex_unlock_disabled ( dispatcher_handle_t  handle,
struct thread_mutex *  mutex 
)

Unlock a mutex, while disabled.

This function unlocks the given mutex. It may only be called while disabled.

Parameters
dispDispatcher pointer
mutexMutex pointer
Returns
Pointer to thread to be woken on foreign dispatcher
void thread_pause ( struct thread thread)

Pause (suspend execution of) the given thread.

The thread will not be run, until a subsequent call to thread_resume()

void thread_pause_and_capture_state ( struct thread thread,
arch_registers_state_t **  ret_regs,
arch_registers_fpu_state_t **  ret_fpuregs 
)

Pause (suspend execution of) the given thread, and optionally capture its register state.

The thread will not be run, until a subsequent call to thread_resume()

void thread_set_status ( int  status)

Set a thread's exit status.

Parameters
statusThe status.
void thread_set_tls ( void *  p)

Set old-style thread-local storage pointer.

Parameters
pUser's pointer
void thread_yield ( void  )

Yield the calling thread.

Switches to the next runnable thread in this dispatcher, or if none is available, yields the dispatcher.

void thread_yield_dispatcher ( struct capref  endpoint)

Yield both the calling thread, and the dispatcher to another domain.

Parameters
endpointEndpoint cap to which we wish to yield, or #CAP_NULL for an undirected yield

Yields the dispatcher, optionally to another specified dispatcher.