Skip to content

Commit

Permalink
Cargo-cult some uses of atomicModifyIORef.
Browse files Browse the repository at this point in the history
This seems to make no difference to performance, but I haven't looked at
memory usage.
  • Loading branch information
bos committed Jan 30, 2010
1 parent 40c043a commit 82af25a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/System/Event/Array.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE CPP, ForeignFunctionInterface #-}
{-# LANGUAGE BangPatterns, CPP, ForeignFunctionInterface #-}

module System.Event.Array
(
Expand Down Expand Up @@ -162,8 +162,10 @@ snoc (Array ref) e = do
writeIORef ref (AC es len' cap)

clear :: Storable a => Array a -> IO ()
clear (Array ref) = atomicModifyIORef ref $ \(AC es _ cap) ->
let !e = AC es 0 cap in (e, ())
clear (Array ref) = do
!_ <- atomicModifyIORef ref $ \(AC es _ cap) ->
let e = AC es 0 cap in (e, e)
return ()

forM_ :: Storable a => Array a -> (a -> IO ()) -> IO ()
forM_ ary g = forHack ary g undefined
Expand Down
8 changes: 4 additions & 4 deletions src/System/Event/Manager.hs
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ registerTimeout mgr ms cb = do
now <- getCurrentTime
let expTime = fromIntegral ms / 1000.0 + now

atomicModifyIORef (emTimeouts mgr) $ \q ->
let !q' = Q.insert key expTime cb q in (q', ())
!_ <- atomicModifyIORef (emTimeouts mgr) $ \q ->
let q' = Q.insert key expTime cb q in (q', q')
wakeManager mgr
return $! TK key

Expand All @@ -278,8 +278,8 @@ updateTimeout mgr (TK key) ms = do
now <- getCurrentTime
let expTime = fromIntegral ms / 1000.0 + now

atomicModifyIORef (emTimeouts mgr) $ \q ->
let !q' = Q.adjust (const expTime) key q in (q', ())
!_ <- atomicModifyIORef (emTimeouts mgr) $ \q ->
let q' = Q.adjust (const expTime) key q in (q', q')
wakeManager mgr

------------------------------------------------------------------------
Expand Down

0 comments on commit 82af25a

Please sign in to comment.