From 994dd364e298b82f72408ac4ad7dc9dfb3e5a1f5 Mon Sep 17 00:00:00 2001 From: Stevan Andjelkovic Date: Tue, 15 Feb 2022 11:58:07 +0100 Subject: [PATCH] fix(journal): take slice into account for cas ops --- src/journal/src/Journal/Internal/ByteBufferPtr.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/journal/src/Journal/Internal/ByteBufferPtr.hs b/src/journal/src/Journal/Internal/ByteBufferPtr.hs index 18fd0092..9ef3079f 100644 --- a/src/journal/src/Journal/Internal/ByteBufferPtr.hs +++ b/src/journal/src/Journal/Internal/ByteBufferPtr.hs @@ -510,14 +510,16 @@ writeWord64OffAddr = primitiveWord_ writeWord64OffAddr# (\(W64# w#) -> w#) (size casInt32Addr :: ByteBuffer -> Int -> Int32 -> Int32 -> IO Bool casInt32Addr bb offset expected desired = do boundCheck bb offset (sizeOf (4 :: Int32)) + Slice slice <- readIORef (bbSlice bb) withForeignPtr (bbData bb) $ \ptr -> - casInt32Ptr (ptr `plusPtr` offset) expected desired + casInt32Ptr (ptr `plusPtr` (offset + slice)) expected desired casInt64Addr :: ByteBuffer -> Int -> Int64 -> Int64 -> IO Bool casInt64Addr bb offset expected desired = do - boundCheck bb offset (sizeOf (4 :: Int64)) + boundCheck bb offset (sizeOf (8 :: Int64)) + Slice slice <- readIORef (bbSlice bb) withForeignPtr (bbData bb) $ \ptr -> - casInt64Ptr (ptr `plusPtr` offset) expected desired + casInt64Ptr (ptr `plusPtr` (offset + slice)) expected desired -- | Given a bytebuffer, and offset in machine words, and a value to add, -- atomically add the value to the element. Returns the value of the element