From 8fb1c09df1540aa3fca1148bed6a08ffc3090669 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Tue, 27 Oct 2026 19:15:22 +0100 Subject: All OSes now do have a cheap monotonic clock, so no caching thread is needed. Also add some relative time helpers --- ot_livesync.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'ot_livesync.c') diff --git a/ot_livesync.c b/ot_livesync.c index 5a63f3c..fb0bef2 100644 --- a/ot_livesync.c +++ b/ot_livesync.c @@ -70,8 +70,8 @@ void livesync_init(void) { g_v6_buf.fill = sizeof(g_tracker_id) + sizeof(uint32_t); g_v4_buf.fill = sizeof(g_tracker_id) + sizeof(uint32_t); - g_v6_buf.next_packet_time = g_now_seconds + LIVESYNC_MAXDELAY; - g_v4_buf.next_packet_time = g_now_seconds + LIVESYNC_MAXDELAY; + g_v6_buf.next_packet_time = time_future_seconds(LIVESYNC_MAXDELAY); + g_v4_buf.next_packet_time = time_future_seconds(LIVESYNC_MAXDELAY); pthread_create(&thread_id, NULL, livesync_worker, NULL); } @@ -106,7 +106,7 @@ static void livesync_issue_peersync(sync_buffer *buf) { memcpy(mycopy, buf->data, fill); buf->fill = sizeof(g_tracker_id) + sizeof(uint32_t); - buf->next_packet_time = g_now_seconds + LIVESYNC_MAXDELAY; + buf->next_packet_time = time_future_seconds(LIVESYNC_MAXDELAY); /* From now this thread has a local copy of the buffer and has modified the protected element */ @@ -152,13 +152,13 @@ static void livesync_handle_peersync(struct ot_workstruct *ws, size_t peer_size) void livesync_ticker(void) { /* livesync_issue_peersync sets g_next_packet_time */ pthread_mutex_lock(&g_outbuf_mutex); - if (g_now_seconds > g_v6_buf.next_packet_time && g_v6_buf.fill > sizeof(g_tracker_id) + sizeof(uint32_t)) + if (time_now_seconds() > g_v6_buf.next_packet_time && g_v6_buf.fill > sizeof(g_tracker_id) + sizeof(uint32_t)) livesync_issue_peersync(&g_v6_buf); else pthread_mutex_unlock(&g_outbuf_mutex); pthread_mutex_lock(&g_outbuf_mutex); - if (g_now_seconds > g_v4_buf.next_packet_time && g_v4_buf.fill > sizeof(g_tracker_id) + sizeof(uint32_t)) + if (time_now_seconds() > g_v4_buf.next_packet_time && g_v4_buf.fill > sizeof(g_tracker_id) + sizeof(uint32_t)) livesync_issue_peersync(&g_v4_buf); else pthread_mutex_unlock(&g_outbuf_mutex); -- cgit v1.3