Merge pull request #5180 from jpark37/leaks
Fix a bunch of pthread leaks
This commit is contained in:
commit
9b6cc99828
@ -641,11 +641,7 @@ static int obs_lua_register_source(lua_State *script)
|
||||
if (!existing) {
|
||||
ls.data = current_lua_script;
|
||||
|
||||
pthread_mutexattr_t mutexattr;
|
||||
pthread_mutexattr_init(&mutexattr);
|
||||
pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE);
|
||||
pthread_mutex_init(&ls.definition_mutex, &mutexattr);
|
||||
pthread_mutexattr_destroy(&mutexattr);
|
||||
pthread_mutex_init_recursive(&ls.definition_mutex);
|
||||
|
||||
info.type_data = bmemdup(&ls, sizeof(ls));
|
||||
info.free_type_data = obs_lua_source_free_type_data;
|
||||
|
17
deps/obs-scripting/obs-scripting-lua.c
vendored
17
deps/obs-scripting/obs-scripting-lua.c
vendored
@ -55,10 +55,10 @@ package.path = package.path .. \";\" .. script_path() .. \"/?.lua\"\n";
|
||||
|
||||
static char *startup_script = NULL;
|
||||
|
||||
static pthread_mutex_t tick_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t tick_mutex;
|
||||
static struct obs_lua_script *first_tick_script = NULL;
|
||||
|
||||
pthread_mutex_t lua_source_def_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_mutex_t lua_source_def_mutex;
|
||||
|
||||
#define ls_get_libobs_obj(type, lua_index, obs_obj) \
|
||||
ls_get_libobs_obj_(script, #type " *", lua_index, obs_obj, NULL, \
|
||||
@ -242,7 +242,7 @@ struct lua_obs_timer {
|
||||
uint64_t interval;
|
||||
};
|
||||
|
||||
static pthread_mutex_t timer_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t timer_mutex;
|
||||
static struct lua_obs_timer *first_timer = NULL;
|
||||
|
||||
static inline void lua_obs_timer_init(struct lua_obs_timer *timer)
|
||||
@ -1119,12 +1119,9 @@ obs_script_t *obs_lua_script_create(const char *path, obs_data_t *settings)
|
||||
data->base.type = OBS_SCRIPT_LANG_LUA;
|
||||
data->tick = LUA_REFNIL;
|
||||
|
||||
pthread_mutexattr_t attr;
|
||||
pthread_mutexattr_init(&attr);
|
||||
pthread_mutex_init_value(&data->mutex);
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
|
||||
if (pthread_mutex_init(&data->mutex, &attr) != 0) {
|
||||
if (pthread_mutex_init_recursive(&data->mutex) != 0) {
|
||||
bfree(data);
|
||||
return NULL;
|
||||
}
|
||||
@ -1300,12 +1297,8 @@ void obs_lua_load(void)
|
||||
struct dstr dep_paths = {0};
|
||||
struct dstr tmp = {0};
|
||||
|
||||
pthread_mutexattr_t attr;
|
||||
pthread_mutexattr_init(&attr);
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
|
||||
pthread_mutex_init(&tick_mutex, NULL);
|
||||
pthread_mutex_init(&timer_mutex, &attr);
|
||||
pthread_mutex_init_recursive(&timer_mutex);
|
||||
pthread_mutex_init(&lua_source_def_mutex, NULL);
|
||||
|
||||
/* ---------------------------------------------- */
|
||||
|
20
deps/obs-scripting/obs-scripting-python.c
vendored
20
deps/obs-scripting/obs-scripting-python.c
vendored
@ -53,8 +53,9 @@ static wchar_t home_path[1024] = {0};
|
||||
|
||||
DARRAY(char *) python_paths;
|
||||
static bool python_loaded = false;
|
||||
static bool mutexes_loaded = false;
|
||||
|
||||
static pthread_mutex_t tick_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t tick_mutex;
|
||||
static struct obs_python_script *first_tick_script = NULL;
|
||||
|
||||
static PyObject *py_obspython = NULL;
|
||||
@ -378,7 +379,7 @@ struct python_obs_timer {
|
||||
uint64_t interval;
|
||||
};
|
||||
|
||||
static pthread_mutex_t timer_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t timer_mutex;
|
||||
static struct python_obs_timer *first_timer = NULL;
|
||||
|
||||
static inline void python_obs_timer_init(struct python_obs_timer *timer)
|
||||
@ -1570,12 +1571,10 @@ void obs_python_load(void)
|
||||
{
|
||||
da_init(python_paths);
|
||||
|
||||
pthread_mutexattr_t attr;
|
||||
pthread_mutexattr_init(&attr);
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
|
||||
pthread_mutex_init(&tick_mutex, NULL);
|
||||
pthread_mutex_init(&timer_mutex, &attr);
|
||||
pthread_mutex_init_recursive(&timer_mutex);
|
||||
|
||||
mutexes_loaded = true;
|
||||
}
|
||||
|
||||
extern void add_python_frontend_funcs(PyObject *module);
|
||||
@ -1702,6 +1701,11 @@ out:
|
||||
|
||||
void obs_python_unload(void)
|
||||
{
|
||||
if (mutexes_loaded) {
|
||||
pthread_mutex_destroy(&tick_mutex);
|
||||
pthread_mutex_destroy(&timer_mutex);
|
||||
}
|
||||
|
||||
if (!python_loaded_at_all)
|
||||
return;
|
||||
|
||||
@ -1720,8 +1724,6 @@ void obs_python_unload(void)
|
||||
bfree(python_paths.array[i]);
|
||||
da_free(python_paths);
|
||||
|
||||
pthread_mutex_destroy(&tick_mutex);
|
||||
pthread_mutex_destroy(&timer_mutex);
|
||||
dstr_free(&cur_py_log_chunk);
|
||||
|
||||
python_loaded_at_all = false;
|
||||
|
@ -408,7 +408,8 @@ set(libobs_util_HEADERS
|
||||
util/platform.h
|
||||
util/profiler.h
|
||||
util/profiler.hpp
|
||||
util/bitstream.h)
|
||||
util/bitstream.h
|
||||
util/util.hpp)
|
||||
|
||||
set(libobs_libobs_SOURCES
|
||||
${libobs_PLATFORM_SOURCES}
|
||||
|
@ -38,22 +38,13 @@ struct signal_info {
|
||||
|
||||
static inline struct signal_info *signal_info_create(struct decl_info *info)
|
||||
{
|
||||
pthread_mutexattr_t attr;
|
||||
struct signal_info *si;
|
||||
|
||||
if (pthread_mutexattr_init(&attr) != 0)
|
||||
return NULL;
|
||||
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0)
|
||||
return NULL;
|
||||
|
||||
si = bmalloc(sizeof(struct signal_info));
|
||||
|
||||
struct signal_info *si = bmalloc(sizeof(struct signal_info));
|
||||
si->func = *info;
|
||||
si->next = NULL;
|
||||
si->signalling = false;
|
||||
da_init(si->callbacks);
|
||||
|
||||
if (pthread_mutex_init(&si->mutex, &attr) != 0) {
|
||||
if (pthread_mutex_init_recursive(&si->mutex) != 0) {
|
||||
blog(LOG_ERROR, "Could not create signal");
|
||||
|
||||
decl_info_free(&si->func);
|
||||
@ -132,18 +123,13 @@ signal_handler_t *signal_handler_create(void)
|
||||
handler->first = NULL;
|
||||
handler->refs = 1;
|
||||
|
||||
pthread_mutexattr_t attr;
|
||||
if (pthread_mutexattr_init(&attr) != 0)
|
||||
return NULL;
|
||||
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0)
|
||||
return NULL;
|
||||
|
||||
if (pthread_mutex_init(&handler->mutex, NULL) != 0) {
|
||||
blog(LOG_ERROR, "Couldn't create signal handler mutex!");
|
||||
bfree(handler);
|
||||
return NULL;
|
||||
}
|
||||
if (pthread_mutex_init(&handler->global_callbacks_mutex, &attr) != 0) {
|
||||
if (pthread_mutex_init_recursive(&handler->global_callbacks_mutex) !=
|
||||
0) {
|
||||
blog(LOG_ERROR, "Couldn't create signal handler global "
|
||||
"callbacks mutex!");
|
||||
pthread_mutex_destroy(&handler->mutex);
|
||||
|
@ -354,7 +354,6 @@ static inline bool valid_audio_params(const struct audio_output_info *info)
|
||||
int audio_output_open(audio_t **audio, struct audio_output_info *info)
|
||||
{
|
||||
struct audio_output *out;
|
||||
pthread_mutexattr_t attr;
|
||||
bool planar = is_audio_planar(info->format);
|
||||
|
||||
if (!valid_audio_params(info))
|
||||
@ -362,7 +361,7 @@ int audio_output_open(audio_t **audio, struct audio_output_info *info)
|
||||
|
||||
out = bzalloc(sizeof(struct audio_output));
|
||||
if (!out)
|
||||
goto fail;
|
||||
goto fail0;
|
||||
|
||||
memcpy(&out->info, info, sizeof(struct audio_output_info));
|
||||
out->channels = get_audio_channels(info->speakers);
|
||||
@ -372,22 +371,22 @@ int audio_output_open(audio_t **audio, struct audio_output_info *info)
|
||||
out->block_size = (planar ? 1 : out->channels) *
|
||||
get_audio_bytes_per_channel(info->format);
|
||||
|
||||
if (pthread_mutexattr_init(&attr) != 0)
|
||||
goto fail;
|
||||
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0)
|
||||
goto fail;
|
||||
if (pthread_mutex_init(&out->input_mutex, &attr) != 0)
|
||||
goto fail;
|
||||
if (pthread_mutex_init_recursive(&out->input_mutex) != 0)
|
||||
goto fail0;
|
||||
if (os_event_init(&out->stop_event, OS_EVENT_TYPE_MANUAL) != 0)
|
||||
goto fail;
|
||||
goto fail1;
|
||||
if (pthread_create(&out->thread, NULL, audio_thread, out) != 0)
|
||||
goto fail;
|
||||
goto fail2;
|
||||
|
||||
out->initialized = true;
|
||||
*audio = out;
|
||||
return AUDIO_OUTPUT_SUCCESS;
|
||||
|
||||
fail:
|
||||
fail2:
|
||||
os_event_destroy(out->stop_event);
|
||||
fail1:
|
||||
pthread_mutex_destroy(&out->input_mutex);
|
||||
fail0:
|
||||
audio_output_close(out);
|
||||
return AUDIO_OUTPUT_FAIL;
|
||||
}
|
||||
@ -402,6 +401,8 @@ void audio_output_close(audio_t *audio)
|
||||
if (audio->initialized) {
|
||||
os_event_signal(audio->stop_event);
|
||||
pthread_join(audio->thread, &thread_ret);
|
||||
os_event_destroy(audio->stop_event);
|
||||
pthread_mutex_destroy(&audio->input_mutex);
|
||||
}
|
||||
|
||||
for (size_t mix_idx = 0; mix_idx < MAX_AUDIO_MIXES; mix_idx++) {
|
||||
@ -412,8 +413,6 @@ void audio_output_close(audio_t *audio)
|
||||
|
||||
da_free(mix->inputs);
|
||||
}
|
||||
|
||||
os_event_destroy(audio->stop_event);
|
||||
bfree(audio);
|
||||
}
|
||||
|
||||
|
@ -225,32 +225,27 @@ static inline void init_cache(struct video_output *video)
|
||||
int video_output_open(video_t **video, struct video_output_info *info)
|
||||
{
|
||||
struct video_output *out;
|
||||
pthread_mutexattr_t attr;
|
||||
|
||||
if (!valid_video_params(info))
|
||||
return VIDEO_OUTPUT_INVALIDPARAM;
|
||||
|
||||
out = bzalloc(sizeof(struct video_output));
|
||||
if (!out)
|
||||
goto fail;
|
||||
goto fail0;
|
||||
|
||||
memcpy(&out->info, info, sizeof(struct video_output_info));
|
||||
out->frame_time =
|
||||
util_mul_div64(1000000000ULL, info->fps_den, info->fps_num);
|
||||
out->initialized = false;
|
||||
|
||||
if (pthread_mutexattr_init(&attr) != 0)
|
||||
goto fail;
|
||||
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0)
|
||||
goto fail;
|
||||
if (pthread_mutex_init(&out->data_mutex, &attr) != 0)
|
||||
goto fail;
|
||||
if (pthread_mutex_init(&out->input_mutex, &attr) != 0)
|
||||
goto fail;
|
||||
if (pthread_mutex_init_recursive(&out->data_mutex) != 0)
|
||||
goto fail0;
|
||||
if (pthread_mutex_init_recursive(&out->input_mutex) != 0)
|
||||
goto fail1;
|
||||
if (os_sem_init(&out->update_semaphore, 0) != 0)
|
||||
goto fail;
|
||||
goto fail2;
|
||||
if (pthread_create(&out->thread, NULL, video_thread, out) != 0)
|
||||
goto fail;
|
||||
goto fail3;
|
||||
|
||||
init_cache(out);
|
||||
|
||||
@ -258,7 +253,13 @@ int video_output_open(video_t **video, struct video_output_info *info)
|
||||
*video = out;
|
||||
return VIDEO_OUTPUT_SUCCESS;
|
||||
|
||||
fail:
|
||||
fail3:
|
||||
os_sem_destroy(out->update_semaphore);
|
||||
fail2:
|
||||
pthread_mutex_destroy(&out->input_mutex);
|
||||
fail1:
|
||||
pthread_mutex_destroy(&out->data_mutex);
|
||||
fail0:
|
||||
video_output_close(out);
|
||||
return VIDEO_OUTPUT_FAIL;
|
||||
}
|
||||
@ -277,9 +278,6 @@ void video_output_close(video_t *video)
|
||||
for (size_t i = 0; i < video->info.cache_size; i++)
|
||||
video_frame_free((struct video_frame *)&video->cache[i]);
|
||||
|
||||
os_sem_destroy(video->update_semaphore);
|
||||
pthread_mutex_destroy(&video->data_mutex);
|
||||
pthread_mutex_destroy(&video->input_mutex);
|
||||
bfree(video);
|
||||
}
|
||||
|
||||
@ -510,6 +508,9 @@ void video_output_stop(video_t *video)
|
||||
video->stop = true;
|
||||
os_sem_post(video->update_semaphore);
|
||||
pthread_join(video->thread, &thread_ret);
|
||||
os_sem_destroy(video->update_semaphore);
|
||||
pthread_mutex_destroy(&video->data_mutex);
|
||||
pthread_mutex_destroy(&video->input_mutex);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,23 +44,17 @@ const char *obs_encoder_get_display_name(const char *id)
|
||||
static bool init_encoder(struct obs_encoder *encoder, const char *name,
|
||||
obs_data_t *settings, obs_data_t *hotkey_data)
|
||||
{
|
||||
pthread_mutexattr_t attr;
|
||||
|
||||
pthread_mutex_init_value(&encoder->init_mutex);
|
||||
pthread_mutex_init_value(&encoder->callbacks_mutex);
|
||||
pthread_mutex_init_value(&encoder->outputs_mutex);
|
||||
pthread_mutex_init_value(&encoder->pause.mutex);
|
||||
|
||||
if (pthread_mutexattr_init(&attr) != 0)
|
||||
return false;
|
||||
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0)
|
||||
return false;
|
||||
if (!obs_context_data_init(&encoder->context, OBS_OBJ_TYPE_ENCODER,
|
||||
settings, name, hotkey_data, false))
|
||||
return false;
|
||||
if (pthread_mutex_init(&encoder->init_mutex, &attr) != 0)
|
||||
if (pthread_mutex_init_recursive(&encoder->init_mutex) != 0)
|
||||
return false;
|
||||
if (pthread_mutex_init(&encoder->callbacks_mutex, &attr) != 0)
|
||||
if (pthread_mutex_init_recursive(&encoder->callbacks_mutex) != 0)
|
||||
return false;
|
||||
if (pthread_mutex_init(&encoder->outputs_mutex, NULL) != 0)
|
||||
return false;
|
||||
|
@ -84,7 +84,6 @@ static const char *group_getname(void *unused)
|
||||
|
||||
static void *scene_create(obs_data_t *settings, struct obs_source *source)
|
||||
{
|
||||
pthread_mutexattr_t attr;
|
||||
struct obs_scene *scene = bzalloc(sizeof(struct obs_scene));
|
||||
scene->source = source;
|
||||
|
||||
@ -98,16 +97,12 @@ static void *scene_create(obs_data_t *settings, struct obs_source *source)
|
||||
signal_handler_add_array(obs_source_get_signal_handler(source),
|
||||
obs_scene_signals);
|
||||
|
||||
if (pthread_mutexattr_init(&attr) != 0)
|
||||
goto fail;
|
||||
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0)
|
||||
goto fail;
|
||||
if (pthread_mutex_init(&scene->audio_mutex, &attr) != 0) {
|
||||
if (pthread_mutex_init_recursive(&scene->audio_mutex) != 0) {
|
||||
blog(LOG_ERROR, "scene_create: Couldn't initialize audio "
|
||||
"mutex");
|
||||
goto fail;
|
||||
}
|
||||
if (pthread_mutex_init(&scene->video_mutex, &attr) != 0) {
|
||||
if (pthread_mutex_init_recursive(&scene->video_mutex) != 0) {
|
||||
blog(LOG_ERROR, "scene_create: Couldn't initialize video "
|
||||
"mutex");
|
||||
goto fail;
|
||||
@ -117,7 +112,6 @@ static void *scene_create(obs_data_t *settings, struct obs_source *source)
|
||||
return scene;
|
||||
|
||||
fail:
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
bfree(scene);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -172,8 +172,6 @@ extern char *find_libobs_data_file(const char *file);
|
||||
/* internal initialization */
|
||||
static bool obs_source_init(struct obs_source *source)
|
||||
{
|
||||
pthread_mutexattr_t attr;
|
||||
|
||||
source->user_volume = 1.0f;
|
||||
source->volume = 1.0f;
|
||||
source->sync_offset = 0;
|
||||
@ -186,11 +184,7 @@ static bool obs_source_init(struct obs_source *source)
|
||||
pthread_mutex_init_value(&source->audio_cb_mutex);
|
||||
pthread_mutex_init_value(&source->caption_cb_mutex);
|
||||
|
||||
if (pthread_mutexattr_init(&attr) != 0)
|
||||
return false;
|
||||
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0)
|
||||
return false;
|
||||
if (pthread_mutex_init(&source->filter_mutex, &attr) != 0)
|
||||
if (pthread_mutex_init_recursive(&source->filter_mutex) != 0)
|
||||
return false;
|
||||
if (pthread_mutex_init(&source->audio_buf_mutex, NULL) != 0)
|
||||
return false;
|
||||
|
41
libobs/obs.c
41
libobs/obs.c
@ -386,7 +386,6 @@ static int obs_init_video(struct obs_video_info *ovi)
|
||||
{
|
||||
struct obs_core_video *video = &obs->video;
|
||||
struct video_output_info vi;
|
||||
pthread_mutexattr_t attr;
|
||||
int errorcode;
|
||||
|
||||
make_video_info(&vi, ovi);
|
||||
@ -420,10 +419,6 @@ static int obs_init_video(struct obs_video_info *ovi)
|
||||
|
||||
gs_leave_context();
|
||||
|
||||
if (pthread_mutexattr_init(&attr) != 0)
|
||||
return OBS_VIDEO_FAIL;
|
||||
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0)
|
||||
return OBS_VIDEO_FAIL;
|
||||
if (pthread_mutex_init(&video->gpu_encoder_mutex, NULL) < 0)
|
||||
return OBS_VIDEO_FAIL;
|
||||
if (pthread_mutex_init(&video->task_mutex, NULL) < 0)
|
||||
@ -570,15 +565,9 @@ static bool obs_init_audio(struct audio_output_info *ai)
|
||||
struct obs_core_audio *audio = &obs->audio;
|
||||
int errorcode;
|
||||
|
||||
pthread_mutexattr_t attr;
|
||||
|
||||
pthread_mutex_init_value(&audio->monitoring_mutex);
|
||||
|
||||
if (pthread_mutexattr_init(&attr) != 0)
|
||||
return false;
|
||||
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0)
|
||||
return false;
|
||||
if (pthread_mutex_init(&audio->monitoring_mutex, &attr) != 0)
|
||||
if (pthread_mutex_init_recursive(&audio->monitoring_mutex) != 0)
|
||||
return false;
|
||||
|
||||
audio->user_volume = 1.0f;
|
||||
@ -628,30 +617,25 @@ static void obs_free_audio(void)
|
||||
static bool obs_init_data(void)
|
||||
{
|
||||
struct obs_core_data *data = &obs->data;
|
||||
pthread_mutexattr_t attr;
|
||||
|
||||
assert(data != NULL);
|
||||
|
||||
pthread_mutex_init_value(&obs->data.displays_mutex);
|
||||
pthread_mutex_init_value(&obs->data.draw_callbacks_mutex);
|
||||
|
||||
if (pthread_mutexattr_init(&attr) != 0)
|
||||
return false;
|
||||
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0)
|
||||
if (pthread_mutex_init_recursive(&data->sources_mutex) != 0)
|
||||
goto fail;
|
||||
if (pthread_mutex_init(&data->sources_mutex, &attr) != 0)
|
||||
if (pthread_mutex_init_recursive(&data->audio_sources_mutex) != 0)
|
||||
goto fail;
|
||||
if (pthread_mutex_init(&data->audio_sources_mutex, &attr) != 0)
|
||||
if (pthread_mutex_init_recursive(&data->displays_mutex) != 0)
|
||||
goto fail;
|
||||
if (pthread_mutex_init(&data->displays_mutex, &attr) != 0)
|
||||
if (pthread_mutex_init_recursive(&data->outputs_mutex) != 0)
|
||||
goto fail;
|
||||
if (pthread_mutex_init(&data->outputs_mutex, &attr) != 0)
|
||||
if (pthread_mutex_init_recursive(&data->encoders_mutex) != 0)
|
||||
goto fail;
|
||||
if (pthread_mutex_init(&data->encoders_mutex, &attr) != 0)
|
||||
if (pthread_mutex_init_recursive(&data->services_mutex) != 0)
|
||||
goto fail;
|
||||
if (pthread_mutex_init(&data->services_mutex, &attr) != 0)
|
||||
goto fail;
|
||||
if (pthread_mutex_init(&obs->data.draw_callbacks_mutex, &attr) != 0)
|
||||
if (pthread_mutex_init_recursive(&obs->data.draw_callbacks_mutex) != 0)
|
||||
goto fail;
|
||||
if (!obs_view_init(&data->main_view))
|
||||
goto fail;
|
||||
@ -660,7 +644,6 @@ static bool obs_init_data(void)
|
||||
data->valid = true;
|
||||
|
||||
fail:
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
return data->valid;
|
||||
}
|
||||
|
||||
@ -764,7 +747,6 @@ static pthread_once_t obs_pthread_once_init_token = PTHREAD_ONCE_INIT;
|
||||
static inline bool obs_init_hotkeys(void)
|
||||
{
|
||||
struct obs_core_hotkeys *hotkeys = &obs->hotkeys;
|
||||
pthread_mutexattr_t attr;
|
||||
bool success = false;
|
||||
|
||||
assert(hotkeys != NULL);
|
||||
@ -782,11 +764,7 @@ static inline bool obs_init_hotkeys(void)
|
||||
if (!obs_hotkeys_platform_init(hotkeys))
|
||||
return false;
|
||||
|
||||
if (pthread_mutexattr_init(&attr) != 0)
|
||||
return false;
|
||||
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0)
|
||||
goto fail;
|
||||
if (pthread_mutex_init(&hotkeys->mutex, &attr) != 0)
|
||||
if (pthread_mutex_init_recursive(&hotkeys->mutex) != 0)
|
||||
goto fail;
|
||||
|
||||
if (os_event_init(&hotkeys->stop_event, OS_EVENT_TYPE_MANUAL) != 0)
|
||||
@ -800,7 +778,6 @@ static inline bool obs_init_hotkeys(void)
|
||||
success = true;
|
||||
|
||||
fail:
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
return success;
|
||||
}
|
||||
|
||||
|
@ -61,16 +61,6 @@ struct config_data {
|
||||
pthread_mutex_t mutex;
|
||||
};
|
||||
|
||||
static inline bool init_mutex(config_t *config)
|
||||
{
|
||||
pthread_mutexattr_t attr;
|
||||
if (pthread_mutexattr_init(&attr) != 0)
|
||||
return false;
|
||||
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0)
|
||||
return false;
|
||||
return pthread_mutex_init(&config->mutex, &attr) == 0;
|
||||
}
|
||||
|
||||
config_t *config_create(const char *file)
|
||||
{
|
||||
struct config_data *config;
|
||||
@ -83,7 +73,7 @@ config_t *config_create(const char *file)
|
||||
|
||||
config = bzalloc(sizeof(struct config_data));
|
||||
|
||||
if (!init_mutex(config)) {
|
||||
if (pthread_mutex_init_recursive(&config->mutex) != 0) {
|
||||
bfree(config);
|
||||
return NULL;
|
||||
}
|
||||
@ -302,7 +292,7 @@ int config_open(config_t **config, const char *file,
|
||||
if (!*config)
|
||||
return CONFIG_ERROR;
|
||||
|
||||
if (!init_mutex(*config)) {
|
||||
if (pthread_mutex_init_recursive(&(*config)->mutex) != 0) {
|
||||
bfree(*config);
|
||||
return CONFIG_ERROR;
|
||||
}
|
||||
@ -330,7 +320,7 @@ int config_open_string(config_t **config, const char *str)
|
||||
if (!*config)
|
||||
return CONFIG_ERROR;
|
||||
|
||||
if (!init_mutex(*config)) {
|
||||
if (pthread_mutex_init_recursive(&(*config)->mutex) != 0) {
|
||||
bfree(*config);
|
||||
return CONFIG_ERROR;
|
||||
}
|
||||
|
@ -825,6 +825,8 @@ void profiler_free(void)
|
||||
}
|
||||
|
||||
da_free(old_root_entries);
|
||||
|
||||
pthread_mutex_destroy(&root_mutex);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -858,6 +860,9 @@ void profiler_name_store_free(profiler_name_store_t *store)
|
||||
bfree(store->names.array[i]);
|
||||
|
||||
da_free(store->names);
|
||||
|
||||
pthread_mutex_destroy(&store->mutex);
|
||||
|
||||
bfree(store);
|
||||
}
|
||||
|
||||
|
@ -53,6 +53,22 @@ static inline void pthread_mutex_init_value(pthread_mutex_t *mutex)
|
||||
*mutex = init_val;
|
||||
}
|
||||
|
||||
static inline int pthread_mutex_init_recursive(pthread_mutex_t *mutex)
|
||||
{
|
||||
pthread_mutexattr_t attr;
|
||||
int ret = pthread_mutexattr_init(&attr);
|
||||
if (ret == 0) {
|
||||
ret = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
if (ret == 0) {
|
||||
ret = pthread_mutex_init(mutex, &attr);
|
||||
}
|
||||
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
enum os_event_type {
|
||||
OS_EVENT_TYPE_AUTO,
|
||||
OS_EVENT_TYPE_MANUAL,
|
||||
|
@ -140,6 +140,7 @@ struct noise_suppress_data {
|
||||
|
||||
#ifdef LIBNVAFX_ENABLED
|
||||
/* global mutex for nvafx load functions since they aren't thread-safe */
|
||||
bool nvafx_initializer_mutex_initialized;
|
||||
pthread_mutex_t nvafx_initializer_mutex;
|
||||
#endif
|
||||
|
||||
@ -516,7 +517,8 @@ bool load_nvafx(void)
|
||||
return false;
|
||||
}
|
||||
|
||||
pthread_mutex_init(&nvafx_initializer_mutex, NULL);
|
||||
nvafx_initializer_mutex_initialized =
|
||||
pthread_mutex_init(&nvafx_initializer_mutex, NULL) == 0;
|
||||
|
||||
#define LOAD_SYM_FROM_LIB(sym, lib, dll) \
|
||||
if (!(sym = (sym##_t)GetProcAddress(lib, #sym))) { \
|
||||
@ -576,6 +578,18 @@ unload_everything:
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
void unload_nvafx(void)
|
||||
{
|
||||
#ifdef LIBNVAFX_ENABLED
|
||||
release_lib();
|
||||
|
||||
if (nvafx_initializer_mutex_initialized) {
|
||||
pthread_mutex_destroy(&nvafx_initializer_mutex);
|
||||
nvafx_initializer_mutex_initialized = false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void *noise_suppress_create(obs_data_t *settings, obs_source_t *filter)
|
||||
{
|
||||
struct noise_suppress_data *ng =
|
||||
|
@ -28,8 +28,8 @@ extern struct obs_source_info async_delay_filter;
|
||||
#if NOISEREDUCTION_ENABLED
|
||||
extern struct obs_source_info noise_suppress_filter;
|
||||
extern struct obs_source_info noise_suppress_filter_v2;
|
||||
extern bool load_nvafx();
|
||||
extern void release_lib();
|
||||
extern bool load_nvafx(void);
|
||||
extern void unload_nvafx(void);
|
||||
#endif
|
||||
extern struct obs_source_info invert_polarity_filter;
|
||||
extern struct obs_source_info noise_gate_filter;
|
||||
@ -79,6 +79,6 @@ bool obs_module_load(void)
|
||||
#ifdef LIBNVAFX_ENABLED
|
||||
void obs_module_unload(void)
|
||||
{
|
||||
release_lib();
|
||||
unload_nvafx();
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user