This commit is contained in:
Justin Ethier 2020-08-13 12:58:25 -04:00
parent 56610b7869
commit 6c39c42623
2 changed files with 18 additions and 10 deletions

View file

@ -26,12 +26,12 @@
)
(iota 1000))
(write `(Called from C set *done* to ,obj))
(write `(Called from C result is ,result set *done* to ,obj))
(newline)
(mutex-lock! lock)
(set! *done* obj)
(mutex-unlock! lock)
result))
(list list result '#())))
;; More efficient to use a condition var here to signal ready,
;; but this is just an example

View file

@ -9,6 +9,8 @@
*/
extern object __glo_signal_91done;
gc_thread_data local;
void *Cyc_init_thread(object thread_and_thunk);
/**
@ -47,12 +49,13 @@ void *c_thread(void *parent_thd)
*/
void after_call_scm(gc_thread_data *thd, int argc, object k, object result)
{
printf("after call scm\n");
// TODO: Cyc_end_thread logic to wind down thd
// TODO: other longjmp back before the scm trampoline, need to pass result (or something)
int i;
printf("after call scm %p\n", &i);
// thd->gc_cont = result;
// longjmp(*(thd->jmp_start), 1);
TODO: need to use Cyc_end_thread logic to wind down thd: run GC, ensure thread is cleaned up, etc
local.gc_cont = result;
longjmp(*(local.jmp_start), 1);
}
/**
@ -83,8 +86,9 @@ void call_thunk(void *data, int argc, object self, object k)
*/
object scm_call_with_gc(gc_thread_data *parent_thd, object fnc, object arg)
{
// TODO: build thread-and-thunk
//object thread_and_thunk = ??;
jmp_buf l;
local.gc_cont = NULL;
local.jmp_start = &l;
gc_thread_data *td = malloc(sizeof(gc_thread_data));
gc_add_new_unrunning_mutator(td); /* Register this thread */
@ -107,7 +111,11 @@ object scm_call_with_gc(gc_thread_data *parent_thd, object fnc, object arg)
make_pair(thread_and_thunk, &vec, fnc); // TODO: OK we are not clearing vec[5]? I think so...
Cyc_init_thread(&thread_and_thunk);
if (!setjmp(*(local.jmp_start))) {
Cyc_init_thread(&thread_and_thunk);
}
return local.gc_cont;
}
/**