diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 533219c324..6a508a2917 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -53,6 +53,8 @@ #include "../config.def.h" #include "../performance.h" +#include "../tasks/tasks_internal.h" + struct rarch_setting_info { @@ -2821,6 +2823,14 @@ void general_write_handler(void *data) switch (hash) { + case MENU_LABEL_VIDEO_THREADED: + { + if (*setting->value.boolean) + task_ctl(TASK_CTL_SET_THREADED, NULL); + else + task_ctl(TASK_CTL_UNSET_THREADED, NULL); + } + break; case MENU_LABEL_INPUT_POLL_TYPE_BEHAVIOR: core_ctl(CORE_CTL_SET_POLL_TYPE, setting->value.integer); break; diff --git a/retroarch.c b/retroarch.c index 978a94b2bc..2044e1b2b5 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1205,7 +1205,8 @@ static int rarch_main_init(int argc, char *argv[]) rarch_ctl(RARCH_CTL_VALIDATE_CPU_FEATURES, NULL); config_load(); - task_ctl(TASK_CTL_INIT, NULL); + + runloop_ctl(RUNLOOP_CTL_TASK_INIT, NULL); { settings_t *settings = config_get_ptr(); diff --git a/runloop.c b/runloop.c index 655141d7e5..6573a891fb 100644 --- a/runloop.c +++ b/runloop.c @@ -970,12 +970,18 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data) slock_unlock(runloop_msg_queue_lock); #endif break; + case RUNLOOP_CTL_TASK_INIT: + { + bool threaded_enable = settings->threaded_data_runloop_enable; + task_ctl(TASK_CTL_INIT, &threaded_enable); + } + break; case RUNLOOP_CTL_PREPARE_DUMMY: #ifdef HAVE_MENU menu_driver_ctl(RARCH_MENU_CTL_UNSET_LOAD_NO_CONTENT, NULL); #endif runloop_ctl(RUNLOOP_CTL_DATA_DEINIT, NULL); - task_ctl(TASK_CTL_INIT, NULL); + runloop_ctl(RUNLOOP_CTL_TASK_INIT, NULL); runloop_ctl(RUNLOOP_CTL_CLEAR_CONTENT_PATH, NULL); rarch_ctl(RARCH_CTL_LOAD_CONTENT, NULL); diff --git a/runloop.h b/runloop.h index 1142e65659..4d9ada94d4 100644 --- a/runloop.h +++ b/runloop.h @@ -33,6 +33,7 @@ enum runloop_ctl_state RUNLOOP_CTL_SHOULD_SET_FRAME_LIMIT, RUNLOOP_CTL_SET_FRAME_TIME_LAST, RUNLOOP_CTL_UNSET_FRAME_TIME_LAST, + RUNLOOP_CTL_TASK_INIT, RUNLOOP_CTL_IS_FRAME_TIME_LAST, RUNLOOP_CTL_IS_FRAME_COUNT_END, RUNLOOP_CTL_IS_IDLE, diff --git a/tasks/tasks.c b/tasks/tasks.c index 123db22226..edf13769a1 100644 --- a/tasks/tasks.c +++ b/tasks/tasks.c @@ -18,10 +18,6 @@ #include #include -#ifdef HAVE_THREADS -#include "../configuration.h" -#endif - #include "tasks.h" #ifdef HAVE_THREADS @@ -337,9 +333,7 @@ static struct rarch_task_impl impl_threaded = { bool task_ctl(enum task_ctl_state state, void *data) { static struct rarch_task_impl *impl_current = NULL; -#ifdef HAVE_THREADS - settings_t *settings = config_get_ptr(); -#endif + static bool task_threaded_enable = false; switch (state) { @@ -348,14 +342,29 @@ bool task_ctl(enum task_ctl_state state, void *data) impl_current->deinit(); impl_current = NULL; break; + case TASK_CTL_SET_THREADED: + task_threaded_enable = true; + break; + case TASK_CTL_UNSET_THREADED: + task_threaded_enable = false; + break; + case TASK_CTL_IS_THREADED: + return task_threaded_enable; case TASK_CTL_INIT: - impl_current = &impl_regular; + { + bool *boolean_val = (bool*)data; + + impl_current = &impl_regular; #ifdef HAVE_THREADS - if (settings->threaded_data_runloop_enable) - impl_current = &impl_threaded; + if (*boolean_val) + { + task_ctl(TASK_CTL_SET_THREADED, NULL); + impl_current = &impl_threaded; + } #endif - impl_current->init(); + impl_current->init(); + } break; case TASK_CTL_FIND: { @@ -368,7 +377,7 @@ bool task_ctl(enum task_ctl_state state, void *data) { #ifdef HAVE_THREADS bool current_threaded = (impl_current == &impl_threaded); - bool want_threaded = settings->threaded_data_runloop_enable; + bool want_threaded = task_ctl(TASK_CTL_IS_THREADED, NULL); if (want_threaded != current_threaded) task_ctl(TASK_CTL_DEINIT, NULL); @@ -382,8 +391,8 @@ bool task_ctl(enum task_ctl_state state, void *data) break; case TASK_CTL_PUSH: { - /* The lack of NULL checks in the following functions is proposital - * to ensure correct control flow by the users. */ + /* The lack of NULL checks in the following functions + * is proposital to ensure correct control flow by the users. */ rarch_task_t *task = (rarch_task_t*)data; impl_current->push_running(task); break; diff --git a/tasks/tasks.h b/tasks/tasks.h index d40fc13dc7..efb2be0e95 100644 --- a/tasks/tasks.h +++ b/tasks/tasks.h @@ -70,7 +70,13 @@ enum task_ctl_state * They will finish as soon as possible. * * This must only be called from the main thread. */ - TASK_CTL_RESET + TASK_CTL_RESET, + + TASK_CTL_SET_THREADED, + + TASK_CTL_UNSET_THREADED, + + TASK_CTL_IS_THREADED }; typedef struct rarch_task rarch_task_t;