Skip to content

Commit

Permalink
set entropy sources via compare_and_set
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesm committed Mar 28, 2024
1 parent e8cb128 commit f94fe88
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions rng/entropy.ml
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ 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 set () =
let sources = Atomic.get _sources in
let n = S.cardinal sources in
let source = (n, name) in
if Atomic.compare_and_set _sources sources (S.add source sources) then
source
else
set ()
in
set ()

let id (idx, _) = idx

Expand Down

0 comments on commit f94fe88

Please sign in to comment.