mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-16 17:27:33 +02:00
Let GC know a thread is (potentially) blocking
This commit is contained in:
parent
6693b4533a
commit
9a9b3cc640
1 changed files with 9 additions and 1 deletions
10
runtime.c
10
runtime.c
|
@ -1487,9 +1487,12 @@ object Cyc_io_file_exists(void *data, object filename) {
|
||||||
|
|
||||||
// TODO: port arg is optional! (maybe handle that in expansion section??)
|
// TODO: port arg is optional! (maybe handle that in expansion section??)
|
||||||
object Cyc_io_read_char(void *data, object port) {
|
object Cyc_io_read_char(void *data, object port) {
|
||||||
|
int c;
|
||||||
Cyc_check_port(data, port);
|
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) {
|
if (c != EOF) {
|
||||||
return obj_char2obj(c);
|
return obj_char2obj(c);
|
||||||
}
|
}
|
||||||
|
@ -1503,14 +1506,17 @@ object Cyc_io_read_line(void *data, object cont, object port) {
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
int i = 0, c;
|
int i = 0, c;
|
||||||
|
|
||||||
|
gc_set_thread_state_blocked((gc_thread_data *)data);
|
||||||
while (1) {
|
while (1) {
|
||||||
c = fgetc(stream);
|
c = fgetc(stream);
|
||||||
if (c == EOF && i == 0) {
|
if (c == EOF && i == 0) {
|
||||||
|
gc_set_thread_state_runnable((gc_thread_data *)data);
|
||||||
return_closcall1(data, cont, Cyc_EOF);
|
return_closcall1(data, cont, Cyc_EOF);
|
||||||
} else if (c == EOF || i == 1023 || c == '\n') {
|
} else if (c == EOF || i == 1023 || c == '\n') {
|
||||||
buf[i] = '\0';
|
buf[i] = '\0';
|
||||||
{
|
{
|
||||||
make_string(s, buf);
|
make_string(s, buf);
|
||||||
|
gc_set_thread_state_runnable((gc_thread_data *)data);
|
||||||
return_closcall1(data, cont, &s);
|
return_closcall1(data, cont, &s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1527,8 +1533,10 @@ object Cyc_io_peek_char(void *data, object port) {
|
||||||
Cyc_check_port(data, port);
|
Cyc_check_port(data, port);
|
||||||
{
|
{
|
||||||
stream = ((port_type *) port)->fp;
|
stream = ((port_type *) port)->fp;
|
||||||
|
gc_set_thread_state_blocked((gc_thread_data *)data);
|
||||||
c = fgetc(stream);
|
c = fgetc(stream);
|
||||||
ungetc(c, stream);
|
ungetc(c, stream);
|
||||||
|
gc_set_thread_state_runnable((gc_thread_data *)data);
|
||||||
if (c != EOF) {
|
if (c != EOF) {
|
||||||
return obj_char2obj(c);
|
return obj_char2obj(c);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue