Proposal: Retrieving the System Event Manager
When you want to use the system event manager (the one started by the RTS) you currently have to do something like this:
{-# LANGUAGE ForeignFunctionInterface #-}
import System.Event (EventManager)
import GHC.Conc.Sync (sharedCAF)
import Foreign.Ptr (Ptr)
import Data.IORef (IORef, newIORef, readIORef)
import System.IO.Unsafe (unsafePerformIO)
main = do
Just mgr <- readIORef eventManager
...
eventManager :: IORef (Maybe EventManager)
eventManager = unsafePerformIO $ do
em <- newIORef Nothing
sharedCAF em getOrSetSystemEventThreadEventManagerStore
{-# NOINLINE eventManager #-}
foreign import ccall unsafe "getOrSetSystemEventThreadEventManagerStore"
getOrSetSystemEventThreadEventManagerStore :: Ptr a -> IO (Ptr a)
I propose to abstract this ugliness in a function:
getSystemEventManager :: IO (Maybe EventManager)
getSystemEventManager = readIORef eventManager
and export it from GHC.Event
.
I don't think this needs to go through the library submission process since the module is GHC specific.
See the thread on the libraries list.
Trac metadata
Trac field | Value |
---|---|
Version | 7.0.3 |
Type | Task |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | libraries/base |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |