diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-07-08 08:43:42 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-07-09 21:04:50 +0000 |
commit | abc17b0f8997ab07ae66130edd5dc8c43e72c886 (patch) | |
tree | 88056839c808a9f7f8c58f55ebe273aa7b5facdb /toxcore/mono_time.h | |
parent | 4e21c065517d6e125cb1d1b9a13e886b3046b0d8 (diff) |
Factor out time keeping code into its own module: mono_time.c.
It turns out, `unix_time` is also monotonic, and is used as such, so I've
renamed the new functions to `mono_time_*`.
2018-07-08:
```
00:01 <@irungentoo> the idea used to be that the unix_time() function
could go backward in time but I think I might have started using it like
if it could not after I changed it so that it would never go back in time
```
Diffstat (limited to 'toxcore/mono_time.h')
-rw-r--r-- | toxcore/mono_time.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/toxcore/mono_time.h b/toxcore/mono_time.h new file mode 100644 index 00000000..63e0f49d --- /dev/null +++ b/toxcore/mono_time.h | |||
@@ -0,0 +1,35 @@ | |||
1 | #ifndef C_TOXCORE_TOXCORE_MONO_TIME_H | ||
2 | #define C_TOXCORE_TOXCORE_MONO_TIME_H | ||
3 | |||
4 | #include <stdbool.h> | ||
5 | #include <stdint.h> | ||
6 | |||
7 | #ifdef __cplusplus | ||
8 | extern "C" { | ||
9 | #endif | ||
10 | |||
11 | typedef struct Mono_Time Mono_Time; | ||
12 | |||
13 | Mono_Time *mono_time_new(void); | ||
14 | void mono_time_free(Mono_Time *monotime); | ||
15 | |||
16 | void mono_time_update(Mono_Time *monotime); | ||
17 | uint64_t mono_time_get(const Mono_Time *monotime); | ||
18 | bool mono_time_is_timeout(const Mono_Time *monotime, uint64_t timestamp, uint64_t timeout); | ||
19 | |||
20 | // TODO(#405): Use per-tox monotime, delete these functions. | ||
21 | void unix_time_update(void); | ||
22 | uint64_t unix_time(void); | ||
23 | int is_timeout(uint64_t timestamp, uint64_t timeout); | ||
24 | |||
25 | /* return current UNIX time in microseconds (us). */ | ||
26 | uint64_t current_time_actual(void); | ||
27 | |||
28 | /* return current monotonic time in milliseconds (ms). */ | ||
29 | uint64_t current_time_monotonic(void); | ||
30 | |||
31 | #ifdef __cplusplus | ||
32 | } | ||
33 | #endif | ||
34 | |||
35 | #endif // C_TOXCORE_TOXCORE_MONO_TIME_H | ||