summaryrefslogtreecommitdiff
path: root/compiler/utils/Util.lhs
diff options
context:
space:
mode:
authorThomas Schilling <nominolo@googlemail.com>2009-08-17 14:23:52 +0000
committerThomas Schilling <nominolo@googlemail.com>2009-08-17 14:23:52 +0000
commit4fa44a3ae9c36222ccb460ba3ed24e46bf7c70ae (patch)
tree3a141c84806004f03f59862ca77364380c2ba18d /compiler/utils/Util.lhs
parent9f68c34843602e815e71ef68f43adc01da993672 (diff)
downloadhaskell-4fa44a3ae9c36222ccb460ba3ed24e46bf7c70ae.tar.gz
Make the dynamic linker thread-safe.
The current implementation is rather pessimistic. The persistent linker state is now an MVar and all exported Linker functions are wrapped in modifyMVar calls. This is serves as a big lock around all linker functions. There might be a chance for more concurrency in a few places. E.g., extending the closure environment and loading packages might be independent in some cases. But for now it's better to be on the safe side.
Diffstat (limited to 'compiler/utils/Util.lhs')
-rw-r--r--compiler/utils/Util.lhs11
1 files changed, 10 insertions, 1 deletions
diff --git a/compiler/utils/Util.lhs b/compiler/utils/Util.lhs
index 3de52b6737..5cf020f7f5 100644
--- a/compiler/utils/Util.lhs
+++ b/compiler/utils/Util.lhs
@@ -65,7 +65,7 @@ module Util (
doesDirNameExist,
modificationTimeIfExists,
- global, consIORef,
+ global, consIORef, globalMVar, globalEmptyMVar,
-- * Filenames and paths
Suffix,
@@ -83,6 +83,7 @@ import Data.IORef ( IORef, newIORef )
import System.IO.Unsafe ( unsafePerformIO )
import Data.IORef ( readIORef, writeIORef )
import Data.List hiding (group)
+import Control.Concurrent.MVar ( MVar, newMVar, newEmptyMVar )
#ifdef DEBUG
import qualified Data.List as List ( elem, notElem )
@@ -699,6 +700,14 @@ consIORef var x = do
writeIORef var (x:xs)
\end{code}
+\begin{code}
+globalMVar :: a -> MVar a
+globalMVar a = unsafePerformIO (newMVar a)
+
+globalEmptyMVar :: MVar a
+globalEmptyMVar = unsafePerformIO newEmptyMVar
+\end{code}
+
Module names:
\begin{code}