use Boottime clock on linux
Better to advance while suspended, that way a stale content retention lock will expire while suspended. The fallback the Monotonic to support older kernels assumes that there are not systems where Boottime sometimes succeeds and sometimes fails. If that ever happened, the clock would probably not monotonically advance as it read from different clocks on different calls! I don't see any indication in clock_gettime(2) errono list that it can fail intermittently so probably this is ok.
This commit is contained in:
parent
5b6150e5d5
commit
e9bd03fc4b
1 changed files with 14 additions and 2 deletions
|
@ -14,11 +14,23 @@ import qualified System.Clock as Clock
|
||||||
#else
|
#else
|
||||||
import qualified System.Posix.Clock as Clock
|
import qualified System.Posix.Clock as Clock
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef linux_HOST_OS
|
||||||
|
import Utility.Exception
|
||||||
|
#endif
|
||||||
|
|
||||||
newtype MonotonicTimestamp = MonotonicTimestamp Integer
|
newtype MonotonicTimestamp = MonotonicTimestamp Integer
|
||||||
deriving (Show, Eq, Ord)
|
deriving (Show, Eq, Ord)
|
||||||
|
|
||||||
|
-- On linux, this uses a clock that advances while the system is suspended,
|
||||||
|
-- except for on very old kernels (eg 2.6.32).
|
||||||
|
-- On other systems, that is not available, and the monotonic clock will
|
||||||
|
-- not advance while suspended.
|
||||||
currentMonotonicTimestamp :: IO MonotonicTimestamp
|
currentMonotonicTimestamp :: IO MonotonicTimestamp
|
||||||
currentMonotonicTimestamp =
|
currentMonotonicTimestamp =
|
||||||
(MonotonicTimestamp . fromIntegral . Clock.sec)
|
(MonotonicTimestamp . fromIntegral . Clock.sec) <$>
|
||||||
<$> Clock.getTime Clock.Monotonic
|
#ifdef linux_HOST_OS
|
||||||
|
(tryNonAsync (Clock.getTime Clock.Boottime)
|
||||||
|
>>= either (const $ Clock.getTime Clock.Monotonic) return)
|
||||||
|
#else
|
||||||
|
Clock.getTime Clock.Monotonic
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue