Create TASK_CTL_INIT

This commit is contained in:
twinaphex 2016-01-28 09:52:28 +01:00
parent b008750f18
commit a5e8615091
4 changed files with 25 additions and 28 deletions

View File

@ -1223,7 +1223,7 @@ int rarch_main_init(int argc, char *argv[])
rarch_ctl(RARCH_CTL_VALIDATE_CPU_FEATURES, NULL); rarch_ctl(RARCH_CTL_VALIDATE_CPU_FEATURES, NULL);
config_load(); config_load();
rarch_task_init(); task_ctl(TASK_CTL_INIT, NULL);
{ {
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();

View File

@ -996,8 +996,7 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data)
menu_driver_ctl(RARCH_MENU_CTL_UNSET_LOAD_NO_CONTENT, NULL); menu_driver_ctl(RARCH_MENU_CTL_UNSET_LOAD_NO_CONTENT, NULL);
#endif #endif
runloop_ctl(RUNLOOP_CTL_DATA_DEINIT, NULL); runloop_ctl(RUNLOOP_CTL_DATA_DEINIT, NULL);
rarch_task_init(); task_ctl(TASK_CTL_INIT, NULL);
runloop_ctl(RUNLOOP_CTL_CLEAR_CONTENT_PATH, NULL); runloop_ctl(RUNLOOP_CTL_CLEAR_CONTENT_PATH, NULL);
rarch_ctl(RARCH_CTL_LOAD_CONTENT, NULL); rarch_ctl(RARCH_CTL_LOAD_CONTENT, NULL);

View File

@ -369,19 +369,6 @@ static struct rarch_task_impl impl_threaded = {
}; };
#endif #endif
void rarch_task_init(void)
{
#ifdef HAVE_THREADS
settings_t *settings = config_get_ptr();
if (settings->threaded_data_runloop_enable)
impl_current = &impl_threaded;
else
#endif
impl_current = &impl_regular;
impl_current->init();
}
bool rarch_task_find(rarch_task_finder_t func, void *user_data) bool rarch_task_find(rarch_task_finder_t func, void *user_data)
{ {
return impl_current->find(func, user_data); return impl_current->find(func, user_data);
@ -389,6 +376,10 @@ bool rarch_task_find(rarch_task_finder_t func, void *user_data)
bool task_ctl(enum task_ctl_state state, void *data) bool task_ctl(enum task_ctl_state state, void *data)
{ {
#ifdef HAVE_THREADS
settings_t *settings = config_get_ptr();
#endif
switch (state) switch (state)
{ {
case TASK_CTL_DEINIT: case TASK_CTL_DEINIT:
@ -398,10 +389,19 @@ bool task_ctl(enum task_ctl_state state, void *data)
impl_current->deinit(); impl_current->deinit();
impl_current = NULL; impl_current = NULL;
break; break;
case TASK_CTL_INIT:
#ifdef HAVE_THREADS
if (settings->threaded_data_runloop_enable)
impl_current = &impl_threaded;
else
#endif
impl_current = &impl_regular;
impl_current->init();
break;
case TASK_CTL_CHECK: case TASK_CTL_CHECK:
{ {
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
settings_t *settings = config_get_ptr();
bool current_threaded = (impl_current == &impl_threaded); bool current_threaded = (impl_current == &impl_threaded);
bool want_threaded = settings->threaded_data_runloop_enable; bool want_threaded = settings->threaded_data_runloop_enable;
@ -412,7 +412,7 @@ bool task_ctl(enum task_ctl_state state, void *data)
} }
if (impl_current == NULL) if (impl_current == NULL)
rarch_task_init(); task_ctl(TASK_CTL_INIT, NULL);
#endif #endif
impl_current->gather(); impl_current->gather();

View File

@ -36,6 +36,14 @@ enum task_ctl_state
* until TASK_CTL_INIT is called again. */ * until TASK_CTL_INIT is called again. */
TASK_CTL_DEINIT, TASK_CTL_DEINIT,
/* Initializes the task system.
* This initializes the task system
* and chooses an appropriate
* implementation according to the settings.
*
* This must only be called from the main thread. */
TASK_CTL_INIT,
/* Blocks until all tasks have finished. /* Blocks until all tasks have finished.
* This must only be called from the main thread. */ * This must only be called from the main thread. */
TASK_CTL_WAIT, TASK_CTL_WAIT,
@ -99,16 +107,6 @@ struct rarch_task
rarch_task_t *next; rarch_task_t *next;
}; };
/**
* @brief Initializes the task system
*
* This function initializes the task system and chooses an appropriate
* implementation according to the settings.
*
* This function must only be called from the main thread.
*/
void rarch_task_init(void);
/** /**
* @brief Calls func for every running task until it returns true. * @brief Calls func for every running task until it returns true.
* *