/* task.h */ /* EMACS_MODES: c !fill */ /* This file contains the definitions for the UNIX tasking package. This * package requires the general-purpose queuing package. */ #include "q.h" typedef int stack; /* type of data in task's stack */ typedef int event; /* an event flag */ typedef struct task { /* a UNIX task - top of its stack */ struct q_elt tk_elt; /* next task ptr */ stack *tk_fp; /* task's current frame ptr */ unsigned tk_state; /* task's state: run, ready, blocked */ event tk_evf; /* task's wakeup event flag */ caddr_t tk_extern; /* task's external static vars. */ stack tk_stack[1]; /* top of task's stack */ } task; typedef struct task_q { /* a task queue */ task *tq_head; /* first task in queue */ task *tq_tail; /* last task in queue */ int tq_len; /* number of tasks in queue */ } task_q; extern task *tk_cur; /* currently running task */ extern task_q tk_rdy; /* queue of ready tasks */ extern task_q tk_blk; /* queue of blocked tasks */ extern int tk_resched; /* reschedule needed flag */ extern task *tk_init (); /* initialize task system */ extern task *tk_fork (); /* fork a new task */ #define TK_SYSLEEP 30 /* time to block process */ /* Definitions for task states */ #define TK_RUN 1 /* task is currently running */ #define TK_RDY 2 /* task is on ready queue */ #define TK_BLK 3 /* task is on blocked queue */ #define TK_DEAD 4 /* task has exited */ /* Useful macros */ /* Wakeup a specified task. May be used at interrupt level */ #define tk_wake(tk) { (tk)->tk_evf = TRUE; tk_resched = TRUE; } /* Wakeup a task and set the specified event flag for it */ #define tk_setef(tk,ef) { *(ef) = TRUE; (tk)->tk_evf = TRUE; tk_resched = TRUE; } /* Block the current task and force a reschedule. */ #define tk_block() { \ tk_cur->tk_state = TK_BLK; \ q_addt (&tk_blk, tk_cur); \ tk_sched (); \ } /* Yield the processor to any other runnable task */ #define tk_yield() { tk_wake(tk_cur); tk_block(); }