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)) (iota 1000))
(write `(Called from C set *done* to ,obj)) (write `(Called from C result is ,result set *done* to ,obj))
(newline) (newline)
(mutex-lock! lock) (mutex-lock! lock)
(set! *done* obj) (set! *done* obj)
(mutex-unlock! lock) (mutex-unlock! lock)
result)) (list list result '#())))
;; More efficient to use a condition var here to signal ready, ;; More efficient to use a condition var here to signal ready,
;; but this is just an example ;; but this is just an example

View file

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