summaryrefslogtreecommitdiffstats
path: root/src/tests/once-test.c
diff options
context:
space:
mode:
authorMaarten Bosmans <mkbosmans@gmail.com>2011-06-23 22:21:02 +0200
committerColin Guthrie <colin@mageia.org>2011-06-24 00:32:22 +0100
commit3adc43b8fe507e3140f7d6f9bab32584b9eadfa4 (patch)
treea293ede6cd9ebd1306a1cf1e3deb411724bfbbbc /src/tests/once-test.c
parent2cfacc6f5585f039fa85f849ddb9b89e4d33c432 (diff)
win32: Make once-test work
The barrier is not used when pthread is not available.
Diffstat (limited to 'src/tests/once-test.c')
-rw-r--r--src/tests/once-test.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/tests/once-test.c b/src/tests/once-test.c
index 13791688..8a9995da 100644
--- a/src/tests/once-test.c
+++ b/src/tests/once-test.c
@@ -21,7 +21,9 @@
#include <config.h>
#endif
+#ifdef HAVE_PTHREAD
#include <pthread.h>
+#endif
#include <pulsecore/thread.h>
#include <pulsecore/once.h>
@@ -33,7 +35,9 @@
static pa_once once = PA_ONCE_INIT;
static volatile unsigned n_run = 0;
static const char * volatile ran_by = NULL;
+#ifdef HAVE_PTHREAD
static pthread_barrier_t barrier;
+#endif
static unsigned n_cpu;
#define N_ITERATIONS 500
@@ -45,6 +49,7 @@ static void once_func(void) {
}
static void thread_func(void *data) {
+#ifdef HAVE_PTHREAD
int r;
#ifdef HAVE_PTHREAD_SETAFFINITY_NP
@@ -60,6 +65,7 @@ static void thread_func(void *data) {
r = pthread_barrier_wait(&barrier);
pa_assert(r == 0 || r == PTHREAD_BARRIER_SERIAL_THREAD);
+#endif /* HAVE_PTHREAD */
pa_run_once(&once, once_func);
}
@@ -72,7 +78,9 @@ int main(int argc, char *argv[]) {
for (n = 0; n < N_ITERATIONS; n++) {
pa_thread* threads[N_THREADS];
+#ifdef HAVE_PTHREAD
pa_assert_se(pthread_barrier_init(&barrier, NULL, N_THREADS) == 0);
+#endif
/* Yes, kinda ugly */
pa_zero(once);
@@ -94,7 +102,9 @@ int main(int argc, char *argv[]) {
n_run = 0;
ran_by = NULL;
+#ifdef HAVE_PTHREAD
pa_assert_se(pthread_barrier_destroy(&barrier) == 0);
+#endif
}
return 0;