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 12 #include <OS.h> 13 #include <thread_types.h> 14 #include <arch/thread.h> 15 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 void scheduler_reschedule(void); 22 void start_scheduler(void); 23 24 void thread_enqueue(struct thread *t, struct thread_queue *q); 25 struct thread *thread_lookat_queue(struct thread_queue *q); 26 struct thread *thread_dequeue(struct thread_queue *q); 27 struct thread *thread_dequeue_id(struct thread_queue *q, thread_id thr_id); 28 29 void scheduler_enqueue_in_run_queue(struct thread *thread); 30 void scheduler_remove_from_run_queue(struct thread *thread); 31 32 void thread_atkernel_entry(void); 33 // called when the thread enters the kernel on behalf of the thread 34 void thread_atkernel_exit(void); 35 36 status_t thread_init(kernel_args *ka); 37 status_t thread_per_cpu_init(int32 cpu_num); 38 void thread_exit(void); 39 40 #define thread_get_current_thread arch_thread_get_current_thread 41 42 struct thread *thread_get_thread_struct(thread_id id); 43 struct thread *thread_get_thread_struct_locked(thread_id id); 44 45 static thread_id thread_get_current_thread_id(void); 46 static inline thread_id 47 thread_get_current_thread_id(void) 48 { 49 struct thread *t = thread_get_current_thread(); 50 return t ? t->id : 0; 51 } 52 53 thread_id spawn_kernel_thread_etc(thread_func, const char *name, int32 priority, void *args, team_id team); 54 55 // used in syscalls.c 56 status_t _user_set_thread_priority(thread_id thread, int32 newPriority); 57 status_t _user_rename_thread(thread_id thread, const char *name); 58 status_t _user_suspend_thread(thread_id thread); 59 status_t _user_resume_thread(thread_id thread); 60 thread_id _user_spawn_thread(thread_func func, const char *name, int32 priority, void *arg1, void *arg2); 61 status_t _user_wait_for_thread(thread_id id, status_t *_returnCode); 62 status_t _user_snooze_etc(bigtime_t timeout, int timebase, uint32 flags); 63 status_t _user_kill_thread(thread_id thread); 64 void _user_exit_thread(status_t return_value); 65 bool _user_has_data(thread_id thread); 66 status_t _user_send_data(thread_id thread, int32 code, const void *buffer, size_t buffer_size); 67 status_t _user_receive_data(thread_id *_sender, void *buffer, size_t buffer_size); 68 thread_id _user_find_thread(const char *name); 69 status_t _user_get_thread_info(thread_id id, thread_info *info); 70 status_t _user_get_next_thread_info(team_id team, int32 *cookie, thread_info *info); 71 72 // ToDo: these don't belong here 73 int _user_getrlimit(int resource, struct rlimit * rlp); 74 int _user_setrlimit(int resource, const struct rlimit * rlp); 75 76 #if 1 77 // XXX remove later 78 int thread_test(void); 79 #endif 80 81 #ifdef __cplusplus 82 } 83 #endif 84 85 #endif /* _THREAD_H */ 86