add collect-rendezvous

original commit: 73cf31d3625e519493918faba650bbfc303f1712
This commit is contained in:
Matthew Flatt 2018-01-22 17:01:46 -07:00
parent ef497bf210
commit a590b5ec35
6 changed files with 64 additions and 0 deletions

2
LOG
View File

@ -788,3 +788,5 @@
- fix bounds checking with an immediate index on immutable vectors, - fix bounds checking with an immediate index on immutable vectors,
fxvectors, strings, and bytevectors fxvectors, strings, and bytevectors
cpnanopass.ss, 5_5.ms, 5_6.ms, bytevector.ms cpnanopass.ss, 5_5.ms, 5_6.ms, bytevector.ms
- add collect-rendezvous
prim.c, 7.ss, primdata.ss, 7.ms, smgmt.stex

View File

@ -186,6 +186,7 @@ void S_prim_init() {
Sforeign_symbol("(cs)enable_object_counts", (void *)S_enable_object_counts); Sforeign_symbol("(cs)enable_object_counts", (void *)S_enable_object_counts);
Sforeign_symbol("(cs)set_enable_object_counts", (void *)S_set_enable_object_counts); Sforeign_symbol("(cs)set_enable_object_counts", (void *)S_set_enable_object_counts);
Sforeign_symbol("(cs)object_counts", (void *)S_object_counts); Sforeign_symbol("(cs)object_counts", (void *)S_object_counts);
Sforeign_symbol("(cs)fire_collector", (void *)S_fire_collector);
} }
static void s_instantiate_code_object() { static void s_instantiate_code_object() {

View File

@ -153,6 +153,25 @@ The system determines which generations to collect, based on \var{g} and
\var{tg} if provided, as described in the lead-in to this section. \var{tg} if provided, as described in the lead-in to this section.
%----------------------------------------------------------------------------
\entryheader
\formdef{collect-rendezvous}{\categoryprocedure}{(collect-rendezvous)}
\returns unspecified
\listlibraries
\endentryheader
\noindent
Requests a garbage collection in the same way as when the system
determines that a collection should occur. All running threads are
coordinated so that one of them calls the collect-request handler, while
the other threads pause until the handler returns.
Note that if the collect-request handler (see
\scheme{collect-request-handler}) does not call \scheme{collect}, then
\scheme{collect-rendezvous} does not actualy perform a garbage
collection.
%---------------------------------------------------------------------------- %----------------------------------------------------------------------------
\entryheader \entryheader
\formdef{collect-notify}{\categoryglobalparameter}{collect-notify} \formdef{collect-notify}{\categoryglobalparameter}{collect-notify}

View File

@ -3589,6 +3589,41 @@ evaluating module init
(or (not a) (not (assq 'static (cdr a))))) (or (not a) (not (assq 'static (cdr a)))))
) )
(mat collect-rendezvous
(begin
(define (check-working-gc collect)
(with-interrupts-disabled
(let ([p (weak-cons (gensym) #f)])
(collect)
(eq? (car p) #!bwp))))
(and (check-working-gc collect)
(check-working-gc collect-rendezvous)))
(or (not (threaded?))
(let ([m (make-mutex)]
[c (make-condition)]
[done? #f])
(fork-thread
(lambda ()
(let loop ()
(mutex-acquire m)
(cond
[done?
(condition-signal c)
(mutex-release m)]
[else
(mutex-release m)
(loop)]))))
(and (check-working-gc collect-rendezvous)
;; End thread:
(begin
(mutex-acquire m)
(set! done? #t)
(condition-wait c m)
(mutex-release m)
;; Plain `collect` should work again:
(check-working-gc collect)))))
)
;;; section 7.6: ;;; section 7.6:

6
s/7.ss
View File

@ -750,6 +750,12 @@
($oops who "invalid target generation ~s for generation ~s" gtarget g)) ($oops who "invalid target generation ~s for generation ~s" gtarget g))
(collect2 g (if (eq? gtarget 'static) (constant static-generation) gtarget))]))) (collect2 g (if (eq? gtarget 'static) (constant static-generation) gtarget))])))
(set! collect-rendezvous
(let ([fire-collector (foreign-procedure "(cs)fire_collector" () void)])
(lambda ()
(fire-collector)
($collect-rendezvous))))
(set! keyboard-interrupt-handler (set! keyboard-interrupt-handler
($make-thread-parameter ($make-thread-parameter
(lambda () (lambda ()

View File

@ -1194,6 +1194,7 @@
(clear-input-port [sig [() (input-port) -> (void)]] [flags true]) (clear-input-port [sig [() (input-port) -> (void)]] [flags true])
(clear-output-port [sig [() (output-port) -> (void)]] [flags true]) (clear-output-port [sig [() (output-port) -> (void)]] [flags true])
(collect [sig [() (sub-ufixnum) (sub-ufixnum ptr) -> (void)]] [flags true]) (collect [sig [() (sub-ufixnum) (sub-ufixnum ptr) -> (void)]] [flags true])
(collect-rendezvous [sig [() -> (void)]] [flags])
(collections [sig [() -> (uint)]] [flags unrestricted alloc]) (collections [sig [() -> (uint)]] [flags unrestricted alloc])
(compile [sig [(sub-ptr) (sub-ptr environment) -> (ptr ...)]] [flags]) (compile [sig [(sub-ptr) (sub-ptr environment) -> (ptr ...)]] [flags])
(compile-file [sig [(pathname) (pathname pathname) (pathname pathname sub-symbol) -> (void)]] [flags true]) (compile-file [sig [(pathname) (pathname pathname) (pathname pathname sub-symbol) -> (void)]] [flags true])