aboutsummaryrefslogtreecommitdiff
path: root/src/util/timeout.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/timeout.c')
-rw-r--r--src/util/timeout.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/util/timeout.c b/src/util/timeout.c
index d273ecb..21f9591 100644
--- a/src/util/timeout.c
+++ b/src/util/timeout.c
@@ -3,10 +3,12 @@
* Copyright (C) 2017-2018 J08nY
*/
#include "timeout.h"
+#include "util/memory.h"
__thread jmp_buf timeout_ptr;
__thread bool timeout_in = false;
-__thread timer_t timeout_timer;
+__thread timer_t *timeout_timer;
+__thread struct sigevent *sevp;
void timeout_handle(int signum, siginfo_t *siginfo, void *other) {
sigset_t mask;
@@ -17,7 +19,19 @@ void timeout_handle(int signum, siginfo_t *siginfo, void *other) {
if (timeout_in) siglongjmp(timeout_ptr, 1);
}
+void timeout_thread_init() {
+ timeout_timer = try_calloc(sizeof(timer_t));
+ sevp = try_calloc(sizeof(struct sigevent));
+}
+
+void timeout_thread_quit() {
+ try_free(timeout_timer);
+ try_free(sevp);
+}
+
bool timeout_init() {
+ // init for the main thread.
+ timeout_thread_init();
struct sigaction new_action;
new_action.sa_sigaction = timeout_handle;
@@ -26,4 +40,9 @@ bool timeout_init() {
sigaction(SIGALRM, &new_action, NULL);
return true;
+}
+
+void timeout_quit() {
+ // deinit the main thread.
+ timeout_thread_quit();
} \ No newline at end of file