Skip to content

Commit

Permalink
Release a RefTracker even if the corresponding finaliser throws an …
Browse files Browse the repository at this point in the history
…error
  • Loading branch information
jorisdral committed Dec 30, 2024
1 parent e80f7f2 commit 0c8bac8
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src-control/Control/RefCount.hs
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ releaseRef ::
-> m ()
releaseRef ref@Ref{refobj} = do
assertNoDoubleRelease ref
decrementRefCounter (getRefCounter refobj)
releaseRefTracker ref
withReleaseRefTracker ref (decrementRefCounter (getRefCounter refobj))

{-# COMPLETE DeRef #-}
#if MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
Expand Down Expand Up @@ -383,9 +382,9 @@ instance Exception RefException where

#ifndef NO_IGNORE_ASSERTS

{-# INLINE releaseRefTracker #-}
releaseRefTracker :: PrimMonad m => Ref a -> m ()
releaseRefTracker _ = return ()
{-# INLINE withReleaseRefTracker #-}
withReleaseRefTracker :: Ref a -> m () -> m ()
withReleaseRefTracker _ref k = k

{-# INLINE assertNoUseAfterRelease #-}
assertNoUseAfterRelease :: PrimMonad m => Ref a -> m ()
Expand Down Expand Up @@ -438,6 +437,9 @@ releaseRefTracker Ref { reftracker = RefTracker _refid _weak outer } =
inner <- readIORef outer
writeIORef inner True

withReleaseRefTracker :: (PrimMonad m, MonadThrow m) => Ref a -> m () -> m ()
withReleaseRefTracker ref k = k `finally` releaseRefTracker ref

finaliserRefTracker :: IORef Bool -> RefId -> CallStack -> IO ()
finaliserRefTracker inner refid callsite = do
released <- readIORef inner
Expand Down

0 comments on commit 0c8bac8

Please sign in to comment.