diff --git a/include/cyclone/runtime.h b/include/cyclone/runtime.h index e2f898b6..d7ec7d42 100644 --- a/include/cyclone/runtime.h +++ b/include/cyclone/runtime.h @@ -198,6 +198,7 @@ void Cyc_exit_thread(gc_thread_data *thd); object Cyc_thread_sleep(void *data, object timeout); void GC(void *,closure,object*,int); object Cyc_trigger_minor_gc(void *data, object cont); +object copy2heap(void *data, object obj); void Cyc_st_add(void *data, char *frame); void Cyc_st_print(void *data, FILE *out); diff --git a/runtime.c b/runtime.c index b86c8712..6b6c4f44 100644 --- a/runtime.c +++ b/runtime.c @@ -2866,16 +2866,15 @@ object Cyc_thread_sleep(void *data, object timeout) return boolean_t; } -// WIP for something to use to debug/use for threads -//object copy2heap(void *data, object obj) -//{ -// char stack_pos; -// gc_thread_data *thd = (gc_thread_data *)data; -// int on_stack = check_overflow(&stack_pos, obj) && -// check_overflow(obj, thd->stack_start); -// if (!is_object_type(obj) || !on_stack) { -// return obj; -// } -// -// return gc_alloc(Cyc_heap, gc_allocated_bytes(obj, NULL, NULL), obj, data, &on_stack); -//} +object copy2heap(void *data, object obj) +{ + char stack_pos; + gc_thread_data *thd = (gc_thread_data *)data; + int on_stack = check_overflow((object)(&stack_pos), obj) && + check_overflow(obj, (object)thd->stack_start); + if (!is_object_type(obj) || !on_stack) { + return obj; + } + + return gc_alloc(Cyc_heap, gc_allocated_bytes(obj, NULL, NULL), obj, data, &on_stack); +} diff --git a/srfi/18.sld b/srfi/18.sld index bb75fee2..8fd37b75 100644 --- a/srfi/18.sld +++ b/srfi/18.sld @@ -10,6 +10,7 @@ thread-yield! ; thread-terminate! ; For now, these are built-ins. No need for them here: make-mutex mutex-lock! mutex-unlock! + ->heap ) (begin ;; Threading @@ -45,4 +46,8 @@ (define (thread-yield!) (thread-sleep! 1)) ; (define (thread-terminate!) (Cyc-end-thread!)) ;; TODO: thread-join! + (define-c ->heap + "(void *data, int argc, closure _, object k, object obj)" + " object heap_obj = copy2heap(data, obj); + return_closcall1(data, k, heap_obj); ") ))