We need to do an atomic test-and-set operation to check whether we can
avoid writing to the signal pipe. Use C11 atomics to do this in a portable
way (hopefully).
LIBS="$LIBS -L/sw/lib"
fi
+AX_CHECK_COMPILE_FLAG([-std=c11], [CPPFLAGS="-std=c11"])
+
dnl Compiler hardening flags
dnl No -fstack-protector-all because it doesn't work on all platforms or architectures.
});
if(sig) {
- sig->set = false;
+ atomic_flag_clear(&sig->set);
sig->cb(loop, sig->data);
}
}
}
void signal_trigger(event_loop_t *loop, signal_t *sig) {
- if(sig->set) {
+ if(atomic_flag_test_and_set(&sig->set)) {
return;
}
uint8_t signum = sig->signum;
- sig->set = true;
write(loop->pipefd[1], &signum, 1);
return;
}
sig->cb = cb;
sig->data = data;
sig->signum = signum;
- sig->set = false;
sig->node.data = sig;
+ atomic_flag_clear(&sig->set);
+
if(loop->pipefd[0] == -1) {
pipe_init(loop);
}
typedef struct signal_t {
struct splay_node_t node;
int signum;
- bool set;
+ volatile atomic_flag set;
signal_cb_t cb;
void *data;
} signal_t;
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
+#include <stdatomic.h>
#include <stdbool.h>
#include <stdint.h>
#include <inttypes.h>