diff options
| author | Dirk Engling <erdgeist@erdgeist.org> | 2026-10-29 00:53:50 +0100 |
|---|---|---|
| committer | Dirk Engling <erdgeist@erdgeist.org> | 2026-10-29 00:53:50 +0100 |
| commit | 0f95c7d1056cab5bd8c6334cf601349ac4631457 (patch) | |
| tree | c7c27709ef3695659ab4b743d7ae359d4ece272b /ot_livesync.c | |
| parent | 2812a6795149f68226e940212c511b7c625c81d5 (diff) | |
Revert last wake-up experiment. Having each udp worker wake up once a second to check if the tracker stops is wasteful
Diffstat (limited to 'ot_livesync.c')
| -rw-r--r-- | ot_livesync.c | 12 |
1 files changed, 7 insertions, 5 deletions
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}; | |||
| 32 | 32 | ||
| 33 | #define LIVESYNC_MAXDELAY 15 /* seconds */ | 33 | #define LIVESYNC_MAXDELAY 15 /* seconds */ |
| 34 | 34 | ||
| 35 | /* How long the worker may sit in a read before it looks at the running flag */ | ||
| 36 | #define LIVESYNC_WORKER_PATIENCE 1 /* seconds */ | ||
| 37 | |||
| 38 | enum { OT_SYNC_PEER4, OT_SYNC_PEER6 }; | 35 | enum { OT_SYNC_PEER4, OT_SYNC_PEER6 }; |
| 39 | 36 | ||
| 40 | /* Forward declaration */ | 37 | /* Forward declaration */ |
| @@ -58,6 +55,7 @@ static sync_buffer g_v4_buf; | |||
| 58 | 55 | ||
| 59 | static pthread_t thread_id; | 56 | static pthread_t thread_id; |
| 60 | static int thread_started; | 57 | static int thread_started; |
| 58 | static _Atomic int thread_left; | ||
| 61 | void livesync_init(void) { | 59 | void livesync_init(void) { |
| 62 | uint32_t packet_type6 = htonl(OT_SYNC_PEER6); | 60 | uint32_t packet_type6 = htonl(OT_SYNC_PEER6); |
| 63 | uint32_t packet_type4 = htonl(OT_SYNC_PEER4); | 61 | uint32_t packet_type4 = htonl(OT_SYNC_PEER4); |
| @@ -78,13 +76,16 @@ void livesync_init(void) { | |||
| 78 | g_v6_buf.next_packet_time = time_future_seconds(LIVESYNC_MAXDELAY); | 76 | g_v6_buf.next_packet_time = time_future_seconds(LIVESYNC_MAXDELAY); |
| 79 | g_v4_buf.next_packet_time = time_future_seconds(LIVESYNC_MAXDELAY); | 77 | g_v4_buf.next_packet_time = time_future_seconds(LIVESYNC_MAXDELAY); |
| 80 | 78 | ||
| 81 | socket_set_timeout(g_socket_in, LIVESYNC_WORKER_PATIENCE); | ||
| 82 | thread_started = !pthread_create(&thread_id, NULL, livesync_worker, NULL); | 79 | thread_started = !pthread_create(&thread_id, NULL, livesync_worker, NULL); |
| 83 | } | 80 | } |
| 84 | 81 | ||
| 85 | void livesync_deinit(void) { | 82 | void livesync_deinit(void) { |
| 86 | if (thread_started) { | 83 | if (thread_started) { |
| 87 | shutdown(g_socket_in, SHUT_RD); | 84 | /* Repeats so it interrupts a read already under way */ |
| 85 | while (!atomic_load(&thread_left)) { | ||
| 86 | pthread_kill(thread_id, OT_SIGNAL_WAKE); | ||
| 87 | usleep(1000); | ||
| 88 | } | ||
| 88 | pthread_join(thread_id, NULL); | 89 | pthread_join(thread_id, NULL); |
| 89 | thread_started = 0; | 90 | thread_started = 0; |
| 90 | } | 91 | } |
| @@ -235,6 +236,7 @@ static void *livesync_worker(void *args) { | |||
| 235 | } | 236 | } |
| 236 | 237 | ||
| 237 | free(ws.inbuf); | 238 | free(ws.inbuf); |
| 239 | atomic_store(&thread_left, 1); | ||
| 238 | return NULL; | 240 | return NULL; |
| 239 | } | 241 | } |
| 240 | 242 | ||
