On Thu, Jul 30, 2015 at 12:11:57PM +0200, 'Klaus Aehlig' via ganeti-devel wrote:
In some cases, we only care about a change being made atomically
to an IORef, but do not want to simultaneously read a value from
it. In this case, we can accept a function only returning the
new value, and not a pair of result and new value.

Signed-off-by: Klaus Aehlig <[email protected]>
---
src/Ganeti/Utils/IORef.hs | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/src/Ganeti/Utils/IORef.hs b/src/Ganeti/Utils/IORef.hs
index 488d2e8..a220e3e 100644
--- a/src/Ganeti/Utils/IORef.hs
+++ b/src/Ganeti/Utils/IORef.hs
@@ -34,6 +34,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

module Ganeti.Utils.IORef
  ( atomicModifyWithLens
+  , atomicModifyWithLens_
  , atomicModifyIORefErr
  , atomicModifyIORefErrLog
  ) where
@@ -53,6 +54,11 @@ atomicModifyWithLens :: (MonadBase IO m)
                     => IORef a -> Lens a a b c -> (b -> (r, c)) -> m r
atomicModifyWithLens ref l f = atomicModifyIORef ref (swap . traverseOf l f)

+-- | Atomically modify an 'IORef', not reading any value.
+atomicModifyWithLens_ :: (MonadBase IO m)
+                      => IORef a -> Lens a a b c -> (b -> c) -> m ()
+atomicModifyWithLens_ ref l f = atomicModifyWithLens ref l $ (,) () . f
+
-- | Atomically modifies an 'IORef' using a function that can possibly fail.
-- If it fails, the value of the 'IORef' is preserved.
atomicModifyIORefErr :: (MonadBase IO m)
--
2.5.0.rc2.392.g76e840b


LGTM

Reply via email to