Let GC know a thread is (potentially) blocking

This commit is contained in:
Justin Ethier 2015-12-22 22:24:11 -05:00
parent 6693b4533a
commit 9a9b3cc640

View file

@ -1487,9 +1487,12 @@ object Cyc_io_file_exists(void *data, object filename) {
// TODO: port arg is optional! (maybe handle that in expansion section??)
object Cyc_io_read_char(void *data, object port) {
int c;
Cyc_check_port(data, port);
{
int c = fgetc(((port_type *) port)->fp);
gc_set_thread_state_blocked((gc_thread_data *)data);
c = fgetc(((port_type *) port)->fp);
gc_set_thread_state_runnable((gc_thread_data *)data);
if (c != EOF) {
return obj_char2obj(c);
}
@ -1503,14 +1506,17 @@ object Cyc_io_read_line(void *data, object cont, object port) {
char buf[1024];
int i = 0, c;
gc_set_thread_state_blocked((gc_thread_data *)data);
while (1) {
c = fgetc(stream);
if (c == EOF && i == 0) {
gc_set_thread_state_runnable((gc_thread_data *)data);
return_closcall1(data, cont, Cyc_EOF);
} else if (c == EOF || i == 1023 || c == '\n') {
buf[i] = '\0';
{
make_string(s, buf);
gc_set_thread_state_runnable((gc_thread_data *)data);
return_closcall1(data, cont, &s);
}
}
@ -1527,8 +1533,10 @@ object Cyc_io_peek_char(void *data, object port) {
Cyc_check_port(data, port);
{
stream = ((port_type *) port)->fp;
gc_set_thread_state_blocked((gc_thread_data *)data);
c = fgetc(stream);
ungetc(c, stream);
gc_set_thread_state_runnable((gc_thread_data *)data);
if (c != EOF) {
return obj_char2obj(c);
}