11 /* The idle thread runs at this priority */
12 #define IDLE_THREAD_PRIORITY INT_MAX
14 /* This priority should normally be used for hardware-polling threads */
15 #define POLL_THREAD_PRIORITY (INT_MAX-1)
20 struct thread_list
*next
, *prev
;
24 * Stack frame used by __switch_to, see thread_asm.S
29 uint32_t edi
, esi
, ebp
, ebx
;
34 struct thread_list list
;
35 struct thread
*thread
;
36 struct semaphore
*semaphore
;
42 #define THREAD_MAGIC 0x3568eb7d
45 struct thread_stack
*esp
; /* Must be first; stack pointer */
46 unsigned int thread_magic
;
47 const char *name
; /* Name (for debugging) */
48 struct thread_list list
;
49 struct thread_block
*blocked
;
50 void *stack
, *rmstack
; /* Stacks, iff allocated by malloc/lmalloc */
51 void *pvt
; /* For the benefit of lwIP */
55 extern void (*sched_hook_func
)(void);
57 void __thread_process_timeouts(void);
58 void __schedule(void);
59 void __switch_to(struct thread
*);
60 void thread_yield(void);
62 extern struct thread
*__current
;
63 static inline struct thread
*current(void)
70 struct thread_list list
;
73 #define DECLARE_INIT_SEMAPHORE(sem, cnt) \
74 struct semaphore sem = { \
82 mstime_t
sem_down(struct semaphore
*, mstime_t
);
83 void sem_up(struct semaphore
*);
84 void sem_init(struct semaphore
*, int);
87 * This marks a semaphore object as unusable; it will remain unusable
88 * until sem_init() is called on it again. This DOES NOT clear the
89 * list of blocked processes on this semaphore!
91 * It is also possible to mark the semaphore invalid by zeroing its
94 static inline void sem_set_invalid(struct semaphore
*sem
)
97 sem
->list
.next
= NULL
;
101 * Ask if a semaphore object has been initialized.
103 static inline bool sem_is_valid(struct semaphore
*sem
)
105 return ((!!sem
) && (!!sem
->list
.next
));
108 struct thread
*start_thread(const char *name
, size_t stack_size
, int prio
,
109 void (*start_func
)(void *), void *func_arg
);
110 void __exit_thread(void);
111 void kill_thread(struct thread
*);
113 void start_idle_thread(void);
114 void test_thread(void);
116 #endif /* _THREAD_H */