diff --git a/pipewire-jack/src/pipewire-jack.c b/pipewire-jack/src/pipewire-jack.c index 9d7ce6acb..da7a82a94 100644 --- a/pipewire-jack/src/pipewire-jack.c +++ b/pipewire-jack/src/pipewire-jack.c @@ -3182,31 +3182,27 @@ static struct spa_thread *impl_create(void *object, void *(*start)(void*), void *arg) { struct client *c = (struct client *) object; - struct spa_thread *thr; - int res = 0; + struct spa_dict_item *items; + struct spa_dict copy; + char creator_ptr[64]; pw_log_info("create thread"); if (globals.creator != NULL) { - pthread_t pt; - pthread_attr_t *attr = NULL, attributes; + uint32_t i, n_items = props ? props->n_items : 0; - attr = pw_thread_fill_attr(props, &attributes); + items = alloca((n_items) + 1 * sizeof(*items)); - res = -globals.creator(&pt, attr, start, arg); - if (attr) - pthread_attr_destroy(attr); - if (res != 0) - goto error; - thr = (struct spa_thread*)pt; - } else { - thr = spa_thread_utils_create(c->context.old_thread_utils, props, start, arg); + for (i = 0; i < n_items; i++) + items[i] = props->items[i]; + + snprintf(creator_ptr, sizeof(creator_ptr), "pointer:%p", globals.creator); + items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_THREAD_CREATOR, + creator_ptr); + + copy = SPA_DICT_INIT(items, n_items); + props = © } - return thr; -error: - pw_log_warn("create RT thread failed: %s", strerror(res)); - errno = -res; - return NULL; - + return spa_thread_utils_create(c->context.old_thread_utils, props, start, arg); } static int impl_join(void *object, diff --git a/spa/include/spa/support/thread.h b/spa/include/spa/support/thread.h index 23d443774..f691e3a30 100644 --- a/spa/include/spa/support/thread.h +++ b/spa/include/spa/support/thread.h @@ -118,6 +118,7 @@ static inline int spa_thread_utils_drop_rt(struct spa_thread_utils *o, #define SPA_KEY_THREAD_NAME "thread.name" /* the thread name */ #define SPA_KEY_THREAD_STACK_SIZE "thread.stack-size" /* the stack size of the thread */ #define SPA_KEY_THREAD_AFFINITY "thread.affinity" /* array of CPUs for this thread */ +#define SPA_KEY_THREAD_CREATOR "thread.creator" /* platform specific thread creator function */ /** * \} diff --git a/src/pipewire/thread.c b/src/pipewire/thread.c index cf656fb9e..4fda54286 100644 --- a/src/pipewire/thread.c +++ b/src/pipewire/thread.c @@ -90,10 +90,16 @@ static struct spa_thread *impl_create(void *object, pthread_attr_t *attr = NULL, attributes; const char *str; int err; + int (*create_func)(pthread_t *, const pthread_attr_t *attr, void *(*start)(void*), void *) = NULL; attr = pw_thread_fill_attr(props, &attributes); - err = pthread_create(&pt, attr, start, arg); + if (props == NULL || + (str = spa_dict_lookup(props, SPA_KEY_THREAD_CREATOR)) == NULL || + sscanf(str, "pointer:%p", &create_func) != 1) + create_func = pthread_create; + + err = create_func(&pt, attr, start, arg); if (attr) pthread_attr_destroy(attr);