xref: /haiku/headers/private/kernel/thread.h (revision 4f00613311d0bd6b70fa82ce19931c41f071ea4e)
1 /*
2  * Copyright 2002-2005, 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_exit(void);
35 
36 bigtime_t thread_get_active_cpu_time(int32 cpuNum);
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 *t = thread_get_current_thread();
50 	return t ? t->id : 0;
51 }
52 
53 thread_id allocate_thread_id(void);
54 thread_id peek_next_thread_id(void);
55 
56 thread_id spawn_kernel_thread_etc(thread_func, const char *name, int32 priority,
57 	void *args, team_id team, thread_id threadID);
58 
59 // used in syscalls.c
60 status_t _user_set_thread_priority(thread_id thread, int32 newPriority);
61 status_t _user_rename_thread(thread_id thread, const char *name);
62 status_t _user_suspend_thread(thread_id thread);
63 status_t _user_resume_thread(thread_id thread);
64 status_t _user_rename_thread(thread_id thread, const char *name);
65 thread_id _user_spawn_thread(thread_entry_func entry, const char *name, int32 priority, void *arg1, void *arg2);
66 status_t _user_wait_for_thread(thread_id id, status_t *_returnCode);
67 status_t _user_snooze_etc(bigtime_t timeout, int timebase, uint32 flags);
68 status_t _user_kill_thread(thread_id thread);
69 void _user_exit_thread(status_t return_value);
70 bool _user_has_data(thread_id thread);
71 status_t _user_send_data(thread_id thread, int32 code, const void *buffer, size_t buffer_size);
72 status_t _user_receive_data(thread_id *_sender, void *buffer, size_t buffer_size);
73 thread_id _user_find_thread(const char *name);
74 status_t _user_get_thread_info(thread_id id, thread_info *info);
75 status_t _user_get_next_thread_info(team_id team, int32 *cookie, thread_info *info);
76 
77 // ToDo: these don't belong here
78 struct rlimit;
79 int _user_getrlimit(int resource, struct rlimit * rlp);
80 int _user_setrlimit(int resource, const struct rlimit * rlp);
81 
82 #ifdef __cplusplus
83 }
84 #endif
85 
86 #endif /* _THREAD_H */
87