sched: add task and thread alloc functions
This commit is contained in:
@@ -2,25 +2,40 @@
|
||||
#define SOCKS_SCHED_H_
|
||||
|
||||
#include <socks/pmap.h>
|
||||
#include <socks/locks.h>
|
||||
#include <socks/queue.h>
|
||||
#include <socks/object.h>
|
||||
#include <socks/btree.h>
|
||||
#include <socks/status.h>
|
||||
|
||||
#define TASK_NAME_MAX 64
|
||||
#define PRIO_MAX 32
|
||||
|
||||
typedef enum task_state {
|
||||
TASK_RUNNING,
|
||||
TASK_STOPPED,
|
||||
} task_state_t;
|
||||
|
||||
typedef enum task_thread_state {
|
||||
TASK_THREAD_READY,
|
||||
TASK_THREAD_SLEEPING,
|
||||
TASK_THREAD_STOPPED,
|
||||
} task_thread_state_t;
|
||||
typedef enum thread_state {
|
||||
THREAD_READY,
|
||||
THREAD_SLEEPING,
|
||||
THREAD_STOPPED,
|
||||
} thread_state_t;
|
||||
|
||||
typedef enum sched_priority {
|
||||
PRIO_IDLE = 4,
|
||||
PRIO_SUBNORMAL = 6,
|
||||
PRIO_NORMAL = 10,
|
||||
PRIO_SUPERNORMAL = 14,
|
||||
PRIO_HIGH = 18,
|
||||
PRIO_REALTIME = 24,
|
||||
} sched_priority_t;
|
||||
|
||||
typedef struct task {
|
||||
struct task *t_parent;
|
||||
unsigned int t_id;
|
||||
task_state_t t_state;
|
||||
char t_name[TASK_NAME_MAX];
|
||||
|
||||
pmap_t t_pmap;
|
||||
|
||||
@@ -29,15 +44,41 @@ typedef struct task {
|
||||
queue_t t_children;
|
||||
} task_t;
|
||||
|
||||
typedef struct task_thread {
|
||||
task_thread_state_t tr_state;
|
||||
typedef struct thread {
|
||||
thread_state_t tr_state;
|
||||
task_t *tr_parent;
|
||||
|
||||
unsigned int tr_id;
|
||||
unsigned int tr_prio;
|
||||
|
||||
queue_entry_t tr_threads;
|
||||
queue_entry_t tr_rqentry;
|
||||
void *tr_kstack;
|
||||
} task_thread_t;
|
||||
} thread_t;
|
||||
|
||||
typedef struct runqueue {
|
||||
queue_t rq_queues[PRIO_MAX];
|
||||
uint32_t rq_readybits;
|
||||
spin_lock_t rq_lock;
|
||||
} runqueue_t;
|
||||
|
||||
extern kern_status_t sched_init(void);
|
||||
|
||||
extern task_t *task_alloc(void);
|
||||
static inline task_t *task_ref(task_t *task) { return object_data(object_ref(object_header(task))); }
|
||||
static inline void task_deref(task_t *task) { object_deref(object_header(task)); }
|
||||
extern task_t *task_from_pid(unsigned int pid);
|
||||
|
||||
static inline void task_lock_irqsave(task_t *task, unsigned long *flags)
|
||||
{
|
||||
object_lock(object_header(task), flags);
|
||||
}
|
||||
|
||||
static inline void task_unlock_irqrestore(task_t *task, unsigned long flags)
|
||||
{
|
||||
object_unlock(object_header(task), flags);
|
||||
}
|
||||
|
||||
extern thread_t *thread_alloc(void);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user