1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2024-12-04 14:46:30 -05:00

Update: Replaced sleep with a condition wait in ping thread

This commit is contained in:
Philipp Schafft 2023-02-27 02:19:43 +00:00
parent 8a308f2e12
commit a27a97012f

View File

@ -34,6 +34,7 @@ static bool ping_running = false;
static thread_type *ping_thread_id; static thread_type *ping_thread_id;
static mutex_t ping_mutex; static mutex_t ping_mutex;
static ping_queue_t *ping_queue; static ping_queue_t *ping_queue;
static cond_t ping_cond;
static void on_done(ping_queue_t *entry) static void on_done(ping_queue_t *entry)
{ {
@ -68,7 +69,9 @@ static void *ping_thread(void *arg)
break; break;
if (!status) { if (!status) {
thread_sleep(100000); if (!ping_running)
break;
thread_cond_wait(&ping_cond);
continue; continue;
} }
@ -102,6 +105,7 @@ static void ping_add_to_queue(ping_queue_t *entry)
entry->next = ping_queue; entry->next = ping_queue;
ping_queue = entry; ping_queue = entry;
thread_mutex_unlock(&ping_mutex); thread_mutex_unlock(&ping_mutex);
thread_cond_broadcast(&ping_cond);
} }
void ping_simple(const char *url, const char *username, const char *password, const char *data) void ping_simple(const char *url, const char *username, const char *password, const char *data)
@ -136,6 +140,7 @@ void ping_initialize(void)
return; return;
thread_mutex_create(&ping_mutex); thread_mutex_create(&ping_mutex);
thread_cond_create(&ping_cond);
ping_running = true; ping_running = true;
ping_thread_id = thread_create("Ping Thread", ping_thread, NULL, THREAD_ATTACHED); ping_thread_id = thread_create("Ping Thread", ping_thread, NULL, THREAD_ATTACHED);
@ -148,7 +153,9 @@ void ping_shutdown(void)
ping_running = false; ping_running = false;
ICECAST_LOG_DEBUG("Waiting for ping thread"); ICECAST_LOG_DEBUG("Waiting for ping thread");
thread_cond_broadcast(&ping_cond);
thread_join(ping_thread_id); thread_join(ping_thread_id);
thread_mutex_destroy(&ping_mutex); thread_mutex_destroy(&ping_mutex);
thread_cond_destroy(&ping_cond);
ICECAST_LOG_DEBUG("Joined ping thread, good job!"); ICECAST_LOG_DEBUG("Joined ping thread, good job!");
} }