Permalink
Browse files

Made externalMulti thread-safe.

  • Loading branch information...
takano-akio committed Jan 29, 2012
1 parent 5b2899a commit 6c1695b896bafca07f6cf5f7bd6b4a1701352c0b
Showing with 9 additions and 12 deletions.
  1. +3 −4 FRP/Elerea/Clocked.hs
  2. +3 −4 FRP/Elerea/Param.hs
  3. +3 −4 FRP/Elerea/Simple.hs
View
@@ -530,10 +530,9 @@ externalMulti :: IO (SignalGen (Signal [a]), a -> IO ()) -- ^ a generator for th
externalMulti = do
var <- newMVar []
return (SG $ \gpool _pool -> do
- let sig = S $ readMVar var
- update <- mkWeak sig (return (),takeMVar var >> putMVar var []) Nothing
- modifyIORef gpool (USig update:)
- return sig
+ ref <- newIORef (Ready undefined)
+ let sample = modifyMVar var $ \list -> memoise ref list >> return ([], list)
+ addSignal (const sample) (const (() <$ sample)) ref gpool
,\val -> do
vals <- takeMVar var
putMVar var (val:vals)
View
@@ -434,10 +434,9 @@ externalMulti :: IO (SignalGen p (Signal [a]), a -> IO ()) -- ^ a generator for
externalMulti = do
var <- newMVar []
return (SG $ \pool _ -> do
- let sig = S $ readMVar var
- update <- mkWeak sig (return (),takeMVar var >> putMVar var []) Nothing
- modifyIORef pool (update:)
- return sig
+ ref <- newIORef (Ready undefined)
+ let sample = modifyMVar var $ \list -> memoise ref list >> return ([], list)
+ addSignal (const sample) (const (() <$ sample)) ref pool
,\val -> do vals <- takeMVar var
putMVar var (val:vals)
)
View
@@ -414,10 +414,9 @@ externalMulti :: IO (SignalGen (Signal [a]), a -> IO ()) -- ^ a generator for th
externalMulti = do
var <- newMVar []
return (SG $ \pool -> do
- let sig = S $ readMVar var
- update <- mkWeak sig (return (),takeMVar var >> putMVar var []) Nothing
- modifyIORef pool (update:)
- return sig
+ ref <- newIORef (Ready undefined)
+ let sample = modifyMVar var $ \list -> memoise ref list >> return ([], list)
+ addSignal (const sample) (const (() <$ sample)) ref pool
,\val -> do vals <- takeMVar var
putMVar var (val:vals)
)

0 comments on commit 6c1695b

Please sign in to comment.