Skip to content
Merged
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
25 changes: 25 additions & 0 deletions Control/Concurrent/STM/TMVar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ module Control.Concurrent.STM.TMVar (
readTMVar,
writeTMVar,
tryReadTMVar,
tryReadTMVarIO,
swapTMVar,
tryTakeTMVar,
tryPutTMVar,
isEmptyTMVar,
isEmptyTMVarIO,
mkWeakTMVar
#endif
) where
Expand Down Expand Up @@ -141,6 +143,19 @@ readTMVar (TMVar t) = do
tryReadTMVar :: TMVar a -> STM (Maybe a)
tryReadTMVar (TMVar t) = readTVar t

-- | A version of 'readTMVar' which does not retry. This is
-- equivalent to
--
-- > readTVarIO = atomically . readTVar
--
-- but works much faster, because it doesn't perform a complete
-- transaction, it just attempts to read the current value of
-- the 'TMVar'.
--
-- @since 2.5.4.0
tryReadTMVarIO :: TMVar a -> IO (Maybe a)
tryReadTMVarIO (TMVar t) = readTVarIO t

-- |Swap the contents of a 'TMVar' for a new value.
swapTMVar :: TMVar a -> a -> STM a
swapTMVar (TMVar t) new = do
Expand All @@ -164,6 +179,16 @@ isEmptyTMVar (TMVar t) = do
Nothing -> return True
Just _ -> return False

-- | @IO@ version of 'isEmptyTVar'.
--
-- @since 2.5.4.0
isEmptyTMVarIO :: TMVar a -> IO Bool
isEmptyTMVarIO (TMVar t) = do
m <- readTVarIO t
case m of
Nothing -> return True
Just _ -> return False

-- | Make a 'Weak' pointer to a 'TMVar', using the second argument as
-- a finalizer to run when the 'TMVar' is garbage-collected.
--
Expand Down
7 changes: 7 additions & 0 deletions Control/Concurrent/STM/TSem.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
module Control.Concurrent.STM.TSem
( TSem
, newTSem
, newTSemIO

, waitTSem

Expand Down Expand Up @@ -59,6 +60,12 @@ newtype TSem = TSem (TVar Integer)
newTSem :: Integer -> STM TSem
newTSem i = fmap TSem (newTVar $! i)

-- | @IO@ equivalent of 'newTSem'.
--
-- @since 2.5.4.0
newTSemIO :: Integer -> IO TSem
newTSemIO i = fmap TSem (newTVarIO $! i)

-- NOTE: we can't expose a good `TSem -> STM Int' operation as blocked
-- 'waitTSem' aren't reliably reflected in a negative counter value.

Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog for [`stm` package](http://hackage.haskell.org/package/stm)

## 2.5.4.0 *Apr 2026*

* Add `IO` variants for operations that don't need to retry ([#94](https://github.com/haskell/stm/pull/94))

## 2.5.3.1 *Apr 2024*

* Drop unused testcase inadvertently introduced in previous reversion
Expand Down
2 changes: 1 addition & 1 deletion stm.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ library
build-depends: semigroups >=0.18.6 && <0.21

build-depends:
base >= 4.4 && < 4.23,
base >= 4.4 && < 4.24,
array >= 0.3 && < 0.6

exposed-modules:
Expand Down
10 changes: 6 additions & 4 deletions testsuite/testsuite.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ description:
See also @README.md@ for more information.

tested-with:
GHC == 9.10.1
GHC == 9.8.2
GHC == 9.6.4
GHC == 9.14.1
GHC == 9.12.4
GHC == 9.10.3
GHC == 9.8.4
GHC == 9.6.7
GHC == 9.4.8
GHC == 9.2.8
GHC == 9.0.2
Expand Down Expand Up @@ -49,7 +51,7 @@ test-suite stm

--
build-depends:
, base >= 4.4 && < 4.23
, base >= 4.4 && < 4.24
, test-framework ^>= 0.8.2.0
, test-framework-hunit ^>= 0.3.0.2
, HUnit ^>= 1.6.0.0
Expand Down
Loading