mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-10 05:03:58 -05:00
compat 4.08
This commit is contained in:
parent
bfcf7f774e
commit
052b70027a
1 changed files with 4 additions and 2 deletions
|
|
@ -1,5 +1,7 @@
|
|||
(* see: https://discuss.ocaml.org/t/a-hack-to-implement-efficient-tls-thread-local-storage/13264 *)
|
||||
|
||||
module A = Atomic_
|
||||
|
||||
(* sanity check *)
|
||||
let () = assert (Obj.field (Obj.repr (Thread.self ())) 1 = Obj.repr ())
|
||||
|
||||
|
|
@ -11,13 +13,13 @@ type 'a key = {
|
|||
}
|
||||
|
||||
(** Counter used to allocate new keys *)
|
||||
let counter = Atomic.make 0
|
||||
let counter = A.make 0
|
||||
|
||||
(** Value used to detect a TLS slot that was not initialized yet *)
|
||||
let[@inline] sentinel_value_for_uninit_tls_ () : Obj.t = Obj.repr counter
|
||||
|
||||
let new_key compute : _ key =
|
||||
let index = Atomic.fetch_and_add counter 1 in
|
||||
let index = A.fetch_and_add counter 1 in
|
||||
{ index; compute }
|
||||
|
||||
type thread_internal_state = {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue