diff options
Diffstat (limited to 'src/timestamp/timestamp.cpp')
| -rw-r--r-- | src/timestamp/timestamp.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/timestamp/timestamp.cpp b/src/timestamp/timestamp.cpp index 4cac82a..72bd37c 100644 --- a/src/timestamp/timestamp.cpp +++ b/src/timestamp/timestamp.cpp @@ -6,6 +6,16 @@ // 1 ms = 1000 us // 1 us = 1000 ns +/* + * The maximum number of seconds that can be stored in the time_t value is 2147483647 –- a little over 68 years. + * + * struct timespec + * { + * time_t tv_sec; // seconds + * long tv_nsec; // nanoseconds + * }; + */ + struct timestamp { struct timespec ts; @@ -18,6 +28,17 @@ struct timestamp void timestamp_update() { + /* + * CLOCK_MONOTONIC + * + * On Linux, that point corresponds to the number of sec‐ + * onds that the system has been running since it was booted. + * + * The CLOCK_MONOTONIC clock is not affected by discontinuous + * jumps in the system time (e.g., if the system administrator + * manually changes the clock), but is affected by the incremen‐ + * tal adjustments performed by adjtime(3) and NTP. + */ clock_gettime(CLOCK_MONOTONIC, &g_timestamp.ts); uint64_t current_timestamp_ms = g_timestamp.ts.tv_sec * 1000 + g_timestamp.ts.tv_nsec / 1000000; @@ -32,7 +53,6 @@ uint64_t timestamp_get_sec() return ATOMIC_READ(&g_timestamp.ts_in_sec); } -// TODO uint64_t 溢出 uint64_t timestamp_get_msec() { return ATOMIC_READ(&g_timestamp.ts_in_msec); |
