[pulseaudio-commits] r1681 - in /branches/lennart/src/pulse: timeval.c timeval.h

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Tue Aug 21 17:18:06 PDT 2007


Author: lennart
Date: Wed Aug 22 02:18:04 2007
New Revision: 1681

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1681&root=3Dpulseaudio&vi=
ew=3Drev
Log:
modernizations

Modified:
    branches/lennart/src/pulse/timeval.c
    branches/lennart/src/pulse/timeval.h

Modified: branches/lennart/src/pulse/timeval.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulse/time=
val.c?rev=3D1681&root=3Dpulseaudio&r1=3D1680&r2=3D1681&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/pulse/timeval.c (original)
+++ branches/lennart/src/pulse/timeval.c Wed Aug 22 02:18:04 2007
@@ -26,7 +26,6 @@
 #include <config.h>
 #endif
 =

-#include <assert.h>
 #include <stddef.h>
 #include <sys/time.h>
 =

@@ -34,15 +33,17 @@
 #include <windows.h>
 #endif
 =

-#include "../pulsecore/winsock.h"
+#include <pulsecore/winsock.h>
+#include <pulsecore/macro.h>
 =

 #include "timeval.h"
 =

 struct timeval *pa_gettimeofday(struct timeval *tv) {
 #ifdef HAVE_GETTIMEOFDAY
-    assert(tv);
+    pa_assert(tv);
 =

-    return gettimeofday(tv, NULL) < 0 ? NULL : tv;
+    pa_assert_se(gettimeofday(tv, NULL) =3D=3D 0);
+    return tv;
 #elif defined(OS_IS_WIN32)
     /*
      * Copied from implementation by Steven Edwards (LGPL).
@@ -54,12 +55,12 @@
 #else
 #define EPOCHFILETIME (116444736000000000LL)
 #endif
-
+    =

     FILETIME        ft;
     LARGE_INTEGER   li;
     __int64         t;
 =

-    assert(tv);
+    pa_assert(tv);
 =

     GetSystemTimeAsFileTime(&ft);
     li.LowPart  =3D ft.dwLowDateTime;
@@ -67,8 +68,8 @@
     t  =3D li.QuadPart;       /* In 100-nanosecond intervals */
     t -=3D EPOCHFILETIME;     /* Offset to the Epoch time */
     t /=3D 10;                /* In microseconds */
-    tv->tv_sec  =3D (long)(t / 1000000);
-    tv->tv_usec =3D (long)(t % 1000000);
+    tv->tv_sec  =3D (time_t) (t / PA_USEC_PER_SEC);
+    tv->tv_usec =3D (suseconds_t) (t % PA_USEC_PER_SEC);
 =

     return tv;
 #else
@@ -78,9 +79,10 @@
 =

 pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b=
) {
     pa_usec_t r;
-    assert(a && b);
+    pa_assert(a);
+    pa_assert(b);
 =

-    /* Check which whan is the earlier time and swap the two arguments if =
reuqired. */
+    /* Check which whan is the earlier time and swap the two arguments if =
required. */
     if (pa_timeval_cmp(a, b) < 0) {
         const struct timeval *c;
         c =3D a;
@@ -89,7 +91,7 @@
     }
 =

     /* Calculate the second difference*/
-    r =3D ((pa_usec_t) a->tv_sec - b->tv_sec)* 1000000;
+    r =3D ((pa_usec_t) a->tv_sec - b->tv_sec) * PA_USEC_PER_SEC;
 =

     /* Calculate the microsecond difference */
     if (a->tv_usec > b->tv_usec)
@@ -101,7 +103,8 @@
 }
 =

 int pa_timeval_cmp(const struct timeval *a, const struct timeval *b) {
-    assert(a && b);
+    pa_assert(a);
+    pa_assert(b);
 =

     if (a->tv_sec < b->tv_sec)
         return -1;
@@ -120,25 +123,25 @@
 =

 pa_usec_t pa_timeval_age(const struct timeval *tv) {
     struct timeval now;
-    assert(tv);
+    pa_assert(tv);
 =

     return pa_timeval_diff(pa_gettimeofday(&now), tv);
 }
 =

 struct timeval* pa_timeval_add(struct timeval *tv, pa_usec_t v) {
     unsigned long secs;
-    assert(tv);
+    pa_assert(tv);
 =

-    secs =3D (v/1000000);
-    tv->tv_sec +=3D (unsigned long) secs;
-    v -=3D secs*1000000;
+    secs =3D (unsigned long) (v/PA_USEC_PER_SEC);
+    tv->tv_sec +=3D secs;
+    v -=3D ((pa_usec_t) secs) * PA_USEC_PER_SEC;
 =

-    tv->tv_usec +=3D v;
+    tv->tv_usec +=3D (suseconds_t) v;
 =

     /* Normalize */
-    while (tv->tv_usec >=3D 1000000) {
+    while (tv->tv_usec >=3D PA_USEC_PER_SEC) {
         tv->tv_sec++;
-        tv->tv_usec -=3D 1000000;
+        tv->tv_usec -=3D PA_USEC_PER_SEC;
     }
 =

     return tv;

Modified: branches/lennart/src/pulse/timeval.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulse/time=
val.h?rev=3D1681&root=3Dpulseaudio&r1=3D1680&r2=3D1681&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/pulse/timeval.h (original)
+++ branches/lennart/src/pulse/timeval.h Wed Aug 22 02:18:04 2007
@@ -33,6 +33,10 @@
 =

 PA_C_DECL_BEGIN
 =

+#define PA_MSEC_PER_SEC 1000
+#define PA_USEC_PER_SEC 1000000
+#define PA_NSEC_PER_SEC 1000000000
+
 struct timeval;
 =

 /** Return the current timestamp, just like UNIX gettimeofday() */




More information about the pulseaudio-commits mailing list