Skip to content

Commit

Permalink
Use backoff to be sure to be in sync when we update sources (@reynir)
Browse files Browse the repository at this point in the history
  • Loading branch information
dinosaure committed Mar 25, 2024
1 parent ae23f11 commit b25b1e1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions rng/entropy.ml
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,15 @@ let _sources = Atomic.make S.empty
type source = Rng.source

let register_source name =
let n = S.cardinal (Atomic.get _sources) in
let source = (n, name) in
Atomic.set _sources (S.add source (Atomic.get _sources));
source
let rec go backoff =
let seen = Atomic.get _sources in
let n = S.cardinal seen in
let source = (n, name) in
let after = S.add source (Atomic.get _sources) in
if Atomic.compare_and_set _sources seen after = false
then go (Backoff.once backoff)
else source in
go Backoff.default

let id (idx, _) = idx

Expand Down

0 comments on commit b25b1e1

Please sign in to comment.