Add suspend() and resume() to harness

This commit is contained in:
Tony Garnock-Jones 2011-01-01 21:12:54 -05:00
parent a5c2ec5830
commit 9e0191b274
2 changed files with 19 additions and 3 deletions

View File

@ -40,7 +40,7 @@ typedef unsigned char u_char;
static volatile int harness_running = 1;
Process *current_process = NULL;
#define EMPTY_PROCESS_QUEUE ((queue_t) { offsetof(Process, link), 0, NULL, NULL })
#define EMPTY_PROCESS_QUEUE EMPTY_QUEUE(Process, link)
static ucontext_t scheduler;
static queue_t runlist = EMPTY_PROCESS_QUEUE;
@ -73,12 +73,23 @@ void killproc(void) {
schedule();
}
void suspend(void) {
assert(current_process->state == PROCESS_RUNNING);
current_process->state = PROCESS_WAITING;
schedule();
}
void resume(Process *p) {
assert(p->state == PROCESS_WAITING);
enqueue_runlist(p);
}
static void driver(void (*f)(void *), void *arg) {
f(arg);
killproc();
}
void spawn(void (*f)(void *), void *arg) {
Process *spawn(void (*f)(void *), void *arg) {
Process *p = calloc(1, sizeof(*p));
PCHECK(p, "spawn calloc");
@ -97,6 +108,8 @@ void spawn(void (*f)(void *), void *arg) {
p->link = NULL;
enqueue_runlist(p);
return p;
}
void nap_isr(int fd, short what, void *arg) {

View File

@ -28,9 +28,12 @@ typedef struct IOHandle {
extern Process *current_process;
extern void yield(void);
extern void spawn(process_main_t f, void *arg);
extern Process *spawn(process_main_t f, void *arg);
extern void nap(long millis);
extern void suspend(void);
extern void resume(Process *p);
extern IOHandle *new_iohandle(int fd);
extern void delete_iohandle(IOHandle *h);
extern void iohandle_clear_error(IOHandle *h);