diff options
author | Erik de Castro Lopo <erikd@mega-nerd.com> | 2016-09-28 07:37:33 +1000 |
---|---|---|
committer | Erik de Castro Lopo <erikd@mega-nerd.com> | 2016-09-28 07:37:34 +1000 |
commit | f897b7427a4804e3285144f57676574d338be1f5 (patch) | |
tree | 3b4c9f55080fc55fdc8aed8f61c246a801c9f8d9 /libraries | |
parent | c36904d66f30d4386a231ce365a056962a881767 (diff) | |
download | haskell-f897b7427a4804e3285144f57676574d338be1f5.tar.gz |
TH: Use atomicModifyIORef' for fresh names
This prevents the possibility of race conditions when creating fresh
names.
Test Plan: validate
Reviewers: goldfire, austin, bgamari
Reviewed By: bgamari
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D2548
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/template-haskell/Language/Haskell/TH/Syntax.hs | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs index 20c239671e..00ac0b308b 100644 --- a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs +++ b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs @@ -112,9 +112,8 @@ class Monad m => Quasi m where ----------------------------------------------------- instance Quasi IO where - qNewName s = do { n <- readIORef counter - ; writeIORef counter (n+1) - ; return (mkNameU s n) } + qNewName s = do { n <- atomicModifyIORef' counter (\x -> (x + 1, x)) + ; pure (mkNameU s n) } qReport True msg = hPutStrLn stderr ("Template Haskell error: " ++ msg) qReport False msg = hPutStrLn stderr ("Template Haskell error: " ++ msg) |