@@ -21,7 +21,7 @@ import Data.Time
21import Data.Bits
21import Data.Bits
22import Data.Word
22import Data.Word
24−import Data.IORef
24+import Control.Concurrent.MVar
25import System.IO
25import System.IO
26import System.IO.Unsafe
26import System.IO.Unsafe
@@ -65,29 +65,27 @@ type instance ByteSink MACSource g = Takes3Bytes (Takes3Bytes g)
65-- the clock value on initialization.
65-- the clock value on initialization.
66stepTime :: IO (Maybe (Word16, Word64))
66stepTime :: IO (Maybe (Word16, Word64))
67stepTime = do
67stepTime = do
68− State c0 h0 <- readIORef state
69 h1 <- fmap hundredsOfNanosSinceGregorianReform getCurrentTime
68 h1 <- fmap hundredsOfNanosSinceGregorianReform getCurrentTime
69+ modifyMVar state $ \s@(State c0 h0) ->
70− if h1 > h0
70+ if h1 > h0
72− writeIORef state $ State c0 h1
73− return $ Just (c0, h1)
72+ return (State c0 h1, Just (c0, h1))
76 c1 = succ c0
75 c1 = succ c0
77− if c1 <= 0x3fff -- when clock is initially randomized,
76+ in if c1 <= 0x3fff -- when clock is initially randomized,
78 -- then this test will need to change
77 -- then this test will need to change
80− writeIORef state $ State c1 h1
81− return $ Just (c1, h1)
79+ return (State c1 h1, Just (c1, h1))
83− return Nothing
81+ return (s, Nothing)
86{-# NOINLINE state #-}
84{-# NOINLINE state #-}
87−state :: IORef State
85+state :: MVar State
88state = unsafePerformIO $ do
86state = unsafePerformIO $ do
89 h0 <- fmap hundredsOfNanosSinceGregorianReform getCurrentTime
87 h0 <- fmap hundredsOfNanosSinceGregorianReform getCurrentTime
90− newIORef $ State 0 h0 -- the 0 should be a random number
88+ newMVar $ State 0 h0 -- the 0 should be a random number
93data State = State
91data State = State