From 54201a4e28dc9cb4c854c2ad8eee1046e0fdc891 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Tue, 22 Mar 2022 21:34:46 -0400 Subject: [PATCH] fix(atomic): prevent race conditions under flambda, for now --- src/core/CCAtomic.ml | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/core/CCAtomic.ml b/src/core/CCAtomic.ml index dbdc8061..94bfe49a 100644 --- a/src/core/CCAtomic.ml +++ b/src/core/CCAtomic.ml @@ -12,24 +12,37 @@ type 'a t = {mutable x: 'a} let[@inline] make x = {x} let[@inline] get {x} = x let[@inline] set r x = r.x <- x -let[@inline] exchange r x = +let[@inline never] exchange r x = + (* atomic *) let y = r.x in r.x <- x; + (* atomic *) y -let[@inline] compare_and_set r seen v = +let[@inline never] compare_and_set r seen v = + (* atomic *) if r.x == seen then ( r.x <- v; + (* atomic *) true ) else false -let[@inline] fetch_and_add r x = +let[@inline never] fetch_and_add r x = + (* atomic *) let v = r.x in r.x <- x + r.x; + (* atomic *) v -let[@inline] incr r = r.x <- 1 + r.x -let[@inline] decr r = r.x <- r.x - 1 +let[@inline never] incr r = + (* atomic *) + r.x <- 1 + r.x + (* atomic *) +let[@inline never] decr r = + (* atomic *) + r.x <- r.x - 1 + (* atomic *) [@@@endif] +