From 20c05eda6a0d410d84fe97a3a79d04fb70609d48 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Tue, 25 Nov 2025 17:26:01 -0600 Subject: [PATCH] Don't lock the ENet mutex when querying for RTT information --- src/ControlStream.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ControlStream.c b/src/ControlStream.c index 4280963..b7e3685 100644 --- a/src/ControlStream.c +++ b/src/ControlStream.c @@ -1670,7 +1670,10 @@ bool isControlDataInTransit(void) { bool LiGetEstimatedRttInfo(uint32_t* estimatedRtt, uint32_t* estimatedRttVariance) { bool ret = false; - PltLockMutex(&enetMutex); + // We do not acquire enetMutex here because we're just reading metrics + // and observing a torn write every once in a while is totally fine. + // The peer pointer points to memory reserved inside the client object, + // so it's guaranteed that it will never go away underneath us. if (peer != NULL && peer->state == ENET_PEER_STATE_CONNECTED) { if (estimatedRtt != NULL) { *estimatedRtt = peer->roundTripTime; @@ -1682,7 +1685,6 @@ bool LiGetEstimatedRttInfo(uint32_t* estimatedRtt, uint32_t* estimatedRttVarianc ret = true; } - PltUnlockMutex(&enetMutex); return ret; }