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