provide hook for 'setNumCapabilities'
This request is straight forward: i want to run some code when user call setNumCapabilities
.
I'm making a 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 propose
-- this is not exported
capabilityChangedHook :: IORef (IO ())
capabilityChangedHook = unsafePerformIO $ newIORef (return ())
-- this is exported to user, and can be called within unsafePerformIO
addCapabilityChangedHook :: IO () -> IO ()
addCapabilityChangedHook f = do
atomicModifyIORef' capabilityChangedHook $ \ g -> (g >> f, ())
setNumCapabilities :: ...
setNumCapabilities = ...
...
-- somewhere inside setNumCapabilities
hook <- readIORef capabilityChangedHook
hook
...