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