aboutsummaryrefslogtreecommitdiff
path: root/lib/include
diff options
context:
space:
mode:
authorDavid Oberhollenzer <goliath@infraroot.at>2020-05-13 17:08:54 +0200
committerDavid Oberhollenzer <goliath@infraroot.at>2020-05-13 17:08:54 +0200
commit9084f3862973aa5eccfafe51c6682a6aef123d4d (patch)
treefcd0810e34a1c9b97aa796ebc114fb605f916162 /lib/include
parentdd0007f9dcb850806cb62ecc705c35789e12f175 (diff)
Add utility functions for clearing/setting signal mask
Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
Diffstat (limited to 'lib/include')
-rw-r--r--lib/include/util.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/include/util.h b/lib/include/util.h
new file mode 100644
index 0000000..884eeab
--- /dev/null
+++ b/lib/include/util.h
@@ -0,0 +1,26 @@
+#ifndef UTIL_H
+#define UTIL_H
+
+#include <signal.h>
+
+static inline void cli(sigset_t *old_mask)
+{
+ sigset_t mask;
+
+ sigfillset(&mask);
+ sigprocmask(SIG_SETMASK, &mask, old_mask);
+}
+
+static inline void sti(const sigset_t *old_mask)
+{
+ sigset_t mask;
+
+ if (old_mask == NULL) {
+ sigemptyset(&mask);
+ sigprocmask(SIG_SETMASK, &mask, NULL);
+ } else {
+ sigprocmask(SIG_SETMASK, old_mask, NULL);
+ }
+}
+
+#endif /* UTIL_H */