1 /* 2 ** Copyright 2002-2004, The OpenBeOS Team. All rights reserved. 3 ** Distributed under the terms of the OpenBeOS License. 4 ** 5 ** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. 6 ** Distributed under the terms of the NewOS License. 7 */ 8 #ifndef _THREAD_H 9 #define _THREAD_H 10 11 #ifdef __cplusplus 12 extern "C" { 13 #endif 14 15 #include <OS.h> 16 #include <thread_types.h> 17 #include <arch/thread.h> 18 19 20 void scheduler_reschedule(void); 21 void start_scheduler(void); 22 23 void thread_enqueue(struct thread *t, struct thread_queue *q); 24 struct thread *thread_lookat_queue(struct thread_queue *q); 25 struct thread *thread_dequeue(struct thread_queue *q); 26 struct thread *thread_dequeue_id(struct thread_queue *q, thread_id thr_id); 27 28 void scheduler_enqueue_in_run_queue(struct thread *thread); 29 void scheduler_remove_from_run_queue(struct thread *thread); 30 31 void thread_atkernel_entry(void); 32 // called when the thread enters the kernel on behalf of the thread 33 void thread_atkernel_exit(void); 34 35 int thread_init(kernel_args *ka); 36 int thread_init_percpu(int cpu_num); 37 void thread_exit(void); 38 int thread_kill_thread(thread_id id); 39 int thread_kill_thread_nowait(thread_id id); 40 41 #define thread_get_current_thread arch_thread_get_current_thread 42 43 struct thread *thread_get_thread_struct(thread_id id); 44 struct thread *thread_get_thread_struct_locked(thread_id id); 45 46 static thread_id thread_get_current_thread_id(void); 47 static inline thread_id 48 thread_get_current_thread_id(void) 49 { 50 struct thread *t = thread_get_current_thread(); 51 return t ? t->id : 0; 52 } 53 54 thread_id spawn_kernel_thread_etc(thread_func, const char *name, int32 priority, void *args, team_id team); 55 56 int team_init(kernel_args *ka); 57 struct team *team_get_kernel_team(void); 58 team_id team_create_team(const char *path, const char *name, char **args, int argc, char **envp, int envc, int priority); 59 int team_kill_team(team_id); 60 status_t wait_for_team(team_id id, status_t *returnCode); 61 void team_remove_team_from_hash(struct team *team); 62 team_id team_get_kernel_team_id(void); 63 team_id team_get_current_team_id(void); 64 char **user_team_get_arguments(void); 65 int user_team_get_arg_count(void); 66 bool team_is_valid(team_id id); 67 struct team *team_get_team_struct_locked(team_id id); 68 69 // used in syscalls.c 70 int user_thread_wait_for_thread(thread_id id, int *uretcode); 71 team_id user_team_create_team(const char *path, const char *name, char **args, int argc, char **envp, int envc, int priority); 72 int user_team_wait_for_team(team_id id, int *uretcode); 73 74 status_t user_set_thread_priority(thread_id thread, int32 newPriority); 75 status_t user_suspend_thread(thread_id thread); 76 status_t user_resume_thread(thread_id thread); 77 thread_id user_spawn_thread(thread_func func, const char *name, int32 priority, void *arg1, void *arg2); 78 status_t user_wait_for_thread(thread_id id, status_t *returnCode); 79 status_t user_wait_for_team(team_id id, status_t *returnCode); 80 status_t user_snooze_etc(bigtime_t timeout, int timebase, uint32 flags); 81 void user_exit_thread(status_t return_value); 82 83 bool user_has_data(thread_id thread); 84 status_t user_send_data(thread_id thread, int32 code, const void *buffer, size_t buffer_size); 85 status_t user_receive_data(thread_id *sender, void *buffer, size_t buffer_size); 86 87 status_t user_get_thread_info(thread_id id, thread_info *info); 88 status_t user_get_next_thread_info(team_id team, int32 *cookie, thread_info *info); 89 status_t user_get_team_info(team_id id, team_info *info); 90 status_t user_get_next_team_info(int32 *cookie, team_info *info); 91 92 int user_getrlimit(int resource, struct rlimit * rlp); 93 int user_setrlimit(int resource, const struct rlimit * rlp); 94 95 // ToDo: please move the "env" setter/getter out of the kernel! 96 int user_setenv(const char *name, const char *value, int overwrite); 97 int user_getenv(const char *name, char **value); 98 99 #if 1 100 // XXX remove later 101 int thread_test(void); 102 #endif 103 104 #ifdef __cplusplus 105 } 106 #endif 107 108 #endif /* _THREAD_H */ 109