git.iko.soy/typeable/thread-local
on master help sign in
Fix fetch bug.
commit90329ad61f97347a099f6b7dd14592b3cec51a41 authorNick <nick@typeable.io> dateMon 10 Jul 2023, 11:59 (3 years ago) parent4d894c9
1 file changed+2−3
src/Control/Concurrent/ThreadLocal/Internal.hs+2−3
src/Control/Concurrent/ThreadLocal/Internal.hs+2−3
@@ -4,7 +4,7 @@ module Control.Concurrent.ThreadLocal.Internal where
44import Control.Concurrent (ThreadId, myThreadId, mkWeakThreadId)
55import Control.Concurrent.MVar
66import Control.Monad ((<=<), guard)
7−import Data.Foldable (toList)
7+import Data.Foldable (find, toList)
88import Data.Maybe (isJust)
99import Data.Vector (Vector)
1010import qualified Data.Vector as Vector
@@ -48,8 +48,7 @@ fetchThreadLocal :: ThreadLocal a -> IO (Maybe a)
4848fetchThreadLocal (ThreadLocal var) = do tid <- myThreadId
4949 v <- readMVar var
5050 f tid <$> wither derefLocal v
51− where f tid vec = do ((tid',v),_) <- Vector.uncons vec
52− guard (tid == tid')
51+ where f tid vec = do (_,v) <- find ((== tid) . fst) vec
5352 pure v
5453
5554gcThreadLocal :: ThreadLocal a -> IO ()