Simplify context switch logic
This commit is contained in:
parent
74f253b575
commit
5556c521a0
@ -3,38 +3,24 @@
|
|||||||
|
|
||||||
#include "kernel_priv.h"
|
#include "kernel_priv.h"
|
||||||
|
|
||||||
enum { PUSH = 1, POP = 2, IGN = 3 };
|
|
||||||
|
|
||||||
static const int ss_table[256][256][3] = {
|
|
||||||
['C'] = {
|
|
||||||
['O'] = { CH_CS, PUSH, ST_CSOUT },
|
|
||||||
['I'] = { CH_CS, POP, ST_CSOUT },
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
simple(struct emu *emu)
|
context_switch(struct emu *emu)
|
||||||
{
|
{
|
||||||
const int *entry = ss_table[emu->ev->c][emu->ev->v];
|
|
||||||
int chind = entry[0];
|
|
||||||
int action = entry[1];
|
|
||||||
int st = entry[2];
|
|
||||||
|
|
||||||
struct kernel_thread *th = EXT(emu->thread, 'K');
|
struct kernel_thread *th = EXT(emu->thread, 'K');
|
||||||
struct chan *ch = &th->m.ch[chind];
|
struct chan *ch = &th->m.ch[CH_CS];
|
||||||
|
|
||||||
if (action == PUSH) {
|
switch (emu->ev->v) {
|
||||||
return chan_push(ch, value_int64(st));
|
case 'O':
|
||||||
} else if (action == POP) {
|
return chan_push(ch, value_int64(ST_CSOUT));
|
||||||
return chan_pop(ch, value_int64(st));
|
case 'I':
|
||||||
} else if (action == IGN) {
|
return chan_pop(ch, value_int64(ST_CSOUT));
|
||||||
return 0; /* do nothing */
|
default:
|
||||||
} else {
|
err("unknown context switch event");
|
||||||
err("unknown event");
|
return -1;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
/* Not reached */
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -42,7 +28,7 @@ process_ev(struct emu *emu)
|
|||||||
{
|
{
|
||||||
switch (emu->ev->c) {
|
switch (emu->ev->c) {
|
||||||
case 'C':
|
case 'C':
|
||||||
return simple(emu);
|
return context_switch(emu);
|
||||||
default:
|
default:
|
||||||
err("unknown Kernel event category");
|
err("unknown Kernel event category");
|
||||||
return -1;
|
return -1;
|
||||||
@ -65,7 +51,6 @@ model_kernel_event(struct emu *emu)
|
|||||||
enabled = 1;
|
enabled = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
dbg("in kernel_event");
|
dbg("in kernel_event");
|
||||||
if (emu->ev->m != 'K') {
|
if (emu->ev->m != 'K') {
|
||||||
err("unexpected event model %c\n", emu->ev->m);
|
err("unexpected event model %c\n", emu->ev->m);
|
||||||
|
Loading…
Reference in New Issue
Block a user