summaryrefslogtreecommitdiff
path: root/ot_livesync.c
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2026-10-27 19:15:22 +0100
committerDirk Engling <erdgeist@erdgeist.org>2026-10-27 19:15:22 +0100
commit8fb1c09df1540aa3fca1148bed6a08ffc3090669 (patch)
treeeb03f2a9f3eb8e074abc0533aac7f5ab7cd8926c /ot_livesync.c
parentdf5557705764d5e8f904a31d549fc037f5b1cf47 (diff)
All OSes now do have a cheap monotonic clock, so no caching thread is needed. Also add some relative time helpers
Diffstat (limited to 'ot_livesync.c')
-rw-r--r--ot_livesync.c10
1 files changed, 5 insertions, 5 deletions
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) {
70 g_v6_buf.fill = sizeof(g_tracker_id) + sizeof(uint32_t); 70 g_v6_buf.fill = sizeof(g_tracker_id) + sizeof(uint32_t);
71 g_v4_buf.fill = sizeof(g_tracker_id) + sizeof(uint32_t); 71 g_v4_buf.fill = sizeof(g_tracker_id) + sizeof(uint32_t);
72 72
73 g_v6_buf.next_packet_time = g_now_seconds + LIVESYNC_MAXDELAY; 73 g_v6_buf.next_packet_time = time_future_seconds(LIVESYNC_MAXDELAY);
74 g_v4_buf.next_packet_time = g_now_seconds + LIVESYNC_MAXDELAY; 74 g_v4_buf.next_packet_time = time_future_seconds(LIVESYNC_MAXDELAY);
75 75
76 pthread_create(&thread_id, NULL, livesync_worker, NULL); 76 pthread_create(&thread_id, NULL, livesync_worker, NULL);
77} 77}
@@ -106,7 +106,7 @@ static void livesync_issue_peersync(sync_buffer *buf) {
106 106
107 memcpy(mycopy, buf->data, fill); 107 memcpy(mycopy, buf->data, fill);
108 buf->fill = sizeof(g_tracker_id) + sizeof(uint32_t); 108 buf->fill = sizeof(g_tracker_id) + sizeof(uint32_t);
109 buf->next_packet_time = g_now_seconds + LIVESYNC_MAXDELAY; 109 buf->next_packet_time = time_future_seconds(LIVESYNC_MAXDELAY);
110 110
111 /* From now this thread has a local copy of the buffer and 111 /* From now this thread has a local copy of the buffer and
112 has modified the protected element */ 112 has modified the protected element */
@@ -152,13 +152,13 @@ static void livesync_handle_peersync(struct ot_workstruct *ws, size_t peer_size)
152void livesync_ticker(void) { 152void livesync_ticker(void) {
153 /* livesync_issue_peersync sets g_next_packet_time */ 153 /* livesync_issue_peersync sets g_next_packet_time */
154 pthread_mutex_lock(&g_outbuf_mutex); 154 pthread_mutex_lock(&g_outbuf_mutex);
155 if (g_now_seconds > g_v6_buf.next_packet_time && g_v6_buf.fill > sizeof(g_tracker_id) + sizeof(uint32_t)) 155 if (time_now_seconds() > g_v6_buf.next_packet_time && g_v6_buf.fill > sizeof(g_tracker_id) + sizeof(uint32_t))
156 livesync_issue_peersync(&g_v6_buf); 156 livesync_issue_peersync(&g_v6_buf);
157 else 157 else
158 pthread_mutex_unlock(&g_outbuf_mutex); 158 pthread_mutex_unlock(&g_outbuf_mutex);
159 159
160 pthread_mutex_lock(&g_outbuf_mutex); 160 pthread_mutex_lock(&g_outbuf_mutex);
161 if (g_now_seconds > g_v4_buf.next_packet_time && g_v4_buf.fill > sizeof(g_tracker_id) + sizeof(uint32_t)) 161 if (time_now_seconds() > g_v4_buf.next_packet_time && g_v4_buf.fill > sizeof(g_tracker_id) + sizeof(uint32_t))
162 livesync_issue_peersync(&g_v4_buf); 162 livesync_issue_peersync(&g_v4_buf);
163 else 163 else
164 pthread_mutex_unlock(&g_outbuf_mutex); 164 pthread_mutex_unlock(&g_outbuf_mutex);