WatchDog and IO functions: ensure we return it to normal timeout in case of exception... 83/5383/1
authorYaroslav Brustinov <[email protected]>
Sun, 5 Feb 2017 13:52:21 +0000 (15:52 +0200)
committerYaroslav Brustinov <[email protected]>
Sun, 5 Feb 2017 13:52:21 +0000 (15:52 +0200)
Change-Id: I5d2e119f19c3e3214fdbe8108ea35af899ab49a5
Signed-off-by: Yaroslav Brustinov <[email protected]>
src/rpc-server/commands/trex_rpc_cmd_general.cpp
src/stateless/dp/trex_stateless_dp_core.cpp
src/trex_watchdog.h

index d254674..4d73714 100644 (file)
@@ -637,11 +637,9 @@ TrexRpcCmdPushRemote::_run(const Json::Value &params, Json::Value &result) {
     }
 
 
-    /* IO might take time, increase timeout of WD */
-    TrexMonitor * cur_monitor = TrexWatchDog::getInstance().get_current_monitor();
-    if (cur_monitor != NULL) {
-        cur_monitor->io_begin();
-    }
+    /* IO might take time, increase timeout of WD inside this function */
+    TrexWatchDog::IOFunction dummy;
+    (void)dummy;
 
     try {
         port->push_remote(pcap_filename, ipg_usec, min_ipg_sec, speedup, count, duration, is_dual);
@@ -649,11 +647,6 @@ TrexRpcCmdPushRemote::_run(const Json::Value &params, Json::Value &result) {
         generate_execute_err(result, ex.what());
     }
 
-    /* revert timeout of WD */
-    if (cur_monitor != NULL) {
-        cur_monitor->io_end();
-    }
-
     result["result"] = Json::objectValue;
     return (TREX_RPC_CMD_OK);
 
index 0a31717..d8563e9 100644 (file)
@@ -1282,10 +1282,7 @@ bool CGenNodePCAP::create(uint8_t port_id,
     m_min_ipg_sec    = min_ipg_sec;
 
     /* increase timeout of WD due to io */
-    TrexMonitor * cur_monitor = TrexWatchDog::getInstance().get_current_monitor();
-    if (cur_monitor != NULL) {
-        cur_monitor->io_begin();
-    }
+    TrexWatchDog::IOFunction::io_begin();
 
     /* mark this node as slow path */
     set_slow_path(true);
@@ -1351,10 +1348,7 @@ void CGenNodePCAP::destroy() {
     }
 
     /* end of io, return normal timeout of WD */
-    TrexMonitor * cur_monitor = TrexWatchDog::getInstance().get_current_monitor();
-    if (cur_monitor != NULL) {
-        cur_monitor->io_end();
-    }
+    TrexWatchDog::IOFunction::io_end();
 
     m_state = PCAP_INVALID;
 }
index 67dbb80..b4512b6 100644 (file)
@@ -193,6 +193,8 @@ public:
         return instance;
     }
 
+    class IOFunction;
+
     void init(bool enable);
 
     /**
@@ -252,5 +254,30 @@ private:
     static bool                g_signal_init;
 };
 
+class TrexWatchDog::IOFunction {
+public:
+    static void io_begin() {
+        TrexMonitor * cur_monitor = TrexWatchDog::getInstance().get_current_monitor();
+        if (cur_monitor != NULL) {
+            cur_monitor->io_begin();
+        }
+    }
+
+    static void io_end() {
+        TrexMonitor * cur_monitor = TrexWatchDog::getInstance().get_current_monitor();
+        if (cur_monitor != NULL) {
+            cur_monitor->io_end();
+        }
+    }
+
+    IOFunction() {
+        IOFunction::io_begin();
+    }
+
+    ~IOFunction() {
+        IOFunction::io_end();
+    }
+
+};
 
 #endif /* __TREX_WATCHDOG_H__ */