summaryrefslogtreecommitdiffstats
path: root/include/timer.h
diff options
context:
space:
mode:
authorKarel Zak2013-03-13 12:13:11 +0100
committerKarel Zak2013-03-13 12:13:11 +0100
commit01acff6e0919ff373ffd9cf94b202d27c6be19a1 (patch)
tree1c58970ce5fc875b274d0ca2440208c80ea588f9 /include/timer.h
parentflock: use strtotimeval() from libcommon (diff)
downloadkernel-qcow2-util-linux-01acff6e0919ff373ffd9cf94b202d27c6be19a1.tar.gz
kernel-qcow2-util-linux-01acff6e0919ff373ffd9cf94b202d27c6be19a1.tar.xz
kernel-qcow2-util-linux-01acff6e0919ff373ffd9cf94b202d27c6be19a1.zip
include: add timer.h
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'include/timer.h')
-rw-r--r--include/timer.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/include/timer.h b/include/timer.h
new file mode 100644
index 000000000..b820453d4
--- /dev/null
+++ b/include/timer.h
@@ -0,0 +1,31 @@
+#ifndef UTIL_LINUX_TIMER_H
+#define UTIL_LINUX_TIMER_H
+
+#include <signal.h>
+#include <sys/time.h>
+
+static inline void setup_timer(
+ struct itimerval *timer,
+ struct itimerval *old_timer,
+ struct sigaction *old_sa,
+ void (*timeout_handler)(int))
+{
+ struct sigaction sa;
+
+ memset(&sa, 0, sizeof sa);
+ sa.sa_handler = timeout_handler;
+ sa.sa_flags = SA_RESETHAND;
+ sigaction(SIGALRM, &sa, old_sa);
+
+ setitimer(ITIMER_REAL, timer, old_timer);
+}
+
+static inline void cancel_timer(
+ struct itimerval *old_timer,
+ struct sigaction *old_sa)
+{
+ setitimer(ITIMER_REAL, old_timer, NULL);
+ sigaction(SIGALRM, old_sa, NULL);
+}
+
+#endif