Skip to content

Commit

Permalink
fix(journal): take slice into account for cas ops
Browse files Browse the repository at this point in the history
  • Loading branch information
symbiont-stevan-andjelkovic committed Feb 15, 2022
1 parent 0cac51d commit 994dd36
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/journal/src/Journal/Internal/ByteBufferPtr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 994dd36

Please sign in to comment.