diff options
author | bjj <bjj> | 2001-03-12 03:25:16 +0000 |
---|---|---|
committer | bjj <bjj> | 2001-03-12 03:25:16 +0000 |
commit | ba5fe7e03f7a120d9163b27b39931197f3f0d295 (patch) | |
tree | 3f488f71e467a3989525ee25df5e350390c9e9f9 | |
parent | 6d7dac3c98256c71d94af1260495cd1e424968cd (diff) | |
download | moo-ba5fe7e03f7a120d9163b27b39931197f3f0d295.tar.gz moo-ba5fe7e03f7a120d9163b27b39931197f3f0d295.tar.xz moo-ba5fe7e03f7a120d9163b27b39931197f3f0d295.zip |
Added new package type BI_KILL which kills the task calling the builtin.
Removed the static int task_killed in execute.c which wa tested on every
loop through the interpreter to see if the task had been killed.
-rw-r--r-- | execute.c | 35 | ||||
-rw-r--r-- | functions.c | 15 | ||||
-rw-r--r-- | functions.h | 9 | ||||
-rw-r--r-- | tasks.c | 14 |
4 files changed, 53 insertions, 20 deletions
@@ -57,7 +57,6 @@ static int root_activ_vector; /* root_activ_vector == MAIN_VECTOR static int ticks_remaining; int task_timed_out; static int interpreter_is_running = 0; -static int task_killed; static Timer_ID task_alarm_id; static task_kind current_task_kind; @@ -313,6 +312,8 @@ unwind_stack(Finally_Reason why, Var value, enum outcome *outcome) a->bi_func_pc = p.u.call.pc; a->bi_func_data = p.u.call.data; return 0; + case BI_KILL: + return unwind_stack(FIN_ABORT, zero, outcome); } } else { /* Built-in functions receive zero as a `returned value' on @@ -337,6 +338,7 @@ unwind_stack(Finally_Reason why, Var value, enum outcome *outcome) free_var(p.u.raise.value); break; case BI_SUSPEND: + case BI_KILL: break; case BI_CALL: free_activation(activ_stack[top_activ_stack--], 0); @@ -713,6 +715,8 @@ run(char raise, enum error resumption_error, Var * result) + ((unsigned) bv[-2] << 8) \ + bv[-1])))) +#define SKIP_BYTES(bv, nb) (void)(bv += nb) + #define LOAD_STATE_VARIABLES() \ do { \ bc = ( (top_activ_stack != 0 || root_activ_vector == MAIN_VECTOR) \ @@ -778,11 +782,6 @@ do { \ return OUTCOME_ABORTED; } } - if (task_killed) { - STORE_STATE_VARIABLES(); - unwind_stack(FIN_ABORT, zero, 0); - return OUTCOME_ABORTED; - } switch (op) { case OP_IF_QUES: @@ -797,7 +796,7 @@ do { \ if (!is_true(cond)) /* jump if false */ JUMP(READ_BYTES(bv, bc.numbytes_label)); else { - bv += bc.numbytes_label; + SKIP_BYTES(bv, bc.numbytes_label); } free_var(cond); } @@ -1629,6 +1628,11 @@ do { \ PUSH_ERROR(e); } break; + case BI_KILL: + STORE_STATE_VARIABLES(); + unwind_stack(FIN_ABORT, zero, 0); + return OUTCOME_ABORTED; + /* NOTREACHED */ } } } @@ -1731,8 +1735,8 @@ do { \ free_var(POP()); /* replace list with error code */ PUSH_ERROR(e); for (i = 1; i <= nargs; i++) { - READ_BYTES(bv, bc.numbytes_var_name); - READ_BYTES(bv, bc.numbytes_label); + SKIP_BYTES(bv, bc.numbytes_var_name); + SKIP_BYTES(bv, bc.numbytes_label); } } else { nopt_avail = len - nreq; @@ -2063,7 +2067,7 @@ setup_task_execution_limits(int seconds, int ticks) { task_alarm_id = set_virtual_timer(seconds < 1 ? 1 : seconds, task_timeout, 0); - task_timed_out = task_killed = 0; + task_timed_out = 0; ticks_remaining = (ticks < 100 ? 100 : ticks); return task_alarm_id; } @@ -2348,12 +2352,6 @@ setup_activ_for_eval(Program * prog) return 1; } -void -abort_running_task(void) -{ - task_killed = 1; -} - /**** built in functions ****/ struct cf_state { @@ -2862,6 +2860,11 @@ char rcsid_execute[] = "$Id$"; /* * $Log$ + * Revision 1.11 2001/03/12 03:25:16 bjj + * Added new package type BI_KILL which kills the task calling the builtin. + * Removed the static int task_killed in execute.c which wa tested on every + * loop through the interpreter to see if the task had been killed. + * * Revision 1.10 1998/12/14 13:17:50 nop * Merge UNSAFE_OPTS (ref fixups); fix Log tag placement to fit CVS whims * diff --git a/functions.c b/functions.c index fd9b83b..4098b1f 100644 --- a/functions.c +++ b/functions.c @@ -302,6 +302,16 @@ read_bi_func_data(Byte f_id, void **bi_func_state, Byte * bi_func_pc) package +make_kill_pack() +{ + package p; + + p.kind = BI_KILL; + + return p; +} + +package make_error_pack(enum error err) { return make_raise_pack(err, unparse_error(err), zero); @@ -458,6 +468,11 @@ char rcsid_functions[] = "$Id$"; /* * $Log$ + * Revision 1.6 2001/03/12 03:25:16 bjj + * Added new package type BI_KILL which kills the task calling the builtin. + * Removed the static int task_killed in execute.c which wa tested on every + * loop through the interpreter to see if the task had been killed. + * * Revision 1.5 1998/12/14 13:17:53 nop * Merge UNSAFE_OPTS (ref fixups); fix Log tag placement to fit CVS whims * diff --git a/functions.h b/functions.h index 8661c7f..2c7efb4 100644 --- a/functions.h +++ b/functions.h @@ -30,7 +30,8 @@ typedef struct { BI_RETURN, /* Normal function return */ BI_RAISE, /* Raising an error */ BI_CALL, /* Making a nested verb call */ - BI_SUSPEND /* Suspending the current task */ + BI_SUSPEND, /* Suspending the current task */ + BI_KILL /* Kill the current task */ } kind; union { Var ret; @@ -52,6 +53,7 @@ typedef struct { void register_bi_functions(); +package make_kill_pack(); package make_error_pack(enum error err); package make_raise_pack(enum error err, const char *msg, Var value); package make_var_pack(Var v); @@ -93,6 +95,11 @@ extern void load_server_options(void); /* * $Log$ + * Revision 1.5 2001/03/12 03:25:16 bjj + * Added new package type BI_KILL which kills the task calling the builtin. + * Removed the static int task_killed in execute.c which wa tested on every + * loop through the interpreter to see if the task had been killed. + * * Revision 1.4 1998/12/14 13:17:54 nop * Merge UNSAFE_OPTS (ref fixups); fix Log tag placement to fit CVS whims * @@ -1681,13 +1681,14 @@ killing_closure(vm the_vm, const char *status, void *data) { struct kcl_data *kdata = data; - if (the_vm->task_id == kdata->id) + if (the_vm->task_id == kdata->id) { if (is_wizard(kdata->owner) || progr_of_cur_verb(the_vm) == kdata->owner) { free_vm(the_vm, 1); return TEA_KILL; } else return TEA_STOP; + } return TEA_CONTINUE; } @@ -1699,7 +1700,6 @@ kill_task(int id, Objid owner) tqueue *tq; if (id == current_task_id) { - abort_running_task(); return E_NONE; } for (tt = &waiting_tasks; *tt; tt = &((*tt)->next)) { @@ -1785,11 +1785,14 @@ kill_task(int id, Objid owner) static package bf_kill_task(Var arglist, Byte next, void *vdata, Objid progr) { - enum error e = kill_task(arglist.v.list[1].v.num, progr); + int id = arglist.v.list[1].v.num; + enum error e = kill_task(id, progr); free_var(arglist); if (e != E_NONE) return make_error_pack(e); + else if (id == current_task_id) + return make_kill_pack(); return no_var_pack(); } @@ -1948,6 +1951,11 @@ char rcsid_tasks[] = "$Id$"; /* * $Log$ + * Revision 1.6 2001/03/12 03:25:17 bjj + * Added new package type BI_KILL which kills the task calling the builtin. + * Removed the static int task_killed in execute.c which wa tested on every + * loop through the interpreter to see if the task had been killed. + * * Revision 1.5 1998/12/14 13:19:07 nop * Merge UNSAFE_OPTS (ref fixups); fix Log tag placement to fit CVS whims * |