src/modules/module-zeroconf-publish.c | 18 +++++++++++++++--- src/pulse/mainloop-api.h | 4 +++- 2 files changed, 18 insertions(+), 4 deletions(-)
New commits: commit e1e154c7377779377fa1a36655a10effd693f7b5 Author: Arun Raghavan <arun.ragha...@collabora.co.uk> Date: Mon Jun 17 18:11:08 2013 +0530 zeroconf: Fix pa_mainloop_api_once usage We need the mainloop lock to be taken around pa_mainloop_api_once() to prevent an assert due to the defer event creation and setting of the destroy callback not being performed atomically. diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c index f96d4ce..b76a215 100644 --- a/src/modules/module-zeroconf-publish.c +++ b/src/modules/module-zeroconf-publish.c @@ -456,8 +456,11 @@ static pa_hook_result_t device_new_or_changed_cb(pa_core *c, pa_object *o, struc pa_assert(c); pa_object_assert_ref(o); - if (!shall_ignore(o)) + if (!shall_ignore(o)) { + pa_threaded_mainloop_lock(u->mainloop); pa_mainloop_api_once(u->api, publish_service, get_service(u, o)); + pa_threaded_mainloop_unlock(u->mainloop); + } return PA_HOOK_OK; } @@ -575,12 +578,18 @@ static int publish_all_services(struct userdata *u) { pa_log_debug("Publishing services in Zeroconf"); for (sink = PA_SINK(pa_idxset_first(u->core->sinks, &idx)); sink; sink = PA_SINK(pa_idxset_next(u->core->sinks, &idx))) - if (!shall_ignore(PA_OBJECT(sink))) + if (!shall_ignore(PA_OBJECT(sink))) { + pa_threaded_mainloop_lock(u->mainloop); pa_mainloop_api_once(u->api, publish_service, get_service(u, PA_OBJECT(sink))); + pa_threaded_mainloop_unlock(u->mainloop); + } for (source = PA_SOURCE(pa_idxset_first(u->core->sources, &idx)); source; source = PA_SOURCE(pa_idxset_next(u->core->sources, &idx))) - if (!shall_ignore(PA_OBJECT(source))) + if (!shall_ignore(PA_OBJECT(source))) { + pa_threaded_mainloop_lock(u->mainloop); pa_mainloop_api_once(u->api, publish_service, get_service(u, PA_OBJECT(source))); + pa_threaded_mainloop_unlock(u->mainloop); + } if (publish_main_service(u) < 0) goto fail; @@ -755,7 +764,10 @@ int pa__init(pa_module*m) { pa_threaded_mainloop_set_name(u->mainloop, "avahi-ml"); pa_threaded_mainloop_start(u->mainloop); + + pa_threaded_mainloop_lock(u->mainloop); pa_mainloop_api_once(u->api, create_client, u); + pa_threaded_mainloop_unlock(u->mainloop); pa_modargs_free(ma); commit 9a0dd113429909ca998bc6970ae0c50e5aa138b0 Author: Arun Raghavan <arun.ragha...@collabora.co.uk> Date: Mon Jun 17 18:07:42 2013 +0530 mainloop: Document need for mainloop lock around pa_mainloop_api_once This needs us to expose a bit of implementation detail, but this seems to be the cleanest way without an API change. The specific problem is that pa_mainloop_api_once() needs to first create a defer event and then set its destroy callback. If the defer event is completed before the callback is set, an assert will be trigerred. diff --git a/src/pulse/mainloop-api.h b/src/pulse/mainloop-api.h index 018ae19..e754960 100644 --- a/src/pulse/mainloop-api.h +++ b/src/pulse/mainloop-api.h @@ -114,7 +114,9 @@ struct pa_mainloop_api { void (*quit)(pa_mainloop_api*a, int retval); }; -/** Run the specified callback function once from the main loop using an anonymous defer event. */ +/** Run the specified callback function once from the main loop using an anonymous defer event. Note that this performs + * multiple mainloop operations non-atomically. If, for example, you are using a \pa_threaded_mainloop, you will need to + * take the mainloop lock before this call. */ void pa_mainloop_api_once(pa_mainloop_api*m, void (*callback)(pa_mainloop_api*m, void *userdata), void *userdata); PA_C_DECL_END _______________________________________________ pulseaudio-commits mailing list pulseaudio-commits@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/pulseaudio-commits