summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/pulsecore/thread-posix.c9
-rw-r--r--src/pulsecore/thread.h1
-rw-r--r--src/tests/thread-test.c4
3 files changed, 11 insertions, 3 deletions
diff --git a/src/pulsecore/thread-posix.c b/src/pulsecore/thread-posix.c
index 6ca46d70..4c12ec93 100644
--- a/src/pulsecore/thread-posix.c
+++ b/src/pulsecore/thread-posix.c
@@ -25,6 +25,7 @@
#include <assert.h>
#include <pthread.h>
+#include <sched.h>
#include <atomic_ops.h>
@@ -116,6 +117,14 @@ pa_thread* pa_thread_self(void) {
return pa_tls_get(thread_tls);
}
+void pa_thread_yield(void) {
+#ifdef HAVE_PTHREAD_YIELD
+ pthread_yield();
+#else
+ sched_yield();
+#endif
+}
+
pa_tls* pa_tls_new(pa_free_cb_t free_cb) {
pa_tls *t;
diff --git a/src/pulsecore/thread.h b/src/pulsecore/thread.h
index 978e9927..9b99c8c2 100644
--- a/src/pulsecore/thread.h
+++ b/src/pulsecore/thread.h
@@ -33,6 +33,7 @@ void pa_thread_free(pa_thread *t);
int pa_thread_join(pa_thread *t);
int pa_thread_is_running(pa_thread *t);
pa_thread *pa_thread_self(void);
+void pa_thread_yield(void);
typedef struct pa_tls pa_tls;
diff --git a/src/tests/thread-test.c b/src/tests/thread-test.c
index a93ac1e4..120d2554 100644
--- a/src/tests/thread-test.c
+++ b/src/tests/thread-test.c
@@ -23,8 +23,6 @@
#include <config.h>
#endif
-#include <sched.h>
-
#include <pulsecore/thread.h>
#include <pulsecore/mutex.h>
#include <pulsecore/log.h>
@@ -73,7 +71,7 @@ static void thread_func(void *data) {
/* Spin! */
for (n = 0; n < k; n++)
- sched_yield();
+ pa_thread_yield();
pa_mutex_lock(mutex);
}