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