Add suspend() and resume() to harness
This commit is contained in:
parent
a5c2ec5830
commit
9e0191b274
17
harness.c
17
harness.c
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue