-- | A function for changing directories in a thread-safe way.---- We use an MSem to lock the current directory. This means that-- withDir can be nested without deadlock (presumably the user knows what-- he's doing).moduleReactor.WithDir(withDir,-- :: FilePath -> IO a -> IO a)whereimportSystem.DirectoryimportSystem.IO.UnsafeimportUtil.ComputationimportEvents.SynchronizedimportReactor.MSemdirMSem::MSemdirMSem=unsafePerformIOnewMSem{-# NOINLINE dirMSem #-}withDir::FilePath->IOa->IOawithDirfilePathact=synchronizedirMSem(dooriginalDir<-getCurrentDirectorysetCurrentDirectoryfilePathactOut<-tryactsetCurrentDirectoryoriginalDirpropagateactOut)