Skip to content

Commit

Permalink
mapport: remove unnecessary 'g_mapport_enabled'
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
darosior committed Oct 31, 2024
1 parent 8fb45fc commit 28b21b8
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions src/mapport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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()
Expand All @@ -150,8 +136,7 @@ void StartThreadMapPort()

void StartMapPort(bool enable)
{
g_mapport_enabled = enable;
if (g_mapport_enabled) {
if (enable) {
StartThreadMapPort();
} else {
InterruptMapPort();
Expand All @@ -161,7 +146,6 @@ void StartMapPort(bool enable)

void InterruptMapPort()
{
g_mapport_enabled = false;
if (g_mapport_thread.joinable()) {
g_mapport_interrupt();
}
Expand Down

0 comments on commit 28b21b8

Please sign in to comment.