]> git.seodisparate.com - UDPConnection/commitdiff
Minor refactorings
authorStephen Seo <seo.disparate@gmail.com>
Thu, 19 Dec 2019 02:39:34 +0000 (11:39 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Thu, 19 Dec 2019 02:39:34 +0000 (11:39 +0900)
UDPC_update now locks the mutex to keep it thread-safe.

src/UDPConnection.cpp

index 6e29c15b7355f699780eeae3559fc190290af1c2..79788c99f6038169a55104fb1888ce15d7f8470d 100644 (file)
@@ -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<std::mutex> 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<std::mutex> lock(c->mutex);
     c->update_impl();
 }