mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-19 05:39:17 +02:00
New mutator signatures
This commit is contained in:
parent
247b09fc88
commit
8aefcbfd13
2 changed files with 15 additions and 9 deletions
6
gc.c
6
gc.c
|
@ -1360,18 +1360,20 @@ void gc_thread_data_free(gc_thread_data *thd)
|
|||
}
|
||||
}
|
||||
|
||||
void gc_set_thread_blocked(gc_thread_data *thd, object cont)
|
||||
void gc_mutator_thread_blocked(gc_thread_data *thd, object cont)
|
||||
{
|
||||
ATOMIC_SET_IF_EQ(&(thd->thread_state),
|
||||
CYC_THREAD_STATE_RUNNABLE,
|
||||
CYC_THREAD_STATE_BLOCKED);
|
||||
thd->gc_cont = cont;
|
||||
}
|
||||
void gc_set_thread_runnable(gc_thread_data *thd)
|
||||
|
||||
void gc_mutator_thread_runnable(gc_thread_data *thd, object result)
|
||||
{
|
||||
ATOMIC_SET_IF_EQ(&(thd->thread_state),
|
||||
CYC_THREAD_STATE_BLOCKED,
|
||||
CYC_THREAD_STATE_RUNNABLE);
|
||||
(((closure)(thd->gc_cont))->fn)(thd, 1, thd->gc_cont, result);
|
||||
}
|
||||
|
||||
//// Unit testing:
|
||||
|
|
18
runtime.c
18
runtime.c
|
@ -1490,9 +1490,11 @@ object Cyc_io_read_char(void *data, object cont, object port) {
|
|||
int c;
|
||||
Cyc_check_port(data, port);
|
||||
{
|
||||
gc_set_thread_blocked((gc_thread_data *)data, cont);
|
||||
gc_mutator_thread_blocked((gc_thread_data *)data, cont);
|
||||
c = fgetc(((port_type *) port)->fp);
|
||||
gc_set_thread_runnable((gc_thread_data *)data);
|
||||
gc_mutator_thread_runnable(
|
||||
(gc_thread_data *)data,
|
||||
(c != EOF) ? obj_char2obj(c) : Cyc_EOF);
|
||||
if (c != EOF) {
|
||||
return obj_char2obj(c);
|
||||
}
|
||||
|
@ -1506,17 +1508,17 @@ object Cyc_io_read_line(void *data, object cont, object port) {
|
|||
char buf[1024];
|
||||
int i = 0, c;
|
||||
|
||||
gc_set_thread_blocked((gc_thread_data *)data, cont);
|
||||
gc_mutator_thread_blocked((gc_thread_data *)data, cont);
|
||||
while (1) {
|
||||
c = fgetc(stream);
|
||||
if (c == EOF && i == 0) {
|
||||
gc_set_thread_runnable((gc_thread_data *)data);
|
||||
gc_mutator_thread_runnable((gc_thread_data *)data, Cyc_EOF);
|
||||
return_closcall1(data, cont, Cyc_EOF);
|
||||
} else if (c == EOF || i == 1023 || c == '\n') {
|
||||
buf[i] = '\0';
|
||||
{
|
||||
make_string(s, buf);
|
||||
gc_set_thread_runnable((gc_thread_data *)data);
|
||||
gc_mutator_thread_runnable((gc_thread_data *)data, &s);
|
||||
return_closcall1(data, cont, &s);
|
||||
}
|
||||
}
|
||||
|
@ -1533,10 +1535,12 @@ object Cyc_io_peek_char(void *data, object cont, object port) {
|
|||
Cyc_check_port(data, port);
|
||||
{
|
||||
stream = ((port_type *) port)->fp;
|
||||
gc_set_thread_blocked((gc_thread_data *)data, cont);
|
||||
gc_mutator_thread_blocked((gc_thread_data *)data, cont);
|
||||
c = fgetc(stream);
|
||||
ungetc(c, stream);
|
||||
gc_set_thread_runnable((gc_thread_data *)data);
|
||||
gc_mutator_thread_runnable(
|
||||
(gc_thread_data *)data,
|
||||
(c != EOF) ? obj_char2obj(c) : Cyc_EOF);
|
||||
if (c != EOF) {
|
||||
return obj_char2obj(c);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue