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>
This commit is contained in:
committed by
Daniel Stone
parent
5caef6d355
commit
6ffbba3ac1
@@ -1981,6 +1981,10 @@ wet_module_init(struct weston_compositor *ec,
|
||||
struct hmi_controller *hmi_ctrl = NULL;
|
||||
struct wl_event_loop *loop = NULL;
|
||||
|
||||
/* ad hoc weston_compositor_add_destroy_listener_once() */
|
||||
if (wl_signal_get(&ec->destroy_signal, hmi_controller_destroy))
|
||||
return 0;
|
||||
|
||||
hmi_ctrl = hmi_controller_create(ec);
|
||||
if (hmi_ctrl == NULL)
|
||||
return -1;
|
||||
|
||||
@@ -623,10 +623,14 @@ wet_shell_init(struct weston_compositor *compositor,
|
||||
if (shell == NULL)
|
||||
return -1;
|
||||
|
||||
init_ivi_shell(compositor, shell);
|
||||
if (!weston_compositor_add_destroy_listener_once(compositor,
|
||||
&shell->destroy_listener,
|
||||
shell_destroy)) {
|
||||
free(shell);
|
||||
return 0;
|
||||
}
|
||||
|
||||
shell->destroy_listener.notify = shell_destroy;
|
||||
wl_signal_add(&compositor->destroy_signal, &shell->destroy_listener);
|
||||
init_ivi_shell(compositor, shell);
|
||||
|
||||
shell->wake_listener.notify = wake_handler;
|
||||
wl_signal_add(&compositor->wake_signal, &shell->wake_listener);
|
||||
|
||||
Reference in New Issue
Block a user