]> code.delx.au - pulseaudio/commitdiff
add new API pa_threaded_mainloop_in_thread(), update test case for it
authorLennart Poettering <lennart@poettering.net>
Mon, 10 Sep 2007 21:58:01 +0000 (21:58 +0000)
committerLennart Poettering <lennart@poettering.net>
Mon, 10 Sep 2007 21:58:01 +0000 (21:58 +0000)
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1795 fefdeb5f-60dc-0310-8127-8f9354f1896f

src/pulse/thread-mainloop.c
src/pulse/thread-mainloop.h
src/tests/thread-mainloop-test.c

index 0ed54837055f0038740a10739248d01102bb59f0..29769e2b3d93bc6363f3f0e654b20eecbd4eaa52 100644 (file)
@@ -223,3 +223,9 @@ pa_mainloop_api* pa_threaded_mainloop_get_api(pa_threaded_mainloop*m) {
 
     return pa_mainloop_get_api(m->real_mainloop);
 }
+
+int pa_threaded_mainloop_in_thread(pa_threaded_mainloop *m) {
+    pa_assert(m);
+
+    return m->thread && pa_thread_self() == m->thread;
+}
index b78c1583f3913ffeea274180988c58dc1cb9577c..ea08f72ac7b3ece3c2f113eb4baeb73dc8c314c7 100644 (file)
@@ -297,6 +297,9 @@ int pa_threaded_mainloop_get_retval(pa_threaded_mainloop *m);
 /** Return the abstract main loop abstraction layer vtable for this main loop. */
 pa_mainloop_api* pa_threaded_mainloop_get_api(pa_threaded_mainloop*m);
 
+/** Returns non-zero when called from withing the event loop thread. \since 0.9.7 */
+int pa_threaded_mainloop_in_thread(pa_threaded_mainloop *m);
+
 PA_C_DECL_END
 
 #endif
index 9d0e5de16e68b379b7264c4f3cad3aa570ca7174..be1f1ec214db7dd506f9fc99e25dc057fcf15002 100644 (file)
 #include <config.h>
 #endif
 
-#include <assert.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdio.h>
 
 #include <pulse/timeval.h>
 #include <pulse/util.h>
+#include <pulse/thread-mainloop.h>
 
 #include <pulsecore/gccmacro.h>
-#include <pulse/thread-mainloop.h>
+#include <pulsecore/macro.h>
 
 static void tcb(pa_mainloop_api*a, pa_time_event *e, const struct timeval *tv, void *userdata) {
+    pa_assert_se(pa_threaded_mainloop_in_thread(userdata));
     fprintf(stderr, "TIME EVENT START\n");
     pa_threaded_mainloop_signal(userdata, 1);
     fprintf(stderr, "TIME EVENT END\n");
@@ -45,15 +46,15 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) {
     pa_threaded_mainloop *m;
     struct timeval tv;
 
-    m = pa_threaded_mainloop_new();
-    assert(m);
-    a = pa_threaded_mainloop_get_api(m);
-    assert(a);
+    pa_assert_se(m = pa_threaded_mainloop_new());
+    pa_assert_se(a = pa_threaded_mainloop_get_api(m));
 
     pa_threaded_mainloop_start(m);
 
     pa_threaded_mainloop_lock(m);
 
+    pa_assert_se(!pa_threaded_mainloop_in_thread(m));
+    
     pa_gettimeofday(&tv);
     tv.tv_sec += 5;
     a->time_new(a, &tv, tcb, m);