
#13995: provide hook for 'setNumCapabilities' -------------------------------------+------------------------------------- Reporter: winter | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- This request if straight forward: i want to run some code when user call `setNumCapabilities`. I'm making a [https://github.com/winterland1989/stdio/blob/newFD/System/LowResTimer.hs stripped timing wheel implementation], and the problem is obvious: we keep an array of timer managers just like I/O managers, but we have to ask user to call something like `lowResTimerManagerCapabilitiesChanged` so that we can re-allocate new array, which is unreasonable. The same problem exists in some stripped resource pool implementation, so i proposed {{{ -- this is not exported capabilityChangedHook :: IORef (IO ()) capabilityChangedHook = unsafePerformIO $ newIORef (return ()) -- this is exported to user addCapabilityChangedHook :: IO () -> IO () addCapabilityChangedHook f = do atomicModifyIORef' capabilityChangedHook $ \ g -> (g >> f, ()) setNumCapabilities :: ... setNumCapabilities = ... ... -- somewhere inside setNumCapabilities hook <- readIORef capabilityChangedHook hook ... }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13995 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler