klisp

an open source interpreter for the Kernel Programming Language.
git clone http://git.hanabi.in/repos/klisp.git
Log | Files | Refs | README

commit 1cbb0fee5daf4ca4375a0427376dbce9f186464d
parent 42406a0400c3ba8779c4de6023df6162132d24ea
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Tue, 28 Aug 2012 20:21:48 -0300

Added locking to the main interpreter.  This was needed to allow threads to be created in all the stages of the interpreter (init, argument evaluation, script executing, etc)

Diffstat:
Msrc/klisp.c | 17+++++++++++++++++
Msrc/krepl.c | 1+
2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/src/klisp.c b/src/klisp.c @@ -170,6 +170,8 @@ static void print_version(void) static int dostring (klisp_State *K, const char *s, const char *name) { + klisp_lock(K); + bool errorp = false; /* may be set to true in error handler */ bool rootp = true; /* may be set to false in continuation */ @@ -233,6 +235,9 @@ static int dostring (klisp_State *K, const char *s, const char *name) krooted_tvs_pop(K); klispT_tail_call_si(K, ev, ptree, env, KNIL); + + klisp_unlock(K); + /* LOCK: run while acquire the GIL again */ klispT_run(K); int status = errorp? STATUS_ERROR : @@ -276,6 +281,7 @@ void do_file_read(klisp_State *K) /* name = NULL means use stdin */ static int dofile(klisp_State *K, const char *name) { + klisp_lock(K); bool errorp = false; /* may be set to true in error handler */ bool rootp = true; /* may be set to false in continuation */ @@ -361,6 +367,8 @@ static int dofile(klisp_State *K, const char *name) kset_cc(K, read_cont); /* this will protect all conts from gc */ klispT_apply_cc(K, KINERT); + klisp_unlock(K); + /* LOCK: run while acquire the GIL again */ klispT_run(K); int status = errorp? STATUS_ERROR : @@ -373,8 +381,11 @@ static int dofile(klisp_State *K, const char *name) static void dotty(klisp_State *K) { + klisp_lock(K); TValue env = K->next_env; kinit_repl(K); + klisp_unlock(K); + /* LOCK: run while acquire the GIL again */ klispT_run(K); /* get the standard environment again in K->next_env */ K->next_env = env; @@ -383,6 +394,7 @@ static void dotty(klisp_State *K) /* name != NULL */ static int dorfile(klisp_State *K, const char *name) { + klisp_lock(K); bool errorp = false; /* may be set to true in error handler */ bool rootp = true; /* may be set to false in continuation */ @@ -447,6 +459,8 @@ static int dorfile(klisp_State *K, const char *name) krooted_vars_pop(K); klispT_tail_call_si(K, req, ptree, env, KNIL); + klisp_unlock(K); + /* LOCK: run while acquire the GIL again */ klispT_run(K); int status = errorp? STATUS_ERROR : @@ -567,6 +581,7 @@ static int runargs (klisp_State *K, char **argv, int n) return STATUS_CONTINUE; } +/* LOCK: assume that the GIL is acquired */ static void populate_argument_lists(klisp_State *K, char **argv, int argc, int script) { @@ -664,7 +679,9 @@ static void pmain(klisp_State *K) /* TEMP this could be either set before or after running the arguments, we'll do it before for now */ + klisp_lock(K); populate_argument_lists(K, argv, s->argc, (script > 0) ? script : s->argc); + klisp_unlock(K); s->status = runargs(K, argv, (script > 0) ? script : s->argc); diff --git a/src/krepl.c b/src/krepl.c @@ -246,6 +246,7 @@ void do_repl_int_error(klisp_State *K) /* call this to init the repl in a newly created klisp state */ /* the standard environment should be in K->next_env */ +/* LOCK: the GIL should be acquired */ void kinit_repl(klisp_State *K) { TValue std_env = K->next_env;