fix memory-management problem with #:lock-name
Repairs a bug in 290020c597
.
This commit is contained in:
parent
290020c597
commit
6f6a792d06
26
pkgs/racket-test-core/tests/racket/ffi-lock.rkt
Normal file
26
pkgs/racket-test-core/tests/racket/ffi-lock.rkt
Normal file
|
@ -0,0 +1,26 @@
|
|||
#lang racket
|
||||
(require ffi/unsafe)
|
||||
|
||||
(define (go)
|
||||
(place pch (s)))
|
||||
|
||||
(define (s)
|
||||
(define sleep (get-ffi-obj 'sleep #f (_fun #:lock-name "sleep-lock" _int -> _void)))
|
||||
(printf "start\n")
|
||||
(sleep 1)
|
||||
(printf "done\n"))
|
||||
|
||||
(module+ test
|
||||
(when (memq (system-type) '(unix macosx))
|
||||
(place-wait (go))
|
||||
;; Trigger a GC in space of place-shared objects:
|
||||
(for ([i 1000])
|
||||
(place-channel))
|
||||
(define now (current-seconds))
|
||||
(define l
|
||||
(for/list ([i 3])
|
||||
(go)))
|
||||
(map place-wait l)
|
||||
(unless ((- (current-seconds) now) . >= . 3)
|
||||
(error "didn't serialize"))))
|
||||
|
|
@ -3221,6 +3221,16 @@ static Scheme_Object *make_vector_in_master(int count, Scheme_Object *val) {
|
|||
GC_switch_back_from_master(original_gc);
|
||||
return vec;
|
||||
}
|
||||
|
||||
static void **malloc_immobile_box_in_master(Scheme_Object *v)
|
||||
{
|
||||
void **imm;
|
||||
void *original_gc;
|
||||
original_gc = GC_switch_to_master_gc();
|
||||
imm = scheme_malloc_immobile_box(v);
|
||||
GC_switch_back_from_master(original_gc);
|
||||
return imm;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void *name_to_ffi_lock(Scheme_Object *bstr)
|
||||
|
@ -3247,7 +3257,7 @@ static void *name_to_ffi_lock(Scheme_Object *bstr)
|
|||
lock = scheme_place_make_async_channel();
|
||||
lock = make_vector_in_master(2, lock);
|
||||
SCHEME_VEC_ELS(lock)[1] = scheme_make_integer(-1);
|
||||
lock_box = scheme_malloc_immobile_box(lock);
|
||||
lock_box = malloc_immobile_box_in_master(lock);
|
||||
old_lock_box = scheme_register_process_global(SCHEME_BYTE_STR_VAL(bstr), lock_box);
|
||||
if (old_lock_box) {
|
||||
scheme_free_immobile_box(lock_box);
|
||||
|
|
|
@ -2386,6 +2386,16 @@ static Scheme_Object *make_vector_in_master(int count, Scheme_Object *val) {
|
|||
GC_switch_back_from_master(original_gc);
|
||||
return vec;
|
||||
}
|
||||
|
||||
static void **malloc_immobile_box_in_master(Scheme_Object *v)
|
||||
{
|
||||
void **imm;
|
||||
void *original_gc;
|
||||
original_gc = GC_switch_to_master_gc();
|
||||
imm = scheme_malloc_immobile_box(v);
|
||||
GC_switch_back_from_master(original_gc);
|
||||
return imm;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void *name_to_ffi_lock(Scheme_Object *bstr)
|
||||
|
@ -2412,7 +2422,7 @@ static void *name_to_ffi_lock(Scheme_Object *bstr)
|
|||
lock = scheme_place_make_async_channel();
|
||||
lock = make_vector_in_master(2, lock);
|
||||
SCHEME_VEC_ELS(lock)[1] = scheme_make_integer(-1);
|
||||
lock_box = scheme_malloc_immobile_box(lock);
|
||||
lock_box = malloc_immobile_box_in_master(lock);
|
||||
old_lock_box = scheme_register_process_global(SCHEME_BYTE_STR_VAL(bstr), lock_box);
|
||||
if (old_lock_box) {
|
||||
scheme_free_immobile_box(lock_box);
|
||||
|
|
Loading…
Reference in New Issue
Block a user