klisp

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

commit fcd8ffa31614baff9fc6f92daf3b5f6055130048
parent 71b84e2ce6a73156f52624ee7f820ee8f11b1c25
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Tue, 28 Aug 2012 19:39:28 -0300

Added GIL unlocking before and locking after to input/output blocking operations, to allow other threads to run while one is blocked waiting for I/O.

Diffstat:
Msrc/ktoken.c | 5+++++
Msrc/kwrite.c | 12+++++++++++-
2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/ktoken.c b/src/ktoken.c @@ -176,7 +176,12 @@ int ktok_ggetc(klisp_State *K) if (ttisfport(port)) { /* fport */ FILE *file = kfport_file(port); + + /* LOCK: only a single lock should be acquired */ + klisp_unlock(K); int chi = getc(file); + klisp_lock(K); + if (chi == EOF) { /* NOTE: eof doesn't change source code location info */ if (ferror(file) != 0) { diff --git a/src/kwrite.c b/src/kwrite.c @@ -54,7 +54,10 @@ void kw_printf(klisp_State *K, const char *format, ...) if (ttisfport(port)) { FILE *file = kfport_file(port); va_start(argp, format); + /* LOCK: only a single lock should be acquired */ + klisp_unlock(K); int ret = vfprintf(file, format, argp); + klisp_lock(K); va_end(argp); if (ret < 0) { @@ -907,7 +910,9 @@ void kwrite_char_to_port(klisp_State *K, TValue port, TValue ch) if (ttisfport(port)) { FILE *file = kfport_file(port); + klisp_unlock(K); int res = fputc(chvalue(ch), file); + klisp_lock(K); if (res == EOF) { clearerr(file); /* clear error for next time */ @@ -945,7 +950,9 @@ void kwrite_u8_to_port(klisp_State *K, TValue port, TValue u8) i/o functions set it */ if (ttisfport(port)) { FILE *file = kfport_file(port); + klisp_unlock(K); int res = fputc(ivalue(u8), file); + klisp_lock(K); if (res == EOF) { clearerr(file); /* clear error for next time */ @@ -985,7 +992,10 @@ void kwrite_flush_port(klisp_State *K, TValue port) if (ttisfport(port)) { /* only necessary for file ports */ FILE *file = kfport_file(port); klisp_assert(file); - if ((fflush(file)) == EOF) { + klisp_unlock(K); + int res = fflush(file); + klisp_lock(K); + if (res == EOF) { clearerr(file); /* clear error for next time */ kwrite_error(K, "error writing"); }