libobs: Fix destruction order for destruction task queue

Destruction of the task queue should probably happen after the audio and
video threads have been destroyed and all audio/video processing has
stopped.
master
jp9000 2021-12-21 11:46:42 -08:00
parent a593fe6755
commit 49f9a055dc
3 changed files with 12 additions and 13 deletions

View File

@ -364,8 +364,6 @@ struct obs_core_data {
DARRAY(struct draw_callback) draw_callbacks;
DARRAY(struct tick_callback) tick_callbacks;
os_task_queue_t *destruction_task_thread;
struct obs_view main_view;
long long unnamed_index;
@ -439,6 +437,8 @@ struct obs_core {
struct obs_core_data data;
struct obs_core_hotkeys hotkeys;
os_task_queue_t *destruction_task_thread;
obs_task_handler_t ui_task_handler;
};

View File

@ -635,7 +635,7 @@ void obs_source_destroy(struct obs_source *source)
obs_context_data_remove(&source->context);
/* defer source destroy */
os_task_queue_queue_task(obs->data.destruction_task_thread,
os_task_queue_queue_task(obs->destruction_task_thread,
(os_task_t)obs_source_destroy_defer, source);
}

View File

@ -649,10 +649,6 @@ static bool obs_init_data(void)
if (pthread_mutex_init_recursive(&obs->data.draw_callbacks_mutex) != 0)
goto fail;
data->destruction_task_thread = os_task_queue_create();
if (!data->destruction_task_thread)
goto fail;
if (!obs_view_init(&data->main_view))
goto fail;
@ -710,7 +706,6 @@ static void obs_free_data(void)
pthread_mutex_destroy(&data->encoders_mutex);
pthread_mutex_destroy(&data->services_mutex);
pthread_mutex_destroy(&data->draw_callbacks_mutex);
os_task_queue_destroy(data->destruction_task_thread);
da_free(data->draw_callbacks);
da_free(data->tick_callbacks);
obs_data_release(data->private_data);
@ -875,6 +870,10 @@ static bool obs_init(const char *locale, const char *module_config_path,
if (!obs_init_hotkeys())
return false;
obs->destruction_task_thread = os_task_queue_create();
if (!obs->destruction_task_thread)
return false;
if (module_config_path)
obs->module_config_path = bstrdup(module_config_path);
obs->locale = bstrdup(locale);
@ -1047,6 +1046,7 @@ void obs_shutdown(void)
obs_free_data();
obs_free_audio();
obs_free_video();
os_task_queue_destroy(obs->destruction_task_thread);
obs_free_hotkeys();
obs_free_graphics();
proc_handler_destroy(obs->procs);
@ -2563,7 +2563,7 @@ bool obs_in_task_thread(enum obs_task_type type)
else if (type == OBS_TASK_UI)
return is_ui_thread;
else if (type == OBS_TASK_DESTROY)
return os_task_queue_inside(obs->data.destruction_task_thread);
return os_task_queue_inside(obs->destruction_task_thread);
assert(false);
return false;
@ -2612,9 +2612,8 @@ void obs_queue_task(enum obs_task_type type, obs_task_t task, void *param,
} else if (type == OBS_TASK_DESTROY) {
os_task_t os_task = (os_task_t)task;
os_task_queue_queue_task(
obs->data.destruction_task_thread, os_task,
param);
os_task_queue_queue_task(obs->destruction_task_thread,
os_task, param);
}
}
}
@ -2635,7 +2634,7 @@ bool obs_wait_for_destroy_queue(void)
os_event_destroy(info.event);
/* wait for destroy task queue */
return os_task_queue_wait(obs->data.destruction_task_thread);
return os_task_queue_wait(obs->destruction_task_thread);
}
static void set_ui_thread(void *unused)