62 lines
1.3 KiB
C
62 lines
1.3 KiB
C
/*
|
|
* thread.h
|
|
*
|
|
* Created on: Apr 13, 2015
|
|
* Author: tkl
|
|
*/
|
|
|
|
#ifndef THREAD_H_
|
|
#define THREAD_H_
|
|
|
|
#define MAX_THREAD_COUNT 32
|
|
|
|
enum thread_priority {
|
|
THREAD_PRIO_IDLE = 0,
|
|
THREAD_PRIO_LOW,
|
|
THREAD_PRIO_MEDIUM,
|
|
THREAD_PRIO_HIGH
|
|
};
|
|
|
|
enum thread_status {
|
|
THREAD_STATUS_INIT = 0,
|
|
THREAD_STATUS_EXECUTING,
|
|
THREAD_STATUS_WAITING,
|
|
THREAD_STATUS_SLEEPING,
|
|
THREAD_STATUS_BLOCKING
|
|
};
|
|
|
|
struct thread_context {
|
|
stack_t *sp; /**< thread's stack pointer */
|
|
stack_t *stack; /**< thread's stack start address */
|
|
unsigned int stack_size; /**< thread's stack size */
|
|
unsigned int pid; /**< thread's process id */
|
|
enum thread_priority priority; /**< thread's priority */
|
|
enum thread_status status; /**< thread's status */
|
|
unsigned long next_executing_time;
|
|
void *wakeup_blocking_source;
|
|
struct queue_node sem_queue_node;
|
|
};
|
|
|
|
struct thread_list {
|
|
unsigned int count; //<! Number of elements in list
|
|
struct thread_context *list[MAX_THREAD_COUNT];
|
|
};
|
|
|
|
void thread_init(void);
|
|
struct thread_context *thread_create(
|
|
struct thread_context *thread,
|
|
stack_t *stack,
|
|
unsigned int stack_size,
|
|
void (*thread_func)(void *),
|
|
void *arg,
|
|
enum thread_priority priority);
|
|
|
|
void thread_switch_context(void);
|
|
|
|
void thread_exit(void);
|
|
|
|
void blocking_read_wakeup(const void *src);
|
|
|
|
|
|
#endif /* THREAD_H_ */
|