aboutsummaryrefslogtreecommitdiff
path: root/src/util/timeout.h
diff options
context:
space:
mode:
authorJ08nY2017-10-04 18:41:47 +0200
committerJ08nY2017-10-04 18:41:47 +0200
commitcaa000e3625241b930fdcda1594bbaf9c9acf642 (patch)
tree2eb6ce02a3a172bd2cf4463d45bcbd7954589e31 /src/util/timeout.h
parent45c08cad912299a8d2043e432bb38e003151526b (diff)
downloadecgen-caa000e3625241b930fdcda1594bbaf9c9acf642.tar.gz
ecgen-caa000e3625241b930fdcda1594bbaf9c9acf642.tar.zst
ecgen-caa000e3625241b930fdcda1594bbaf9c9acf642.zip
Diffstat (limited to 'src/util/timeout.h')
-rw-r--r--src/util/timeout.h41
1 files changed, 25 insertions, 16 deletions
diff --git a/src/util/timeout.h b/src/util/timeout.h
index 7a1ebb2..0226fda 100644
--- a/src/util/timeout.h
+++ b/src/util/timeout.h
@@ -9,25 +9,34 @@
#include <sys/syscall.h>
#include <time.h>
#include <unistd.h>
+#include "io/output.h"
#include "misc/config.h"
-extern __thread jmp_buf exception;
+extern __thread sigjmp_buf timeout_ptr;
+extern __thread bool timeout_in;
+extern __thread timer_t timeout_timer;
-#define timeout_start(seconds) \
- do { \
- struct sigevent sevp; \
- sevp.sigev_notify = SIGEV_THREAD_ID; \
- sevp.sigev_signo = SIGALRM; \
- sevp._sigev_un._tid = (__pid_t)syscall(SYS_gettid); \
- \
- timer_t timer; \
- timer_create(CLOCK_MONOTONIC, &sevp, &timer); \
- struct itimerspec timer_time = { \
- .it_interval = {.tv_sec = (seconds), .tv_nsec = 0}, \
- .it_value = {.tv_sec = 0, .tv_nsec = 0}}; \
- timer_settime(timer, 0, &timer_time, NULL); \
- setjmp(exception); \
- } while (0);
+#define timeout_start(seconds) \
+ { \
+ struct sigevent sevp; \
+ sevp.sigev_notify = SIGEV_THREAD_ID; \
+ sevp.sigev_signo = SIGALRM; \
+ sevp._sigev_un._tid = (__pid_t)syscall(SYS_gettid); \
+ \
+ timer_create(CLOCK_MONOTONIC, &sevp, &timeout_timer); \
+ struct itimerspec timer_time = { \
+ .it_interval = {.tv_sec = 0, .tv_nsec = 0}, \
+ .it_value = {.tv_sec = (seconds), .tv_nsec = 0}}; \
+ timer_settime(timeout_timer, 0, &timer_time, NULL); \
+ timeout_in = true; \
+ }; \
+ if (sigsetjmp(timeout_ptr, 1) == 1)
+
+#define timeout_stop() \
+ { \
+ timeout_in = false; \
+ timer_delete(timeout_timer); \
+ }
/**
* @brief