Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix windex not being updated in flushTBQueue #79

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Control/Concurrent/STM/TBQueue.hs
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,11 @@ tryReadTBQueue q = fmap Just (readTBQueue q) `orElse` pure Nothing
--
-- @since 2.4.5
flushTBQueue :: forall a. TBQueue a -> STM [a]
flushTBQueue (TBQueue _rindex windex elements cap) = do
flushTBQueue (TBQueue rindex windex elements cap) = do
w <- readTVar windex
go (decMod w cap) []
res <- go (decMod w cap) []
writeTVar windex =<< readTVar rindex
pure res
where
go :: Int -> [a] -> STM [a]
go i acc = do
Expand Down
11 changes: 11 additions & 0 deletions testsuite/src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ module Main where

import Test.Framework (defaultMain, testGroup)
import Test.Framework.Providers.HUnit
import Test.HUnit

import Control.Concurrent.STM

import qualified Issue9
import qualified Stm052
Expand All @@ -21,6 +24,14 @@ main = do
, testCase "stm052" Stm052.main
, testCase "stm064" Stm064.main
, testCase "stm065" Stm065.main
, testCase "issue #76" $ do
queue <- newTBQueueIO 100
len <- atomically $ do
writeTBQueue queue (1 :: Int)
writeTBQueue queue 2
_ <- flushTBQueue queue
lengthTBQueue queue
len @?= 0
]
]