accepted 6Dpwned28fg ettime-non-linux

This commit is contained in:
Dmitry Zuikov 2023-03-27 19:51:20 +03:00
parent f62a9f6f2b
commit e2d17322ed
7 changed files with 25 additions and 16 deletions

View File

@ -1,3 +1,10 @@
## 2023-03-27
PR: gettime-non-linux
branch: pr-gettime-non-linux
commit: a2cd4d575f965dc9c71b69a1355d6603129f2373
Исправляет получение текущего времени для MacOS.
Также добавлены "x86_64-darwin" и "aarch64-darwin" во flake.nix.
## 2023-03-27 ## 2023-03-27

View File

@ -197,11 +197,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1672641093, "lastModified": 1679933705,
"narHash": "sha256-v0Uj3gkDWPdnXZUKpJGD7RxIOncTexhN0csIop36yug=", "narHash": "sha256-UOd70L+FKQLmGjA3IqjFaBpaS/dZMSABtRgVDY3lBCg=",
"owner": "voidlizard", "owner": "voidlizard",
"repo": "hspup", "repo": "hspup",
"rev": "031d27dea1505fd68cd603da7e72eb5eefd348fd", "rev": "6b969a9de1f9800ebfc61c51252b8647123c51bb",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@ -26,7 +26,7 @@ outputs = { self, nixpkgs, haskell-flake-utils, ... }@inputs:
haskell-flake-utils.lib.simpleCabalProject2flake { haskell-flake-utils.lib.simpleCabalProject2flake {
inherit self nixpkgs; inherit self nixpkgs;
systems = [ "x86_64-linux" "aarch64-linux" ]; systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
name = "hbs2"; name = "hbs2";
haskellFlakes = with inputs; [ haskellFlakes = with inputs; [

View File

@ -1,4 +1,5 @@
{-# Language FunctionalDependencies #-} {-# Language FunctionalDependencies #-}
{-# LANGUAGE CPP #-}
module HBS2.Clock module HBS2.Clock
( module HBS2.Clock ( module HBS2.Clock
, module System.Clock , module System.Clock
@ -71,5 +72,12 @@ class Expires a where
-- FIXME: dangerous! -- FIXME: dangerous!
expiresIn _ = Nothing expiresIn _ = Nothing
-- | Use coarse clock timer. This timer has 1ms resolution but is much
-- faster comparing to the ordinary one. Is used on Linux, on MacOS
-- provides ordinary one.
getTimeCoarse :: IO TimeSpec
#ifdef linux_HOST_OS
getTimeCoarse = getTime MonotonicCoarse
#else
getTimeCoarse = getTime Monotonic
#endif

View File

@ -312,8 +312,7 @@ instance HasPeerLocator e m => HasPeerLocator e (BlockDownloadM e m) where
updatePeerInfo :: MonadIO m => Bool -> PeerInfo e -> m () updatePeerInfo :: MonadIO m => Bool -> PeerInfo e -> m ()
updatePeerInfo onError pinfo = do updatePeerInfo onError pinfo = do
-- FIXME: macos-support-3 t1 <- liftIO getTimeCoarse
t1 <- liftIO $ getTime MonotonicCoarse
void $ liftIO $ atomically $ do void $ liftIO $ atomically $ do

View File

@ -204,8 +204,7 @@ fetchBlockState :: MonadIO m => Hash HbSync -> BlockDownloadM e m BlockState
fetchBlockState h = do fetchBlockState h = do
sh <- asks (view blockState) sh <- asks (view blockState)
liftIO do liftIO do
-- FIXME: macos-support-2 now <- getTimeCoarse
now <- getTime MonotonicCoarse
tvlast <- newTVarIO now tvlast <- newTVarIO now
tvreq <- newTVarIO 0 tvreq <- newTVarIO 0
tvsz <- newTVarIO False tvsz <- newTVarIO False
@ -232,8 +231,7 @@ delBlockState h = do
incBlockSizeReqCount :: MonadIO m => Hash HbSync -> BlockDownloadM e m () incBlockSizeReqCount :: MonadIO m => Hash HbSync -> BlockDownloadM e m ()
incBlockSizeReqCount h = do incBlockSizeReqCount h = do
blk <- fetchBlockState h blk <- fetchBlockState h
-- FIXME: macos-support-4 now <- liftIO getTimeCoarse
now <- liftIO $ getTime MonotonicCoarse
seen <- liftIO $ readTVarIO (view bsLastSeen blk) seen <- liftIO $ readTVarIO (view bsLastSeen blk)
let elapsed = realToFrac (toNanoSecs (now - seen)) / 1e9 let elapsed = realToFrac (toNanoSecs (now - seen)) / 1e9
noSize <- liftIO $ readTVarIO (view bsHasSize blk) <&> not noSize <- liftIO $ readTVarIO (view bsHasSize blk) <&> not

View File

@ -105,10 +105,7 @@ touchForRead ss k = liftIO $ do
bsmm <- unsafeMMapFile (simpleBlockFileName ss k) bsmm <- unsafeMMapFile (simpleBlockFileName ss k)
-- FIXME: macos-support-1 tick <- getTimeCoarse
-- вынести функцию в библиотеку
-- обернуть в CPP
tick <- getTime MonotonicCoarse
atomically $ do atomically $ do
modifyTVar' mmaped (HashMap.insert k bsmm) modifyTVar' mmaped (HashMap.insert k bsmm)