Skip to content

Commit 9e6cba2

Browse files
committed
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.
1 parent 8fb45fc commit 9e6cba2

File tree

1 file changed

+3
-17
lines changed

1 file changed

+3
-17
lines changed

src/mapport.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
static CThreadInterrupt g_mapport_interrupt;
2727
static std::thread g_mapport_thread;
28-
static std::atomic_bool g_mapport_enabled{false};
2928

3029
using namespace std::chrono_literals;
3130
static constexpr auto PORT_MAPPING_REANNOUNCE_PERIOD{20min};
@@ -124,20 +123,9 @@ static bool ProcessPCP()
124123

125124
static void ThreadMapPort()
126125
{
127-
bool ok;
128126
do {
129-
ok = false;
130-
131-
if (g_mapport_enabled) {
132-
ok = ProcessPCP();
133-
if (ok) continue;
134-
}
135-
136-
if (!g_mapport_enabled) {
137-
return;
138-
}
139-
140-
} while (ok || g_mapport_interrupt.sleep_for(PORT_MAPPING_RETRY_PERIOD));
127+
ProcessPCP();
128+
} while (g_mapport_interrupt.sleep_for(PORT_MAPPING_RETRY_PERIOD));
141129
}
142130

143131
void StartThreadMapPort()
@@ -150,8 +138,7 @@ void StartThreadMapPort()
150138

151139
void StartMapPort(bool enable)
152140
{
153-
g_mapport_enabled = enable;
154-
if (g_mapport_enabled) {
141+
if (enable) {
155142
StartThreadMapPort();
156143
} else {
157144
InterruptMapPort();
@@ -161,7 +148,6 @@ void StartMapPort(bool enable)
161148

162149
void InterruptMapPort()
163150
{
164-
g_mapport_enabled = false;
165151
if (g_mapport_thread.joinable()) {
166152
g_mapport_interrupt();
167153
}

0 commit comments

Comments
 (0)