]> code.delx.au - pulseaudio/blobdiff - polyp/util.c
latency work
[pulseaudio] / polyp / util.c
index 70766a0685645984df6bee8847d89930ac808875..6c8febb62494cbf634d365d1c39b2576398f4c1e 100644 (file)
@@ -36,6 +36,7 @@
 #include <pwd.h>
 #include <signal.h>
 #include <pthread.h>
+#include <sys/time.h>
 
 #include "util.h"
 #include "xmalloc.h"
@@ -114,12 +115,16 @@ void pa_check_for_sigpipe(void) {
     struct sigaction sa;
     sigset_t set;
 
+#ifdef HAVE_PTHREAD    
     if (pthread_sigmask(SIG_SETMASK, NULL, &set) < 0) {
+#endif
         if (sigprocmask(SIG_SETMASK, NULL, &set) < 0) {
             fprintf(stderr, __FILE__": sigprocmask() failed: %s\n", strerror(errno));
             return;
         }
+#ifdef HAVE_PTHREAD
     }
+#endif
 
     if (sigismember(&set, SIGPIPE))
         return;
@@ -188,3 +193,23 @@ char *pa_get_host_name(char *s, size_t l) {
     s[l-1] = 0;
     return s;
 }
+
+uint32_t pa_age(struct timeval *tv) {
+    struct timeval now;
+    uint32_t r;
+    assert(tv);
+
+    if (tv->tv_sec == 0)
+        return 0;
+
+    gettimeofday(&now, NULL);
+    
+    r = (now.tv_sec-tv->tv_sec) * 1000000;
+
+    if (now.tv_usec >= tv->tv_usec)
+        r += now.tv_usec - tv->tv_usec;
+    else
+        r -= tv->tv_usec - now.tv_usec;
+
+    return r;
+}