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:
parent
b7231e130b
commit
a204408fb8
1 changed files with 18 additions and 11 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue