summaryrefslogtreecommitdiffstats
path: root/src/tests/rtstutter.c
diff options
context:
space:
mode:
authorMaarten Bosmans <mkbosmans@gmail.com>2011-01-18 11:28:53 +0100
committerMaarten Bosmans <mkbosmans@gmail.com>2011-02-17 12:02:31 +0100
commit30c7c9518440670ca3b627298c4e32885204882f (patch)
tree39a63371cb407207992a3b347e85a559aa8553ef /src/tests/rtstutter.c
parentaebf66bef6ebc8561b3cd4bfb4189ea739056f65 (diff)
tests/rtstutter: Use pa_rtclock
Diffstat (limited to 'src/tests/rtstutter.c')
-rw-r--r--src/tests/rtstutter.c33
1 files changed, 11 insertions, 22 deletions
diff --git a/src/tests/rtstutter.c b/src/tests/rtstutter.c
index 21e3cdeb..9ef835c3 100644
--- a/src/tests/rtstutter.c
+++ b/src/tests/rtstutter.c
@@ -41,6 +41,7 @@
#include <pulsecore/macro.h>
#include <pulsecore/thread.h>
#include <pulsecore/core-util.h>
+#include <pulsecore/core-rtclock.h>
static int msec_lower, msec_upper;
@@ -63,36 +64,24 @@ static void work(void *p) {
#endif
for (;;) {
- struct timespec now, end;
- uint64_t nsec;
+ struct timeval now, end;
+ uint64_t usec;
pa_log_notice("CPU%i: Sleeping for 1s", PA_PTR_TO_UINT(p));
pa_msleep(1000);
-#ifdef CLOCK_REALTIME
- pa_assert_se(clock_gettime(CLOCK_REALTIME, &end) == 0);
-#endif
-
- nsec =
- (uint64_t) ((((double) rand())*(double)(msec_upper-msec_lower)*PA_NSEC_PER_MSEC)/RAND_MAX) +
- (uint64_t) ((uint64_t) msec_lower*PA_NSEC_PER_MSEC);
+ usec =
+ (uint64_t) ((((double) rand())*(double)(msec_upper-msec_lower)*PA_USEC_PER_MSEC)/RAND_MAX) +
+ (uint64_t) ((uint64_t) msec_lower*PA_USEC_PER_MSEC);
- pa_log_notice("CPU%i: Freezing for %ims", PA_PTR_TO_UINT(p), (int) (nsec/PA_NSEC_PER_MSEC));
+ pa_log_notice("CPU%i: Freezing for %ims", PA_PTR_TO_UINT(p), (int) (usec/PA_USEC_PER_MSEC));
- end.tv_sec += (time_t) (nsec / PA_NSEC_PER_SEC);
- end.tv_nsec += (long int) (nsec % PA_NSEC_PER_SEC);
-
- while ((pa_usec_t) end.tv_nsec > PA_NSEC_PER_SEC) {
- end.tv_sec++;
- end.tv_nsec -= (long int) PA_NSEC_PER_SEC;
- }
+ pa_rtclock_get(&end);
+ pa_timeval_add(&end, usec);
do {
-#ifdef CLOCK_REALTIME
- pa_assert_se(clock_gettime(CLOCK_REALTIME, &now) == 0);
-#endif
- } while (now.tv_sec < end.tv_sec ||
- (now.tv_sec == end.tv_sec && now.tv_nsec < end.tv_nsec));
+ pa_rtclock_get(&now);
+ } while (pa_timeval_cmp(&now, &end) < 0);
}
}