Skip to content
Snippets Groups Projects
Unverified Commit 2ca45947 authored by Tomáš Pecka's avatar Tomáš Pecka
Browse files

worker: fix timeval initialization

parent 2bf3517a
No related branches found
No related tags found
2 merge requests!270.2.0,!21fetch list of algorithms (introspect) via API
...@@ -13,17 +13,21 @@ ...@@ -13,17 +13,21 @@
#define FD_STDOUT 1 #define FD_STDOUT 1
#define FD_STDERR 2 #define FD_STDERR 2
   
using namespace std::chrono_literals;
/* Communication between signal handler and the rest of the program */ /* Communication between signal handler and the rest of the program */
int g_Wakeup[2]; // pipe for wakeup int g_Wakeup[2]; // pipe for wakeup
int g_RecvSignal; // signalled flag int g_RecvSignal; // signalled flag
   
static int waitSignalTimeout(int timeout) static int waitSignalTimeout(const std::chrono::microseconds& duration)
{ {
struct timeval tv; struct timeval tv;
fd_set rd; fd_set rd;
   
tv.tv_sec = 0; auto duration_secs = std::chrono::duration_cast<std::chrono::seconds>(duration);
tv.tv_usec = timeout; auto duration_usecs = std::chrono::duration_cast<std::chrono::microseconds>(duration - duration_secs);
tv.tv_sec = duration_secs.count();
tv.tv_usec = duration_usecs.count();
FD_ZERO(&rd); FD_ZERO(&rd);
FD_SET(g_Wakeup[PIPE_RD], &rd); FD_SET(g_Wakeup[PIPE_RD], &rd);
   
...@@ -114,9 +118,9 @@ std::tuple<ResultType, std::string> _evaluate(const std::chrono::microseconds& t ...@@ -114,9 +118,9 @@ std::tuple<ResultType, std::string> _evaluate(const std::chrono::microseconds& t
   
/* lets wait the specified time of microseconds, maybe the child will terminate on its own */ /* lets wait the specified time of microseconds, maybe the child will terminate on its own */
spdlog::debug("Waiting for child. Timeout: {} us", timeout.count()); spdlog::debug("Waiting for child. Timeout: {} us", timeout.count());
if (!waitSignalTimeout(timeout.count())) { if (!waitSignalTimeout(timeout)) {
kill(pid, SIGTERM); kill(pid, SIGTERM);
while (!waitSignalTimeout(250000)) /* ... and in case it did not ..., SIGKILL it every 1/4 second */ while (!waitSignalTimeout(250ms)) /* ... and in case it did not ..., SIGKILL it every 1/4 second */
kill(pid, SIGKILL); kill(pid, SIGKILL);
} }
   
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment