uuid 1.2.0 → 1.2.1
raw patch · 4 files changed
+33/−22 lines, 4 filesdep +mersenne-random-pure64
Dependencies added: mersenne-random-pure64
Files
- CHANGES +5/−0
- Data/UUID/V1.hs +13/−15
- tests/BenchUUID.hs +12/−5
- uuid.cabal +3/−2
CHANGES view
@@ -1,3 +1,8 @@+1.2.1++- Fix concurrency bug in Data.UUID.V1 (thanks to Neil Mitchell for reporting+and a test case)+ 1.2.0 (Contributors: Antoine Latter & Mark Lentczner)
Data/UUID/V1.hs view
@@ -21,7 +21,7 @@ import Data.Bits import Data.Word -import Data.IORef+import Control.Concurrent.MVar import System.IO import System.IO.Unsafe @@ -65,29 +65,27 @@ -- the clock value on initialization. stepTime :: IO (Maybe (Word16, Word64)) stepTime = do- State c0 h0 <- readIORef state h1 <- fmap hundredsOfNanosSinceGregorianReform getCurrentTime- if h1 > h0- then do- writeIORef state $ State c0 h1- return $ Just (c0, h1)- else do+ modifyMVar state $ \s@(State c0 h0) ->+ if h1 > h0+ then+ return (State c0 h1, Just (c0, h1))+ else let c1 = succ c0- if c1 <= 0x3fff -- when clock is initially randomized,+ in if c1 <= 0x3fff -- when clock is initially randomized, -- then this test will need to change- then do- writeIORef state $ State c1 h1- return $ Just (c1, h1)- else do- return Nothing+ then+ return (State c1 h1, Just (c1, h1))+ else+ return (s, Nothing) {-# NOINLINE state #-}-state :: IORef State+state :: MVar State state = unsafePerformIO $ do h0 <- fmap hundredsOfNanosSinceGregorianReform getCurrentTime- newIORef $ State 0 h0 -- the 0 should be a random number+ newMVar $ State 0 h0 -- the 0 should be a random number data State = State
tests/BenchUUID.hs view
@@ -1,6 +1,7 @@ import Control.Parallel.Strategies import Criterion.Main import Data.Char (ord)+import Data.IORef import Data.Maybe (fromJust) import Data.Word import qualified Data.Set as Set@@ -11,18 +12,15 @@ import qualified Data.UUID.V3 as U3 import qualified Data.UUID.V5 as U5 import System.Random-+import System.Random.Mersenne.Pure64 instance NFData BL.ByteString where rnf BL.Empty = () rnf (BL.Chunk _ ts) = rnf ts instance NFData U.UUID where- rnf u = () -- main :: IO () main = do u1 <- randomIO@@ -36,6 +34,15 @@ BL.pack [0x16, 0x9a, 0x5a, 0x43, 0xc0, 0x51, 0x4a, 0x16, 0x98, 0xf4, 0x08, 0x44, 0x7d, 0xdd, 0x5d, 0xc0] u3 = fromJust $ U.fromString "dea6f619-1038-438b-b4af-f1cdec1e6e23"++ -- setup for random generation+ randomState <- newPureMT >>= newIORef+ let randomUUID = do+ state <- readIORef randomState+ let (uuid, state') = random state+ writeIORef randomState state'+ return uuid+ defaultMain [ bgroup "testing" [ bench "null non-nil" $ whnf U.null u1,@@ -52,7 +59,7 @@ ], bgroup "generation" [ bench "V1" $ nfIO U.nextUUID,- bench "V4" $ nfIO (randomIO :: IO U.UUID),+ bench "V4" $ nfIO (randomUUID :: IO U.UUID), bench "V3" $ nf (U3.generateNamed U3.namespaceURL) n1, bench "V5" $ nf (U5.generateNamed U5.namespaceURL) n1 ],
uuid.cabal view
@@ -1,5 +1,5 @@ Name: uuid-Version: 1.2.0+Version: 1.2.1 Copyright: (c) 2008-2009 Antoine Latter Author: Antoine Latter Maintainer: aslatter@gmail.com@@ -56,7 +56,8 @@ Buildable: True Build-Depends: random, binary, bytestring, Crypto, maccatcher, time, base >=3, base < 5, containers,- criterion >= 0.3 && < 0.5, parallel >= 2.1 && < 2.3+ criterion >= 0.3 && < 0.5, parallel >= 2.1 && < 2.3,+ mersenne-random-pure64 >= 0.2 && < 0.3 Else Buildable: False