---------------------------------------------------------------------------- -- | -- Module : DAP.Internal -- Copyright : (C) 2023 David M. Johnson -- License : BSD3-style (see the file LICENSE) -- Stability : experimental -- Portability : non-portable -- Description : Internal functions for consumption by other modules like Server.hs ---------------------------------------------------------------------------- module DAP.Internal ( withLock ) where ---------------------------------------------------------------------------- import Control.Concurrent ---------------------------------------------------------------------------- -- | Used for performing actions (e.g. printing debug logs to stdout) -- Also used for writing to each connections Handle. -- Ensures operations occur one thread at a time. -- -- Used internally only -- withLock :: MVar () -> IO () -> IO () withLock :: MVar () -> IO () -> IO () withLock MVar () mvar IO () action = MVar () -> (() -> IO ()) -> IO () forall a. MVar a -> (a -> IO a) -> IO () modifyMVar_ MVar () mvar ((() -> IO ()) -> IO ()) -> (() -> IO ()) -> IO () forall a b. (a -> b) -> a -> b $ \() x -> () x () -> IO () -> IO () forall a b. a -> IO b -> IO a forall (f :: * -> *) a b. Functor f => a -> f b -> f a <$ IO () action ----------------------------------------------------------------------------