mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-06 12:46:35 +02:00
Cleanup of blocked/runnable api
This commit is contained in:
parent
4b4c7db062
commit
dcf4bfafcf
2 changed files with 10 additions and 25 deletions
|
@ -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();
|
||||
|
|
33
runtime.c
33
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue