Issue #118 - Added current-thread

This commit is contained in:
Justin Ethier 2016-11-21 16:54:34 -05:00
parent 97fa0c2dbd
commit 2bee1575c0
2 changed files with 18 additions and 6 deletions

6
gc.c
View file

@ -1044,9 +1044,9 @@ void gc_mut_cooperate(gc_thread_data * thd, int buf_len)
gc_mark_gray(thd, thd->gc_args[i]); gc_mark_gray(thd, thd->gc_args[i]);
} }
// Mark thread object, if applicable. Very likely this is its only ref // Mark thread object, if applicable. Very likely this is its only ref
// if (thd->scm_thread_obj) { if (thd->scm_thread_obj) {
// gc_mark_gray(thd, thd->scm_thread_obj); gc_mark_gray(thd, thd->scm_thread_obj);
// } }
// Also, mark everything the collector moved to the heap // Also, mark everything the collector moved to the heap
for (i = 0; i < buf_len; i++) { for (i = 0; i < buf_len; i++) {
gc_mark_gray(thd, thd->moveBuf[i]); gc_mark_gray(thd, thd->moveBuf[i]);

View file

@ -18,7 +18,7 @@
thread-sleep! thread-sleep!
thread-yield! thread-yield!
thread-terminate! thread-terminate!
;; TODO: current-thread current-thread
;; TODO: thread-join! ;; TODO: thread-join!
mutex? mutex?
@ -72,8 +72,19 @@
(define (thread-specific t) (vector-ref t 4)) (define (thread-specific t) (vector-ref t 4))
(define (thread-specific-set! t obj) (vector-set! t 4 obj)) (define (thread-specific-set! t obj) (vector-set! t 4 obj))
; TODO: (define (current-thread)
; current-thread - not sure how to look this up yet... may need a global list of running threads. Unfortunately need the vector here (let ((t (%current-thread)))
(if (null? t)
*primordial-thread*
t)))
(define *primordial-thread*
(vector 'cyc-thread-obj #f #f "main thread" #f))
(define-c %current-thread
"(void *data, int argc, closure _, object k)"
" gc_thread_data *td = (gc_thread_data *)data;
return_closcall1(data, k, td->scm_thread_obj); ")
(define (thread-start! t) (define (thread-start! t)
;; Initiate a GC prior to running the thread, in case ;; Initiate a GC prior to running the thread, in case
@ -83,6 +94,7 @@
(Cyc-minor-gc) (Cyc-minor-gc)
(let ((mutator-id (Cyc-spawn-thread! thread-params))) (let ((mutator-id (Cyc-spawn-thread! thread-params)))
(vector-set! t 2 mutator-id)))) (vector-set! t 2 mutator-id))))
(define (thread-yield!) (thread-sleep! 1)) (define (thread-yield!) (thread-sleep! 1))
(define-c thread-terminate! (define-c thread-terminate!
"(void *data, int argc, closure _, object k)" "(void *data, int argc, closure _, object k)"