From e2d6545e776ccbadff5c9daeb15f20f76bd8b7d0 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 2 Jul 2021 11:39:44 +0200 Subject: [PATCH] jack: client_thread_id should return the data thread Add a function in data-loop to get the natvive thread and use that in client_thread_id() so that it returns the pthread of the data thread instead of the caller thread. --- pipewire-jack/src/pipewire-jack.c | 10 +++++++++- src/pipewire/data-loop.c | 12 ++++++++++++ src/pipewire/data-loop.h | 3 +++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pipewire-jack/src/pipewire-jack.c b/pipewire-jack/src/pipewire-jack.c index 6f33c0c94..3023381b9 100644 --- a/pipewire-jack/src/pipewire-jack.c +++ b/pipewire-jack/src/pipewire-jack.c @@ -3239,7 +3239,15 @@ int jack_get_client_pid (const char *name) SPA_EXPORT jack_native_thread_t jack_client_thread_id (jack_client_t *client) { - return pthread_self(); + struct client *c = (struct client *) client; + void *thr; + + spa_return_val_if_fail(c != NULL, -EINVAL); + + thr = pw_data_loop_get_thread(c->loop); + if (thr == NULL) + return pthread_self(); + return *(pthread_t*)thr; } SPA_EXPORT diff --git a/src/pipewire/data-loop.c b/src/pipewire/data-loop.c index 44557247a..b3aea0699 100644 --- a/src/pipewire/data-loop.c +++ b/src/pipewire/data-loop.c @@ -253,6 +253,18 @@ bool pw_data_loop_in_thread(struct pw_data_loop * loop) return pthread_equal(loop->thread, pthread_self()); } +/** Get the thread object. + * \param loop the data loop to get the thread of + * \return the thread object or NULL when the thread is not running + * + * On posix based systems this returns a pthread_t * + */ +SPA_EXPORT +void *pw_data_loop_get_thread(struct pw_data_loop * loop) +{ + return loop->running ? &loop->thread : NULL; +} + SPA_EXPORT int pw_data_loop_invoke(struct pw_data_loop *loop, spa_invoke_func_t func, uint32_t seq, const void *data, size_t size, diff --git a/src/pipewire/data-loop.h b/src/pipewire/data-loop.h index b34ee3a36..cb763ce7f 100644 --- a/src/pipewire/data-loop.h +++ b/src/pipewire/data-loop.h @@ -87,6 +87,9 @@ int pw_data_loop_stop(struct pw_data_loop *loop); /** Check if the current thread is the processing thread */ bool pw_data_loop_in_thread(struct pw_data_loop *loop); +/** Get the thread object */ +void *pw_data_loop_get_thread(struct pw_data_loop *loop); + /** invoke func in the context of the thread or in the caller thread when * the loop is not running. Since 0.3.3 */ int pw_data_loop_invoke(struct pw_data_loop *loop,