Skip to content

Commit

Permalink
Merge pull request #1124 from piru/master
Browse files Browse the repository at this point in the history
Use CLOCK_MONOTONIC_RAW when available
  • Loading branch information
eminence authored Dec 8, 2021
2 parents 6b2ffa9 + 87fd565 commit 3117647
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/util/timestamp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@
#include <stdio.h>
#endif

// On Apple systems CLOCK_MONOTONIC is unfortunately able to go
// backwards in time. This breaks mosh when system is returning from
// suspend as described in ticket #1014. To avoid this issue prefer
// CLOCK_MONOTONIC_RAW on Apple systems when available.
#if defined(__APPLE__) && defined(CLOCK_MONOTONIC_RAW)
#define CLOCKTYPE CLOCK_MONOTONIC_RAW
#else
#define CLOCKTYPE CLOCK_MONOTONIC
#endif

static uint64_t millis_cache = -1;

uint64_t frozen_timestamp( void )
Expand All @@ -73,7 +83,7 @@ void freeze_timestamp( void )
// Check for presence, for OS X SDK >= 10.12 and runtime < 10.12
&clock_gettime != NULL &&
#endif
clock_gettime( CLOCK_MONOTONIC, &tp ) == 0 ) {
clock_gettime( CLOCKTYPE, &tp ) == 0 ) {
uint64_t millis = tp.tv_nsec / 1000000;
millis += uint64_t( tp.tv_sec ) * 1000;

Expand Down

0 comments on commit 3117647

Please sign in to comment.