diff options
author | H. Peter Anvin <hpa@zytor.com> | 2009-09-08 21:06:34 -0700 |
---|---|---|
committer | Eric W. Biederman <ebiederm@xmission.com> | 2011-04-08 14:40:28 -0700 |
commit | 884e5778c9b66b943eb02d8437bc0b26a219e2ec (patch) | |
tree | 0b7a91ccf1fe51234bfe73d5868e81f191da8484 /core/include/thread.h | |
parent | 87fa53c543531231cd54ab4857d5e21f76555265 (diff) | |
download | syslinux-884e5778c9b66b943eb02d8437bc0b26a219e2ec.tar.gz |
core: simple thread library
Simple thread library with the intent of making lwIP easier to port.
-- Modified to use milliseconds instead of jiffies,
as lwIP expresses everything in milliseconds. EWB
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Diffstat (limited to 'core/include/thread.h')
-rw-r--r-- | core/include/thread.h | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/core/include/thread.h b/core/include/thread.h new file mode 100644 index 00000000..917c36a6 --- /dev/null +++ b/core/include/thread.h @@ -0,0 +1,84 @@ +#ifndef _THREAD_H +#define _THREAD_H + +#include <stddef.h> +#include <inttypes.h> +#include "core.h" + +struct semaphore; + +struct thread_state { + uint32_t ebx, esp, ebp, esi, edi; +}; + +struct thread_list { + struct thread_list *next, *prev; +}; + +struct thread_block { + struct thread_list list; + struct thread *thread; + struct semaphore *semaphore; + mstime_t block_time; + mstime_t timeout; + bool timed_out; +}; + +struct thread { + struct thread_state state; + struct thread_list list; + struct thread_block *blocked; + int prio; +}; + +void __schedule(void); +void __switch_to(struct thread *); +void thread_yield(void); + +extern struct thread *__current; +static inline struct thread *current(void) +{ + return __current; +} + +struct semaphore { + int count; + struct thread_list list; +}; + +mstime_t sem_down(struct semaphore *, mstime_t); +void sem_up(struct semaphore *); +void sem_init(struct semaphore *, int); + +typedef unsigned long irq_state_t; + +static inline irq_state_t irq_state(void) +{ + irq_state_t __st; + + asm volatile("pushfl ; popl %0" : "=rm" (__st)); + return __st; +} + +static inline irq_state_t irq_save(void) +{ + irq_state_t __st; + + asm volatile("pushfl ; popl %0 ; cli" : "=rm" (__st)); + return __st; +} + +static inline void irq_restore(irq_state_t __st) +{ + asm volatile("pushl %0 ; popfl" : : "rm" (__st)); +} + +void start_thread(struct thread *t, void *stack, size_t stack_size, int prio, + void (*start_func)(void *), void *func_arg); +void __exit_thread(void); +void kill_thread(struct thread *); + +void start_idle_thread(void); +void test_thread(void); + +#endif /* _THREAD_H */ |