From 9e6cba29882e72eabbe68307b2040d7919143b6f Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Thu, 31 Oct 2024 18:43:31 -0400 Subject: [PATCH] mapport: remove unnecessary 'g_mapport_enabled' It was only necessary for switching between mapping protocols. It's also used to return in ThreadMapPort but we can just use the interrupt for this purpose. --- src/mapport.cpp | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/src/mapport.cpp b/src/mapport.cpp index 2bb33cdbd9..ba45219f78 100644 --- a/src/mapport.cpp +++ b/src/mapport.cpp @@ -25,7 +25,6 @@ static CThreadInterrupt g_mapport_interrupt; static std::thread g_mapport_thread; -static std::atomic_bool g_mapport_enabled{false}; using namespace std::chrono_literals; static constexpr auto PORT_MAPPING_REANNOUNCE_PERIOD{20min}; @@ -124,20 +123,9 @@ static bool ProcessPCP() static void ThreadMapPort() { - bool ok; do { - ok = false; - - if (g_mapport_enabled) { - ok = ProcessPCP(); - if (ok) continue; - } - - if (!g_mapport_enabled) { - return; - } - - } while (ok || g_mapport_interrupt.sleep_for(PORT_MAPPING_RETRY_PERIOD)); + ProcessPCP(); + } while (g_mapport_interrupt.sleep_for(PORT_MAPPING_RETRY_PERIOD)); } void StartThreadMapPort() @@ -150,8 +138,7 @@ void StartThreadMapPort() void StartMapPort(bool enable) { - g_mapport_enabled = enable; - if (g_mapport_enabled) { + if (enable) { StartThreadMapPort(); } else { InterruptMapPort(); @@ -161,7 +148,6 @@ void StartMapPort(bool enable) void InterruptMapPort() { - g_mapport_enabled = false; if (g_mapport_thread.joinable()) { g_mapport_interrupt(); }