mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-20 14:19:17 +02:00
Support mutex in the called Scheme code
This commit is contained in:
parent
c4f65c993d
commit
3b9daff384
2 changed files with 16 additions and 8 deletions
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
(include-c-header "sys.h")
|
(include-c-header "sys.h")
|
||||||
|
|
||||||
|
(define lock (make-mutex))
|
||||||
(define *done* #f)
|
(define *done* #f)
|
||||||
(define *dummy signal-done) ;; Hack to prevent optimizing out signal-done
|
(define *dummy signal-done) ;; Hack to prevent optimizing out signal-done
|
||||||
|
|
||||||
|
@ -16,14 +17,19 @@
|
||||||
(define (signal-done obj)
|
(define (signal-done obj)
|
||||||
(write `(Called from C set *done* to ,obj))
|
(write `(Called from C set *done* to ,obj))
|
||||||
(newline)
|
(newline)
|
||||||
|
(mutex-lock! lock)
|
||||||
(set! *done* obj)
|
(set! *done* obj)
|
||||||
#t)
|
(mutex-unlock! lock)
|
||||||
|
#u8(1 2 3))
|
||||||
|
|
||||||
;; 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
|
||||||
(define (wait)
|
(define (wait)
|
||||||
(thread-sleep! 1)
|
(thread-sleep! 1)
|
||||||
(if *done*
|
(mutex-lock! lock)
|
||||||
|
(define done *done*)
|
||||||
|
(mutex-unlock! lock)
|
||||||
|
(if done
|
||||||
#t
|
#t
|
||||||
(wait)))
|
(wait)))
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ void call_scm(gc_thread_data *thd, object obj)
|
||||||
* or re-allocated (EG: malloc) before returning it
|
* or re-allocated (EG: malloc) before returning it
|
||||||
* to the C layer.
|
* to the C layer.
|
||||||
*/
|
*/
|
||||||
void c_trampoline(gc_thread_data *parent_thd, function_type fnc, object arg)
|
object c_trampoline(gc_thread_data *parent_thd, function_type fnc, object arg)
|
||||||
{
|
{
|
||||||
long stack_size = 100000;
|
long stack_size = 100000;
|
||||||
char *stack_base = (char *)&stack_size;
|
char *stack_base = (char *)&stack_size;
|
||||||
|
@ -66,6 +66,7 @@ void c_trampoline(gc_thread_data *parent_thd, function_type fnc, object arg)
|
||||||
//thd.gc_cont = NULL;
|
//thd.gc_cont = NULL;
|
||||||
|
|
||||||
thd.thread_id = pthread_self();
|
thd.thread_id = pthread_self();
|
||||||
|
thd.thread_state = CYC_THREAD_STATE_RUNNABLE;
|
||||||
|
|
||||||
//thd.exception_handler_stack = NULL; // Default
|
//thd.exception_handler_stack = NULL; // Default
|
||||||
|
|
||||||
|
@ -94,12 +95,9 @@ void c_trampoline(gc_thread_data *parent_thd, function_type fnc, object arg)
|
||||||
|
|
||||||
|
|
||||||
if (!setjmp(*(thd.jmp_start))) {
|
if (!setjmp(*(thd.jmp_start))) {
|
||||||
//wait_and_signal(&thd);
|
|
||||||
fnc(&thd, arg);
|
fnc(&thd, arg);
|
||||||
} else {
|
} else {
|
||||||
printf("Received: ");
|
return(thd.gc_cont);
|
||||||
Cyc_write(&thd, thd.gc_cont, stdout);
|
|
||||||
printf("\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +109,11 @@ void c_trampoline(gc_thread_data *parent_thd, function_type fnc, object arg)
|
||||||
*/
|
*/
|
||||||
void *c_thread(void *arg)
|
void *c_thread(void *arg)
|
||||||
{
|
{
|
||||||
c_trampoline(arg, (function_type)call_scm, boolean_t);
|
object obj = c_trampoline(arg, (function_type)call_scm, boolean_t);
|
||||||
|
|
||||||
|
printf("C received: ");
|
||||||
|
Cyc_write(NULL, obj, stdout);
|
||||||
|
printf("\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue