From 1af44db109f4fdf12a8225125936d73e782ae93e Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Thu, 19 Dec 2019 11:39:34 +0900 Subject: [PATCH] Minor refactorings UDPC_update now locks the mutex to keep it thread-safe. --- src/UDPConnection.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/UDPConnection.cpp b/src/UDPConnection.cpp index 6e29c15..79788c9 100644 --- a/src/UDPConnection.cpp +++ b/src/UDPConnection.cpp @@ -1784,9 +1784,10 @@ void UDPC::threadedUpdate(Context *ctx) { decltype(now) nextNow; while(ctx->threadRunning.load()) { now = std::chrono::steady_clock::now(); - ctx->mutex.lock(); - ctx->update_impl(); - ctx->mutex.unlock(); + { + std::lock_guard lock(ctx->mutex); + ctx->update_impl(); + } nextNow = std::chrono::steady_clock::now(); std::this_thread::sleep_for(ctx->threadedSleepTime - (nextNow - now)); } @@ -2075,6 +2076,7 @@ void UDPC_update(UDPC_HContext ctx) { return; } + std::lock_guard lock(c->mutex); c->update_impl(); }