Skip to content

Commit e533ac4

Browse files
committed
fix potential nullptr problem with Log when used from multiple threads during shutdown; reduce the intercycle delay to 2ms from 5ms for all main FNE threads;
1 parent 7fc583c commit e533ac4

2 files changed

Lines changed: 32 additions & 7 deletions

File tree

src/common/Log.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,10 @@ void LogFinalise()
191191
#if defined(CATCH2_TEST_COMPILATION)
192192
return;
193193
#endif
194-
if (m_fpLog != nullptr)
194+
if (m_fpLog != nullptr) {
195195
::fclose(m_fpLog);
196+
m_fpLog = nullptr;
197+
}
196198
#if !defined(_WIN32)
197199
if (g_useSyslog)
198200
closelog();
@@ -330,8 +332,10 @@ void Log(uint32_t level, const char *module, const char* file, const int lineNo,
330332
if (!ret)
331333
return;
332334

333-
::fprintf(m_fpLog, "%s\n", buffer);
334-
::fflush(m_fpLog);
335+
if (m_fpLog != nullptr) {
336+
::fprintf(m_fpLog, "%s\n", buffer);
337+
::fflush(m_fpLog);
338+
}
335339
} else {
336340
#if !defined(_WIN32)
337341
// convert our log level into syslog level

src/fne/HostFNE.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ using namespace lookups;
3939
// Constants
4040
// ---------------------------------------------------------------------------
4141

42+
#define THREAD_CYCLE_THRESHOLD 2U
43+
4244
#define IDLE_WARMUP_MS 5U
4345
#define DEFAULT_MTU_SIZE 496
4446

@@ -646,10 +648,18 @@ void* HostFNE::threadMasterNetwork(void* arg)
646648
::pthread_setname_np(th->thread, threadName.c_str());
647649
#endif // _GNU_SOURCE
648650

651+
StopWatch stopWatch;
652+
stopWatch.start();
653+
649654
if (fne->m_network != nullptr) {
650655
while (!g_killed) {
656+
uint32_t ms = stopWatch.elapsed();
657+
stopWatch.start();
658+
651659
fne->m_network->processNetwork();
652-
Thread::sleep(5U);
660+
661+
if (ms < THREAD_CYCLE_THRESHOLD)
662+
Thread::sleep(THREAD_CYCLE_THRESHOLD);
653663
}
654664
}
655665

@@ -694,10 +704,18 @@ void* HostFNE::threadDiagNetwork(void* arg)
694704
::pthread_setname_np(th->thread, threadName.c_str());
695705
#endif // _GNU_SOURCE
696706

707+
StopWatch stopWatch;
708+
stopWatch.start();
709+
697710
if (fne->m_diagNetwork != nullptr) {
698711
while (!g_killed) {
712+
uint32_t ms = stopWatch.elapsed();
713+
stopWatch.start();
714+
699715
fne->m_diagNetwork->processNetwork();
700-
Thread::sleep(5U);
716+
717+
if (ms < THREAD_CYCLE_THRESHOLD)
718+
Thread::sleep(THREAD_CYCLE_THRESHOLD);
701719
}
702720
}
703721

@@ -890,6 +908,7 @@ void* HostFNE::threadVirtualNetworking(void* arg)
890908
stopWatch.start();
891909

892910
while (!g_killed) {
911+
uint32_t ms = stopWatch.elapsed();
893912
stopWatch.start();
894913

895914
uint8_t packet[DEFAULT_MTU_SIZE];
@@ -908,7 +927,8 @@ void* HostFNE::threadVirtualNetworking(void* arg)
908927
}
909928
}
910929

911-
Thread::sleep(2U);
930+
if (ms < THREAD_CYCLE_THRESHOLD)
931+
Thread::sleep(THREAD_CYCLE_THRESHOLD);
912932
}
913933
}
914934

@@ -968,7 +988,8 @@ void* HostFNE::threadVirtualNetworkingClock(void* arg)
968988
break;
969989
}
970990

971-
Thread::sleep(2U);
991+
if (ms < THREAD_CYCLE_THRESHOLD)
992+
Thread::sleep(THREAD_CYCLE_THRESHOLD);
972993
}
973994
}
974995

0 commit comments

Comments
 (0)