From 95be5a80e00eebcb23370f92378b11a504ede79e Mon Sep 17 00:00:00 2001
From: "Rob Swindell (on ChromeOS)" <rob@synchro.net>
Date: Wed, 14 Feb 2024 00:27:31 -0800
Subject: [PATCH] Simplify the child thread wait loop in cleanup()

---
 src/sbbs3/websrvr.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/sbbs3/websrvr.c b/src/sbbs3/websrvr.c
index 8792229412..ab3edceff0 100644
--- a/src/sbbs3/websrvr.c
+++ b/src/sbbs3/websrvr.c
@@ -6896,15 +6896,17 @@ void web_terminate(void)
 
 static void cleanup(int code)
 {
-	if(protected_uint32_value(thread_count) > 1) {
-		lprintf(LOG_INFO,"0000 Waiting for %d child threads to terminate", protected_uint32_value(thread_count)-1);
-		while(protected_uint32_value(thread_count) > 1) {
-			mswait(1000);
-			listSemPost(&log_list);
-			lprintf(LOG_INFO,"0000 Waiting for %d child threads to terminate", protected_uint32_value(thread_count)-1);
-		}
-		lprintf(LOG_INFO,"0000 Done waiting");
+	bool waited = false;
+	uint32_t threads;
+
+	while((threads = protected_uint32_value(thread_count)) > 1) {
+		lprintf(LOG_INFO,"0000 Waiting for %d child threads to terminate", threads-1);
+		mswait(1000);
+		waited = true;
+		listSemPost(&log_list);
 	}
+	if(waited)
+		lprintf(LOG_INFO,"0000 Done waiting");
 	terminate_js = false;
 	free_cfg(&scfg);
 
-- 
GitLab