]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/rtclock.c
Merge commit 'origin/master-tx'
[pulseaudio] / src / pulsecore / rtclock.c
index f33de83072adcdc810530a083f5ac358740fa2a0..56ab2ef02a593d76f37d6f6504c9aac92567ede6 100644 (file)
 #include <stddef.h>
 #include <time.h>
 #include <sys/time.h>
+#include <errno.h>
+
+#ifdef HAVE_SYS_PRCTL_H
+#include <sys/prctl.h>
+#endif
 
 #include <pulse/timeval.h>
 #include <pulsecore/macro.h>
+#include <pulsecore/core-error.h>
 
 #include "rtclock.h"
 
@@ -89,6 +95,29 @@ pa_bool_t pa_rtclock_hrtimer(void) {
 #endif
 }
 
+void pa_rtclock_hrtimer_enable(void) {
+#ifdef PR_SET_TIMERSLACK
+    int slack_ns;
+
+    if ((slack_ns = prctl(PR_GET_TIMERSLACK, 0, 0, 0, 0)) < 0) {
+        pa_log_info("PR_GET_TIMERSLACK/PR_SET_TIMERSLACK not supported.");
+        return;
+    }
+
+    pa_log_debug("Timer slack set to %i us.", slack_ns/1000);
+
+    slack_ns = 500000000;
+
+    pa_log_debug("Setting timer slack to %i us.", slack_ns/1000);
+
+    if (prctl(PR_SET_TIMERSLACK, slack_ns, 0, 0, 0) < 0) {
+        pa_log_warn("PR_SET_TIMERSLACK failed: %s", pa_cstrerror(errno));
+        return;
+    }
+
+#endif
+}
+
 pa_usec_t pa_rtclock_usec(void) {
     struct timeval tv;
 
@@ -115,3 +144,11 @@ struct timeval* pa_rtclock_from_wallclock(struct timeval *tv) {
 
     return tv;
 }
+
+pa_usec_t pa_timespec_load(const struct timespec *ts) {
+    pa_assert(ts);
+
+    return
+        (pa_usec_t) ts->tv_sec * PA_USEC_PER_SEC +
+        (pa_usec_t) ts->tv_nsec / PA_NSEC_PER_USEC;
+}