7 * Copyright (c) 2007, 2008, 2009, 2010, 2011, ETH Zurich.
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
15 #ifndef LIBBARRELFISH_THREADS_H
16 #define LIBBARRELFISH_THREADS_H
18 #include <barrelfish/caddr.h> // for struct capref.
19 #include <barrelfish/thread_sync.h>
20 #include <barrelfish/caddr.h>
21 #include <barrelfish_kpi/registers_arch.h>
22 #include <barrelfish_kpi/dispatcher_handle.h>
23 #include <errors/errno.h>
24 #include <sys/cdefs.h>
28 typedef int (*thread_func_t)(void *);
30 /// Default size of a thread's stack
31 #define THREADS_DEFAULT_STACK_BYTES (64 * 1024)
33 struct thread *thread_create(thread_func_t start_func, void *data);
34 struct thread *thread_create_varstack(thread_func_t start_func, void *arg,
36 void thread_yield(void);
37 void thread_yield_dispatcher(struct capref endpoint);
38 void thread_exit(void);
39 struct thread *thread_self(void);
40 errval_t thread_join(struct thread *thread, int *retval);
41 errval_t thread_detach(struct thread *thread);
43 void thread_pause(struct thread *thread);
44 void thread_pause_and_capture_state(struct thread *thread,
45 arch_registers_state_t **ret_regs,
46 arch_registers_fpu_state_t **ret_fpuregs);
47 void thread_resume(struct thread *thread);
49 void thread_mutex_init(struct thread_mutex *mutex);
50 void thread_mutex_lock(struct thread_mutex *mutex);
51 bool thread_mutex_trylock(struct thread_mutex *mutex);
52 void thread_mutex_lock_nested(struct thread_mutex *mutex);
53 void thread_mutex_unlock(struct thread_mutex *mutex);
54 struct thread *thread_mutex_unlock_disabled(dispatcher_handle_t handle,
55 struct thread_mutex *mutex);
57 void thread_cond_init(struct thread_cond *cond);
58 void thread_cond_signal(struct thread_cond *cond);
59 void thread_cond_broadcast(struct thread_cond *cond);
60 void thread_cond_wait(struct thread_cond *cond, struct thread_mutex *mutex);
62 void thread_sem_init(struct thread_sem *sem, unsigned int value);
63 void thread_sem_wait(struct thread_sem *sem);
64 bool thread_sem_trywait(struct thread_sem *sem);
65 void thread_sem_post(struct thread_sem *sem);
67 void thread_set_tls(void *);
68 void *thread_get_tls(void);
70 void thread_set_tls_key(int, void *);
71 void *thread_get_tls_key(int);
73 uintptr_t thread_id(void);
74 uintptr_t thread_get_id(struct thread *t);
75 void thread_set_id(uintptr_t id);