1 /* 2 * Copyright 2002-2006, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT 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 struct kernel_args; 17 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 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 thread_at_kernel_entry(void); 29 // called when the thread enters the kernel on behalf of the thread 30 void thread_at_kernel_exit(void); 31 32 status_t thread_init(struct kernel_args *args); 33 status_t thread_per_cpu_init(int32 cpuNum); 34 void thread_yield(void); 35 void thread_exit(void); 36 37 int32 thread_max_threads(void); 38 int32 thread_used_threads(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 *thread = thread_get_current_thread(); 50 return thread ? thread->id : 0; 51 } 52 53 static inline bool 54 thread_is_idle_thread(struct thread *thread) 55 { 56 return thread->entry == NULL; 57 } 58 59 thread_id allocate_thread_id(void); 60 thread_id peek_next_thread_id(void); 61 62 thread_id spawn_kernel_thread_etc(thread_func, const char *name, int32 priority, 63 void *args, team_id team, thread_id threadID); 64 status_t wait_for_thread_etc(thread_id id, uint32 flags, bigtime_t timeout, 65 status_t *_returnCode); 66 67 // used in syscalls.c 68 status_t _user_set_thread_priority(thread_id thread, int32 newPriority); 69 status_t _user_rename_thread(thread_id thread, const char *name); 70 status_t _user_suspend_thread(thread_id thread); 71 status_t _user_resume_thread(thread_id thread); 72 status_t _user_rename_thread(thread_id thread, const char *name); 73 thread_id _user_spawn_thread(thread_entry_func entry, const char *name, int32 priority, void *arg1, void *arg2); 74 status_t _user_wait_for_thread(thread_id id, status_t *_returnCode); 75 status_t _user_snooze_etc(bigtime_t timeout, int timebase, uint32 flags); 76 status_t _user_kill_thread(thread_id thread); 77 void _user_thread_yield(void); 78 void _user_exit_thread(status_t return_value); 79 bool _user_has_data(thread_id thread); 80 status_t _user_send_data(thread_id thread, int32 code, const void *buffer, size_t buffer_size); 81 status_t _user_receive_data(thread_id *_sender, void *buffer, size_t buffer_size); 82 thread_id _user_find_thread(const char *name); 83 status_t _user_get_thread_info(thread_id id, thread_info *info); 84 status_t _user_get_next_thread_info(team_id team, int32 *cookie, thread_info *info); 85 86 // ToDo: these don't belong here 87 struct rlimit; 88 int _user_getrlimit(int resource, struct rlimit * rlp); 89 int _user_setrlimit(int resource, const struct rlimit * rlp); 90 91 #ifdef __cplusplus 92 } 93 #endif 94 95 #endif /* _THREAD_H */ 96