From 59cded18b216ad75ef5ce3694dcfa4b5e0fb1871 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 21 Sep 2026 06:03:12 +0000 Subject: [PATCH] Lock: stop logging on every mutex acquisition on Portduino Before: `Lock::lock()` emitted `LOG_WARN("Lock")` on every successful acquisition, and `LOG_INFO("Attempt to lock an already locked Lock!")` whenever the mutex was already held. There are ~300 lock sites in the tree, and they include the hottest paths on the device: spiLock around every SPI transaction, cryptLock around every encrypt and decrypt, and deferredLock on every received packet. So each of those paid a formatted write to the console before doing its work. That matters beyond noise on this branch specifically, because the open question here is radio-thread latency - a false preamble is abandoned after ~8 ms at ShortTurbo, and one CH341 SPI transaction was already measured at 4-8 ms. Logging inside the lock that serialises those transactions puts I/O on exactly the path being measured, so it has to go before the next round's numbers mean anything. The already-locked line also could not do what it claimed. `locked` records that the mutex is held by somebody, so an ordinary contention between two threads - the normal case for spiLock - triggers it just as readily as a thread re-entering its own lock. It logged before blocking, too, so on a genuine recursive lock it printed and then hung. After: the Portduino implementation locks and unlocks, and says nothing. The `locked` field goes with the lines that read it; nothing else used it. Recursive-lock detection would be worth having, but it needs the owning thread recorded and compared against the caller, not a bare held flag, and that is a deliberate change rather than something to slip into a build fix. Reverting this commit restores the old lines without touching the build fix underneath it. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01REkPVFh6kvG4AZJ5A8AtM9 --- src/concurrency/Lock.cpp | 8 -------- src/concurrency/Lock.h | 1 - 2 files changed, 9 deletions(-) diff --git a/src/concurrency/Lock.cpp b/src/concurrency/Lock.cpp index f52e0caa04..c535d5dbf6 100644 --- a/src/concurrency/Lock.cpp +++ b/src/concurrency/Lock.cpp @@ -45,14 +45,7 @@ Lock::Lock() void Lock::lock() { - if (locked) { - LOG_INFO("Attempt to lock an already locked Lock!"); - } pthread_mutex_lock(&mutex); - locked = true; - - if (console) - LOG_WARN("Lock"); } bool Lock::lock(uint32_t) @@ -66,7 +59,6 @@ bool Lock::lock(uint32_t) void Lock::unlock() { pthread_mutex_unlock(&mutex); - locked = false; } Lock::~Lock() diff --git a/src/concurrency/Lock.h b/src/concurrency/Lock.h index bf64d3fa5e..6a5c9f5bd5 100644 --- a/src/concurrency/Lock.h +++ b/src/concurrency/Lock.h @@ -41,7 +41,6 @@ class Lock SemaphoreHandle_t handle; #elif defined(ARCH_PORTDUINO) pthread_mutex_t mutex; - bool locked = false; #endif };