Changeset 12785 for trunk

Show
Ignore:
Timestamp:
05.11.2009 17:26:04 (4 months ago)
Author:
mgross
Message:

Replaced MVar with IORef.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/CMDL/Interface.hs

    r12622 r12785  
    3636import Data.List 
    3737 
    38 import Control.Concurrent.MVar 
     38import Data.IORef 
    3939import Control.Monad 
    4040import Control.Monad.Trans (MonadIO(..)) 
    4141 
    4242#ifdef HASKELINE 
    43 shellSettings :: MVar CmdlState -> Settings IO 
     43shellSettings :: IORef CmdlState -> Settings IO 
    4444shellSettings st = 
    4545  Settings { 
     
    5151-- We need an MVar here 
    5252-- because our CmdlState is not a Monad (and we use IO as Monad). 
    53 cmdlComplete :: MVar CmdlState -> CompletionFunc IO 
     53cmdlComplete :: IORef CmdlState -> CompletionFunc IO 
    5454cmdlComplete st (left, _) = do 
    55   state <- liftIO $ readMVar st 
     55  state <- liftIO $ readIORef st 
    5656  comps <- liftIO $ cmdlCompletionFn getCommands state $ reverse left 
    5757  let (_, nodes) = case i_state $ intState state of 
     
    6666#endif 
    6767 
    68 shellLoop :: MVar CmdlState 
     68shellLoop :: IORef CmdlState 
    6969          -> Bool 
    7070#ifdef HASKELINE 
     
    7575shellLoop st isTerminal = 
    7676  do 
    77     state <- liftIO $ readMVar st 
     77    state <- liftIO $ readIORef st 
    7878    let prompt = if isTerminal then generatePrompter state else "" 
    7979#ifdef HASKELINE 
     
    107107                                         Just cm -> checkCom 
    108108                                              cm { cmdDescription = c } newState 
    109                         liftIO $ swapMVar st newState' 
     109                        liftIO $ writeIORef st newState' 
    110110                        shellLoop st isTerminal 
    111111 
     
    114114cmdlRunShell state = do 
    115115  isTerminal <- hIsTerminalDevice stdin 
    116   st <- newMVar state 
     116  st <- newIORef state 
    117117#ifdef HASKELINE 
    118118  runInputT (shellSettings st) $ shellLoop st isTerminal