1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-01 01:40:21 +02:00

* syncase.scm: add a simple mutex to gensym.

This commit is contained in:
Rob Browning 2002-03-03 20:37:41 +00:00
parent b7231e130b
commit a204408fb8

View file

@ -167,18 +167,25 @@
;; multiple calls to gensym, not globally unique.
;;
(define gensym
(let ((counter 0))
(let ((counter 0)
(symlock (make-mutex)))
(lambda (. rest)
(let ((val (number->string counter)))
(set! counter (+ counter 1))
(cond
((null? rest)
(string->symbol (string-append "syntmp-" val)))
((null? (cdr rest))
(string->symbol (string-append "syntmp-" (car rest) "-" val)))
(else
(error
"syncase's gensym called with the wrong number of arguments")))))))
(lock-mutex symlock)
(let* ((val (number->string counter))
(result
(set! counter (+ counter 1))
(cond
((null? rest)
(string->symbol (string-append "syntmp-" val)))
((null? (cdr rest))
(string->symbol (string-append "syntmp-" (car rest) "-" val)))
(else
'bad-args))))
(unlock-mutex symlock)
(if (eq? result 'bad-args)
(error
"syncase's gensym called with the wrong number of arguments")
result)))))
;;; Load the preprocessed code