From 0f95c7d1056cab5bd8c6334cf601349ac4631457 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Thu, 29 Oct 2026 00:53:50 +0100 Subject: Revert last wake-up experiment. Having each udp worker wake up once a second to check if the tracker stops is wasteful --- ot_livesync.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'ot_livesync.c') diff --git a/ot_livesync.c b/ot_livesync.c index e6db720..4a0ede1 100644 --- a/ot_livesync.c +++ b/ot_livesync.c @@ -32,9 +32,6 @@ ot_ip6 groupip_1 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 224, 0, 23, 5}; #define LIVESYNC_MAXDELAY 15 /* seconds */ -/* How long the worker may sit in a read before it looks at the running flag */ -#define LIVESYNC_WORKER_PATIENCE 1 /* seconds */ - enum { OT_SYNC_PEER4, OT_SYNC_PEER6 }; /* Forward declaration */ @@ -58,6 +55,7 @@ static sync_buffer g_v4_buf; static pthread_t thread_id; static int thread_started; +static _Atomic int thread_left; void livesync_init(void) { uint32_t packet_type6 = htonl(OT_SYNC_PEER6); uint32_t packet_type4 = htonl(OT_SYNC_PEER4); @@ -78,13 +76,16 @@ void livesync_init(void) { g_v6_buf.next_packet_time = time_future_seconds(LIVESYNC_MAXDELAY); g_v4_buf.next_packet_time = time_future_seconds(LIVESYNC_MAXDELAY); - socket_set_timeout(g_socket_in, LIVESYNC_WORKER_PATIENCE); thread_started = !pthread_create(&thread_id, NULL, livesync_worker, NULL); } void livesync_deinit(void) { if (thread_started) { - shutdown(g_socket_in, SHUT_RD); + /* Repeats so it interrupts a read already under way */ + while (!atomic_load(&thread_left)) { + pthread_kill(thread_id, OT_SIGNAL_WAKE); + usleep(1000); + } pthread_join(thread_id, NULL); thread_started = 0; } @@ -235,6 +236,7 @@ static void *livesync_worker(void *args) { } free(ws.inbuf); + atomic_store(&thread_left, 1); return NULL; } -- cgit v1.3