diff options
author | Ben Gamari <ben@smart-cactus.org> | 2023-03-15 20:50:38 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2023-05-09 08:41:53 -0400 |
commit | 81cfefd2cfb9d97a19d8e543130f94248e667330 (patch) | |
tree | f2b2bc724572fbcaca8c5370c38214f7a5aeb649 /libraries | |
parent | b970e64fb2dd6d65e6e14a7e57bbc0e2eef663a7 (diff) | |
download | haskell-81cfefd2cfb9d97a19d8e543130f94248e667330.tar.gz |
compiler: Implement atomicSwapIORef with xchg
As requested by @treeowl in CLC#139.
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/base/GHC/IORef.hs | 7 |
1 files changed, 1 insertions, 6 deletions
diff --git a/libraries/base/GHC/IORef.hs b/libraries/base/GHC/IORef.hs index f451746dcb..fe65b669fd 100644 --- a/libraries/base/GHC/IORef.hs +++ b/libraries/base/GHC/IORef.hs @@ -127,12 +127,7 @@ atomicModifyIORef'_ ref f = do -- | Atomically replace the contents of an 'IORef', returning -- the old contents. atomicSwapIORef :: IORef a -> a -> IO a --- Bad implementation! This will be a primop shortly. -atomicSwapIORef (IORef (STRef ref)) new = IO $ \s -> - case atomicModifyMutVar2# ref (\_old -> Box new) s of - (# s', old, Box _new #) -> (# s', old #) - -data Box a = Box a +atomicSwapIORef (IORef (STRef ref)) new = IO (atomicSwapMutVar# ref new) -- | A strict version of 'Data.IORef.atomicModifyIORef'. This forces both the -- value stored in the 'IORef' and the value returned. |