obs-scripting: Make callback "removed" variable atomic

Makes the callback variable "removed" atomic, and on script unload,
first sets all callbacks to removed before actually unloading the script
out of a safety precaution. (See note at the bottom for further details)

This minimizes the possibility of a race condition where the script
callback could be called while those callbacks were being removed.

Big note for this change, this change should eventually be replaced with
a reference counting ownership method where script callbacks can hold a
reference and share ownership of the script if it's still alive while
the script callback is being called. That way the script callbacks can
safely execute. May require a fair amount of reworking of the script
object.
This commit is contained in:
jp9000
2022-03-01 03:04:37 -08:00
parent fbcb053cfa
commit 6d3b1998ef
6 changed files with 71 additions and 29 deletions
+2 -2
View File
@@ -280,7 +280,7 @@ static void frontend_save_callback(obs_data_t *save_data, bool saving,
{
struct python_obs_callback *cb = priv;
if (cb->base.removed) {
if (script_callback_removed(&cb->base)) {
obs_frontend_remove_save_callback(frontend_save_callback, cb);
return;
}
@@ -355,7 +355,7 @@ static void frontend_event_callback(enum obs_frontend_event event, void *priv)
{
struct python_obs_callback *cb = priv;
if (cb->base.removed) {
if (script_callback_removed(&cb->base)) {
obs_frontend_remove_event_callback(frontend_event_callback, cb);
return;
}