diff --git a/rdkperf/rdk_perf.cpp b/rdkperf/rdk_perf.cpp index 37bb00e..b9614a3 100644 --- a/rdkperf/rdk_perf.cpp +++ b/rdkperf/rdk_perf.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include "rdk_perf_logging.h" #include "rdk_perf_scopedlock.h" @@ -110,7 +111,7 @@ class TimerCallback { void StopTask() { LOG(eWarning, "Stoping Timer Task\n"); - m_bContinue = false; + m_bContinue.store(false); Signal(EXIT_LOOP); return; }; @@ -141,18 +142,29 @@ class TimerCallback { } void Task() { - m_bContinue = true; - LOG(eWarning, "Task Started\n"); - while(m_bContinue == true) { + + { + std::unique_lock lck(m_mtx); + if (m_current_state == EXIT_LOOP) { + LOG(eWarning, " Early StopTask detected. Exiting loop before start.\n"); + return; + } + m_bContinue.store(true); + } + + LOG(eWarning, "Task Starting\n"); + while(m_bContinue.load() == true) { if(!Loop()) { LOG(eWarning, "Timer loop signaled for Exit..\n"); - m_bContinue = false; + m_bContinue.store(false); break; } LOG(eTrace, "Task sleeping %d seconds\n", TIMER_INTERVAL_SECONDS); SignalResult result = Wait(TIMER_INTERVAL_SECONDS); if(result == EXIT_LOOP) { LOG(eWarning, "Exit task loop has been signaled\n"); + m_bContinue.store(false); + break; } } LOG(eWarning, "Task Completed\n"); @@ -160,7 +172,7 @@ class TimerCallback { }; private: void* m_Context; - bool m_bContinue; + std::atomic m_bContinue; uint32_t m_nDelay; uint32_t m_nCount; // Timeout, signaling