diff options
author | Hanoh Haim <hhaim@cisco.com> | 2016-06-07 15:16:13 +0300 |
---|---|---|
committer | Hanoh Haim <hhaim@cisco.com> | 2016-06-07 15:16:13 +0300 |
commit | ca8b613f14121579d99ce8b7c994e5b87984d410 (patch) | |
tree | 2d7cc0d34c88815df747a02f08e814bf3430f1ac /src/trex_watchdog.cpp | |
parent | 38bcd9c376add0f94e3f660bbcf0558c55f31135 (diff) |
fix wd issue, in some cases it can't exit with CTRL-C
Diffstat (limited to 'src/trex_watchdog.cpp')
-rw-r--r-- | src/trex_watchdog.cpp | 49 |
1 files changed, 38 insertions, 11 deletions
diff --git a/src/trex_watchdog.cpp b/src/trex_watchdog.cpp index e78e8e6d..b320a1b3 100644 --- a/src/trex_watchdog.cpp +++ b/src/trex_watchdog.cpp @@ -36,7 +36,6 @@ limitations under the License. #include <iostream> #include <stdexcept> -#define DISABLE_WATCHDOG_ON_GDB static TrexWatchDog::monitor_st *global_monitor; @@ -122,7 +121,20 @@ static void _callstack_signal_handler(int signr, siginfo_t *info, void *secret) throw std::runtime_error(ss.str()); } + +void TrexWatchDog::init(bool enable){ + m_enable =enable; + if (m_enable) { + register_signal(); + } +} + + void TrexWatchDog::mark_pending_monitor(int count) { + if (!m_enable){ + return; + } + std::unique_lock<std::mutex> lock(m_lock); m_pending += count; lock.unlock(); @@ -130,6 +142,10 @@ void TrexWatchDog::mark_pending_monitor(int count) { void TrexWatchDog::block_on_pending(int max_block_time_ms) { + if (!m_enable){ + return; + } + int timeout_msec = max_block_time_ms; std::unique_lock<std::mutex> lock(m_lock); @@ -163,8 +179,12 @@ void TrexWatchDog::block_on_pending(int max_block_time_ms) { * @return int */ int TrexWatchDog::register_monitor(const std::string &name, double timeout_sec) { + if (!m_enable){ + return 0; + } monitor_st monitor; + /* cannot add monitors while active */ assert(m_active == false); @@ -204,6 +224,10 @@ int TrexWatchDog::register_monitor(const std::string &name, double timeout_sec) * */ void TrexWatchDog::disable_monitor(int handle) { + if (!m_enable){ + return ; + } + assert(handle < m_monitors.size()); m_monitors[handle].active = false; @@ -214,7 +238,9 @@ void TrexWatchDog::disable_monitor(int handle) { * */ void TrexWatchDog::tickle(int handle) { - + if (!m_enable){ + return ; + } assert(handle < m_monitors.size()); /* not nesscary but write gets cache invalidate for nothing */ @@ -226,7 +252,6 @@ void TrexWatchDog::tickle(int handle) { } void TrexWatchDog::register_signal() { - /* do this once */ if (g_signal_init) { return; @@ -247,19 +272,15 @@ void TrexWatchDog::register_signal() { void TrexWatchDog::start() { + if (!m_enable){ + return ; + } + block_on_pending(); /* no pending monitors */ assert(m_pending == 0); - /* under GDB - disable the watchdog */ - #ifdef DISABLE_WATCHDOG_ON_GDB - if (ptrace(PTRACE_TRACEME, 0, NULL, 0) == -1) { - printf("\n\n*** GDB detected - disabling watchdog... ***\n\n"); - return; - } - #endif - m_active = true; m_thread = new std::thread(&TrexWatchDog::_main, this); if (!m_thread) { @@ -268,6 +289,10 @@ void TrexWatchDog::start() { } void TrexWatchDog::stop() { + if (!m_enable){ + return ; + } + m_active = false; if (m_thread) { @@ -285,6 +310,8 @@ void TrexWatchDog::stop() { */ void TrexWatchDog::_main() { + assert(m_enable==true); + /* reset all the monitors */ for (auto &monitor : m_monitors) { monitor.tickled = true; |