diff --git a/src/mapport.cpp b/src/mapport.cpp index 2bb33cdbd92330..b3030171447023 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,7 @@ 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)); + while ((!g_mapport_interrupt && ProcessPCP()) || g_mapport_interrupt.sleep_for(PORT_MAPPING_RETRY_PERIOD)) {} } void StartThreadMapPort() @@ -150,8 +136,7 @@ void StartThreadMapPort() void StartMapPort(bool enable) { - g_mapport_enabled = enable; - if (g_mapport_enabled) { + if (enable) { StartThreadMapPort(); } else { InterruptMapPort(); @@ -161,7 +146,6 @@ void StartMapPort(bool enable) void InterruptMapPort() { - g_mapport_enabled = false; if (g_mapport_thread.joinable()) { g_mapport_interrupt(); }