From dcf4bfafcfa5bf7c0f64c10b7f644602311eb38d Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Thu, 21 Jan 2016 21:36:55 -0500 Subject: [PATCH] Cleanup of blocked/runnable api --- include/cyclone/types.h | 2 +- runtime.c | 33 +++++++++------------------------ 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/include/cyclone/types.h b/include/cyclone/types.h index 711df45b..4a53f090 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -428,7 +428,7 @@ void gc_start_collector(); void gc_mutator_thread_blocked(gc_thread_data *thd, object cont); void gc_mutator_thread_runnable(gc_thread_data *thd, object result); #define set_thread_blocked(d, c) \ - gc_mutator_thread_blocked(((gc_thread_data *)d), (r)) + gc_mutator_thread_blocked(((gc_thread_data *)d), (c)) #define return_thread_runnable(d, r) \ gc_mutator_thread_runnable(((gc_thread_data *)d), (r)) gc_heap *gc_get_heap(); diff --git a/runtime.c b/runtime.c index 75280e57..3ac7a4c8 100644 --- a/runtime.c +++ b/runtime.c @@ -1249,15 +1249,12 @@ object Cyc_make_mutex(void *data) { object Cyc_mutex_lock(void *data, object cont, object obj) { mutex m = (mutex) obj; Cyc_check_mutex(data, obj); - gc_mutator_thread_blocked((gc_thread_data *)data, cont); + set_thread_blocked(data, cont); if (pthread_mutex_lock(&(m->lock)) != 0) { fprintf(stderr, "Error locking mutex\n"); exit(1); } - gc_mutator_thread_runnable( - (gc_thread_data *)data, - boolean_t); - return boolean_t; + return_thread_runnable(data, boolean_t); } object Cyc_mutex_unlock(void *data, object obj) { @@ -1546,14 +1543,9 @@ object Cyc_io_read_char(void *data, object cont, object port) { int c; Cyc_check_port(data, port); { - gc_mutator_thread_blocked((gc_thread_data *)data, cont); + set_thread_blocked(data, cont); c = fgetc(((port_type *) port)->fp); - gc_mutator_thread_runnable( - (gc_thread_data *)data, - (c != EOF) ? obj_char2obj(c) : Cyc_EOF); - if (c != EOF) { - return obj_char2obj(c); - } + return_thread_runnable(data, (c != EOF) ? obj_char2obj(c) : Cyc_EOF); } return Cyc_EOF; } @@ -1564,18 +1556,16 @@ object Cyc_io_read_line(void *data, object cont, object port) { char buf[1024]; int i = 0, c; - gc_mutator_thread_blocked((gc_thread_data *)data, cont); + set_thread_blocked(data, cont); while (1) { c = fgetc(stream); if (c == EOF && i == 0) { - gc_mutator_thread_runnable((gc_thread_data *)data, Cyc_EOF); - return_closcall1(data, cont, Cyc_EOF); + return_thread_runnable(data, Cyc_EOF); } else if (c == EOF || i == 1023 || c == '\n') { buf[i] = '\0'; { make_string(s, buf); - gc_mutator_thread_runnable((gc_thread_data *)data, &s); - return_closcall1(data, cont, &s); + return_thread_runnable(data, &s); } } @@ -1591,15 +1581,10 @@ object Cyc_io_peek_char(void *data, object cont, object port) { Cyc_check_port(data, port); { stream = ((port_type *) port)->fp; - gc_mutator_thread_blocked((gc_thread_data *)data, cont); + set_thread_blocked(data, cont); c = fgetc(stream); ungetc(c, stream); - gc_mutator_thread_runnable( - (gc_thread_data *)data, - (c != EOF) ? obj_char2obj(c) : Cyc_EOF); - if (c != EOF) { - return obj_char2obj(c); - } + return_thread_runnable(data, (c != EOF) ? obj_char2obj(c) : Cyc_EOF); } return Cyc_EOF; }