summaryrefslogtreecommitdiff
path: root/pipewire
diff options
context:
space:
mode:
authorPekka Paalanen <pekka.paalanen@collabora.com>2019-11-06 12:59:32 +0200
committerDaniel Stone <daniel@fooishbar.org>2019-11-21 16:32:55 +0000
commit6ffbba3ac13bc16d247ea50ef09cb149d892e125 (patch)
treef92bdd36e87929a9cc30b0675cfc84b6775ba099 /pipewire
parent5caef6d355f87af2e7f20372dc8c328faba53148 (diff)
downloadweston-6ffbba3ac13bc16d247ea50ef09cb149d892e125.tar.gz
Use weston_compositor_add_destroy_listener_once() in plugins
This introduces a new convention of checking through the compositor destroy listener if the plugin is already initialized. If the plugin is already initialized, then the plugin entry function succeeds as a no-op. This makes it safe to load the same plugin multiple times in a running compositor. Currently module loading functions return failure if a plugin is already loaded, but that will change in the future. Therefore we need this other method of ensuring we do not double-initialize a plugin which would lead to list corruptions the very least. All plugins are converted to use the new helper, except: - those that do not have a destroy listener already, and - hmi-controller which does the same open-coded as the common code pattern did not fit there. Plugins should always have a compositor destroy listener registered since they very least allocate a struct to hold their data. Hence omissions are highlighted in code. Backends do not need this because weston_compositor_load_backend() already protects against double-init. GL-renderer does not export a standard module init function so cannot be initialized the usual way and therefore is not vulnerable to double-init. Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
Diffstat (limited to 'pipewire')
-rw-r--r--pipewire/pipewire-plugin.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/pipewire/pipewire-plugin.c b/pipewire/pipewire-plugin.c
index 1eb5de57..552f5745 100644
--- a/pipewire/pipewire-plugin.c
+++ b/pipewire/pipewire-plugin.c
@@ -797,6 +797,13 @@ weston_module_init(struct weston_compositor *compositor)
if (!pipewire)
return -1;
+ if (!weston_compositor_add_destroy_listener_once(compositor,
+ &pipewire->destroy_listener,
+ weston_pipewire_destroy)) {
+ free(pipewire);
+ return 0;
+ }
+
pipewire->virtual_output_api = api;
pipewire->compositor = compositor;
wl_list_init(&pipewire->output_list);
@@ -821,11 +828,10 @@ weston_module_init(struct weston_compositor *compositor)
"Debug messages from pipewire plugin\n",
NULL, NULL, NULL);
- pipewire->destroy_listener.notify = weston_pipewire_destroy;
- wl_signal_add(&compositor->destroy_signal, &pipewire->destroy_listener);
return 0;
failed:
+ wl_list_remove(&pipewire->destroy_listener.link);
free(pipewire);
return -1;
}