Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove first memory leak in the node controller
There is at least one other (PINNED) memory leak :-/
- Loading branch information
Showing
6 changed files
with
129 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
distributed-process/src/Control/Distributed/Process/Internal/StrictMVar.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
-- | Like Control.Concurrent.MVar.Strict but reduce to HNF, not NF | ||
module Control.Distributed.Process.Internal.StrictMVar | ||
( StrictMVar | ||
, newEmptyMVar | ||
, newMVar | ||
, takeMVar | ||
, putMVar | ||
, withMVar | ||
, modifyMVar_ | ||
, modifyMVar | ||
) where | ||
|
||
import Control.Applicative ((<$>)) | ||
import Control.Monad ((>=>)) | ||
import Control.Exception (evaluate) | ||
import qualified Control.Concurrent.MVar as MVar | ||
( MVar | ||
, newEmptyMVar | ||
, newMVar | ||
, takeMVar | ||
, putMVar | ||
, withMVar | ||
, modifyMVar_ | ||
, modifyMVar | ||
) | ||
|
||
newtype StrictMVar a = StrictMVar (MVar.MVar a) | ||
|
||
newEmptyMVar :: IO (StrictMVar a) | ||
newEmptyMVar = StrictMVar <$> MVar.newEmptyMVar | ||
|
||
newMVar :: a -> IO (StrictMVar a) | ||
newMVar x = evaluate x >> StrictMVar <$> MVar.newMVar x | ||
|
||
takeMVar :: StrictMVar a -> IO a | ||
takeMVar (StrictMVar v) = MVar.takeMVar v | ||
|
||
putMVar :: StrictMVar a -> a -> IO () | ||
putMVar (StrictMVar v) x = evaluate x >> MVar.putMVar v x | ||
|
||
withMVar :: StrictMVar a -> (a -> IO b) -> IO b | ||
withMVar (StrictMVar v) = MVar.withMVar v | ||
|
||
modifyMVar_ :: StrictMVar a -> (a -> IO a) -> IO () | ||
modifyMVar_ (StrictMVar v) f = MVar.modifyMVar_ v (f >=> evaluate) | ||
|
||
modifyMVar :: StrictMVar a -> (a -> IO (a, b)) -> IO b | ||
modifyMVar (StrictMVar v) f = MVar.modifyMVar v (f >=> evaluateFst) | ||
where | ||
evaluateFst :: (a, b) -> IO (a, b) | ||
evaluateFst (x, y) = evaluate x >> return (x, y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters