From 4e21c065517d6e125cb1d1b9a13e886b3046b0d8 Mon Sep 17 00:00:00 2001 From: iphydf Date: Sat, 7 Jul 2018 22:15:08 +0000 Subject: Add a thread-safe version of unix_time and friends. These are not used in a thread-safe way, but it opens the path towards per-tox-instance time keeping and removal of some unsafe global state. --- toxcore/util.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'toxcore/util.h') diff --git a/toxcore/util.h b/toxcore/util.h index c4d55f12..de493ebe 100644 --- a/toxcore/util.h +++ b/toxcore/util.h @@ -39,11 +39,21 @@ extern "C" { #define MIN(a,b) (((a)<(b))?(a):(b)) #define PAIR(TYPE1__, TYPE2__) struct { TYPE1__ first; TYPE2__ second; } +typedef struct Unix_Time Unix_Time; + +Unix_Time *unix_time_new(void); +void unix_time_free(Unix_Time *unixtime); + +// TODO(#405): Use per-tox unixtime, remove unix_time_update, and rename +// unix_time_update_r to unix_time_update. +void unix_time_update_r(Unix_Time *unixtime); +uint64_t unix_time_get(const Unix_Time *unixtime); +int unix_time_is_timeout(const Unix_Time *unixtime, uint64_t timestamp, uint64_t timeout); + void unix_time_update(void); uint64_t unix_time(void); int is_timeout(uint64_t timestamp, uint64_t timeout); - /* id functions */ bool id_equal(const uint8_t *dest, const uint8_t *src); uint32_t id_copy(uint8_t *dest, const uint8_t *src); /* return value is CLIENT_ID_SIZE */ -- cgit v1.2.3