Wrap use of mutexes with call-with-blocked-asyncs
As this will hopefully avoid problems with mutexes when using fibers.
This commit is contained in:
parent
35dc26c0ea
commit
fbd64347fb
1 changed files with 70 additions and 60 deletions
|
|
@ -294,12 +294,14 @@ values are the values."
|
|||
(canonicalise-label-values label-values))
|
||||
(hash
|
||||
(metric-values metric)))
|
||||
(call-with-blocked-asyncs
|
||||
(lambda ()
|
||||
(with-mutex (metric-mutex metric)
|
||||
(hash-set! hash
|
||||
canonical-labels
|
||||
(+ by
|
||||
(or (hash-ref hash canonical-labels)
|
||||
0))))))
|
||||
0))))))))
|
||||
|
||||
(define* (metric-decrement metric
|
||||
#:key
|
||||
|
|
@ -320,12 +322,14 @@ values are the values."
|
|||
(canonicalise-label-values label-values))
|
||||
(hash
|
||||
(metric-values metric)))
|
||||
(call-with-blocked-asyncs
|
||||
(lambda ()
|
||||
(with-mutex (metric-mutex metric)
|
||||
(hash-set! hash
|
||||
canonical-labels
|
||||
(+ (* -1 by)
|
||||
(or (hash-ref hash canonical-labels)
|
||||
0))))))
|
||||
0))))))))
|
||||
|
||||
(define* (metric-set metric value
|
||||
#:key (label-values '()))
|
||||
|
|
@ -340,10 +344,12 @@ values are the values."
|
|||
'(gauge))
|
||||
(error "can only set gauge metrics"))
|
||||
|
||||
(call-with-blocked-asyncs
|
||||
(lambda ()
|
||||
(with-mutex (metric-mutex metric)
|
||||
(hash-set! (metric-values metric)
|
||||
(canonicalise-label-values label-values)
|
||||
value)))
|
||||
value)))))
|
||||
|
||||
(define* (metric-observe metric value
|
||||
#:key (label-values '()))
|
||||
|
|
@ -363,6 +369,8 @@ values are the values."
|
|||
(hash
|
||||
(metric-values metric)))
|
||||
|
||||
(call-with-blocked-asyncs
|
||||
(lambda ()
|
||||
(with-mutex (metric-mutex metric)
|
||||
(let* ((buckets
|
||||
(histogram-metric-type-buckets (metric-type metric)))
|
||||
|
|
@ -395,7 +403,7 @@ values are the values."
|
|||
(vector-ref bucket-values-vector
|
||||
index)))))
|
||||
(iota (length buckets))
|
||||
buckets))))))
|
||||
buckets))))))))
|
||||
|
||||
(define* (call-with-duration-metric registry metric-name thunk
|
||||
#:key
|
||||
|
|
@ -413,6 +421,8 @@ The metric with the name @var{metric-name} is fetched from the
|
|||
"
|
||||
(let* ((metric
|
||||
(or (metrics-registry-fetch-metric registry metric-name)
|
||||
(call-with-blocked-asyncs
|
||||
(lambda ()
|
||||
(monitor
|
||||
;; Check once more in case another thread has created
|
||||
;; the metric while this thread was waiting for the
|
||||
|
|
@ -424,7 +434,7 @@ The metric with the name @var{metric-name} is fetched from the
|
|||
#:buckets buckets
|
||||
#:docstring docstring
|
||||
#:labels labels
|
||||
#:label-preset-values label-preset-values)))))
|
||||
#:label-preset-values label-preset-values)))))))
|
||||
(start-time (get-internal-real-time)))
|
||||
(call-with-values
|
||||
thunk
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue