xref: /haiku/src/tests/system/kernel/scheduler/override_types.h (revision dd980a197cfe1c74f138588317a3b30c3b571bb6)
1 /*
2  * Copyright 2004-2007, Haiku Inc.
3  * Distributed under the terms of the MIT License.
4  *
5  * Thread definition and structures
6  */
7 #ifndef _KERNEL_THREAD_TYPES_H
8 #define _KERNEL_THREAD_TYPES_H
9 
10 #define _THREAD_H
11 
12 #include <OS.h>
13 
14 #if 0
15 struct cpu_ent {
16 	bool preempted;
17 };
18 #endif
19 extern struct thread_queue dead_q;
20 
21 struct thread {
22 	struct thread	*queue_next;	/* i.e. run queue, release queue, etc. */
23 	char			*name;
24 	thread_id		id;
25 	int32			priority;
26 	int32			next_priority;
27 	int32			state;
28 	int32			next_state;
29 	struct cpu_ent	*cpu;
30 	struct Thread	*object;
31 
32 	bool			in_kernel;
33 	bool			is_idle;
34 	bool			was_yielded;
35 
36 	bigtime_t		user_time;
37 	bigtime_t		kernel_time;
38 	bigtime_t		last_time;
39 };
40 
41 enum additional_thread_state {
42 	THREAD_STATE_FREE_ON_RESCHED = 7, // free the thread structure upon reschedule
43 //	THREAD_STATE_BIRTH	// thread is being created
44 };
45 
46 struct thread_queue {
47 	struct thread *head;
48 	struct thread *tail;
49 };
50 
51 
52 static inline bool
thread_is_idle_thread(struct thread * thread)53 thread_is_idle_thread(struct thread *thread)
54 {
55 	return thread->is_idle;
56 }
57 
58 void thread_enqueue(struct thread *t, struct thread_queue *q);
59 struct thread *thread_get_current_thread(void);
60 
61 #define GRAB_THREAD_LOCK grab_thread_lock
62 #define RELEASE_THREAD_LOCK release_thread_lock
63 void grab_thread_lock(void);
64 void release_thread_lock(void);
65 
66 void arch_thread_context_switch(struct thread *t_from, struct thread *t_to);
67 void arch_thread_set_current_thread(struct thread *t);
68 
69 #endif	/* _KERNEL_THREAD_TYPES_H */
70