mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-12-15 08:56:34 -05:00
win32: Make once-test work
The barrier is not used when pthread is not available.
This commit is contained in:
parent
2cfacc6f55
commit
3adc43b8fe
4 changed files with 32 additions and 9 deletions
|
|
@ -271,6 +271,7 @@ TESTS = \
|
||||||
|
|
||||||
TESTS_norun = \
|
TESTS_norun = \
|
||||||
mcalign-test \
|
mcalign-test \
|
||||||
|
once-test \
|
||||||
pacat-simple \
|
pacat-simple \
|
||||||
parec-simple \
|
parec-simple \
|
||||||
extended-test \
|
extended-test \
|
||||||
|
|
@ -309,13 +310,6 @@ TESTS_norun += \
|
||||||
alsa-time-test
|
alsa-time-test
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !OS_IS_DARWIN
|
|
||||||
if !OS_IS_WIN32
|
|
||||||
TESTS_BINARIES += \
|
|
||||||
once-test
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
if BUILD_TESTS_DEFAULT
|
if BUILD_TESTS_DEFAULT
|
||||||
noinst_PROGRAMS = $(TESTS) $(TESTS_norun)
|
noinst_PROGRAMS = $(TESTS) $(TESTS_norun)
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,27 @@ pa_thread* pa_thread_self(void) {
|
||||||
return pa_tls_get(thread_tls);
|
return pa_tls_get(thread_tls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* pa_thread_get_data(pa_thread *t) {
|
||||||
|
pa_assert(t);
|
||||||
|
|
||||||
|
return t->userdata;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pa_thread_set_data(pa_thread *t, void *userdata) {
|
||||||
|
pa_assert(t);
|
||||||
|
|
||||||
|
t->userdata = userdata;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pa_thread_set_name(pa_thread *t, const char *name) {
|
||||||
|
/* Not implemented */
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *pa_thread_get_name(pa_thread *t) {
|
||||||
|
/* Not implemented */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void pa_thread_yield(void) {
|
void pa_thread_yield(void) {
|
||||||
Sleep(0);
|
Sleep(0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,9 @@
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_PTHREAD
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <pulsecore/thread.h>
|
#include <pulsecore/thread.h>
|
||||||
#include <pulsecore/once.h>
|
#include <pulsecore/once.h>
|
||||||
|
|
@ -33,7 +35,9 @@
|
||||||
static pa_once once = PA_ONCE_INIT;
|
static pa_once once = PA_ONCE_INIT;
|
||||||
static volatile unsigned n_run = 0;
|
static volatile unsigned n_run = 0;
|
||||||
static const char * volatile ran_by = NULL;
|
static const char * volatile ran_by = NULL;
|
||||||
|
#ifdef HAVE_PTHREAD
|
||||||
static pthread_barrier_t barrier;
|
static pthread_barrier_t barrier;
|
||||||
|
#endif
|
||||||
static unsigned n_cpu;
|
static unsigned n_cpu;
|
||||||
|
|
||||||
#define N_ITERATIONS 500
|
#define N_ITERATIONS 500
|
||||||
|
|
@ -45,6 +49,7 @@ static void once_func(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void thread_func(void *data) {
|
static void thread_func(void *data) {
|
||||||
|
#ifdef HAVE_PTHREAD
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
#ifdef HAVE_PTHREAD_SETAFFINITY_NP
|
#ifdef HAVE_PTHREAD_SETAFFINITY_NP
|
||||||
|
|
@ -60,6 +65,7 @@ static void thread_func(void *data) {
|
||||||
|
|
||||||
r = pthread_barrier_wait(&barrier);
|
r = pthread_barrier_wait(&barrier);
|
||||||
pa_assert(r == 0 || r == PTHREAD_BARRIER_SERIAL_THREAD);
|
pa_assert(r == 0 || r == PTHREAD_BARRIER_SERIAL_THREAD);
|
||||||
|
#endif /* HAVE_PTHREAD */
|
||||||
|
|
||||||
pa_run_once(&once, once_func);
|
pa_run_once(&once, once_func);
|
||||||
}
|
}
|
||||||
|
|
@ -72,7 +78,9 @@ int main(int argc, char *argv[]) {
|
||||||
for (n = 0; n < N_ITERATIONS; n++) {
|
for (n = 0; n < N_ITERATIONS; n++) {
|
||||||
pa_thread* threads[N_THREADS];
|
pa_thread* threads[N_THREADS];
|
||||||
|
|
||||||
|
#ifdef HAVE_PTHREAD
|
||||||
pa_assert_se(pthread_barrier_init(&barrier, NULL, N_THREADS) == 0);
|
pa_assert_se(pthread_barrier_init(&barrier, NULL, N_THREADS) == 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Yes, kinda ugly */
|
/* Yes, kinda ugly */
|
||||||
pa_zero(once);
|
pa_zero(once);
|
||||||
|
|
@ -94,7 +102,9 @@ int main(int argc, char *argv[]) {
|
||||||
n_run = 0;
|
n_run = 0;
|
||||||
ran_by = NULL;
|
ran_by = NULL;
|
||||||
|
|
||||||
|
#ifdef HAVE_PTHREAD
|
||||||
pa_assert_se(pthread_barrier_destroy(&barrier) == 0);
|
pa_assert_se(pthread_barrier_destroy(&barrier) == 0);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -94,8 +94,6 @@ int main(int argc, char *argv[]) {
|
||||||
int i, k;
|
int i, k;
|
||||||
pa_thread* t[THREADS_MAX];
|
pa_thread* t[THREADS_MAX];
|
||||||
|
|
||||||
assert(pa_thread_is_running(pa_thread_self()));
|
|
||||||
|
|
||||||
mutex = pa_mutex_new(FALSE, FALSE);
|
mutex = pa_mutex_new(FALSE, FALSE);
|
||||||
cond1 = pa_cond_new();
|
cond1 = pa_cond_new();
|
||||||
cond2 = pa_cond_new();
|
cond2 = pa_cond_new();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue