diff --git a/runloop.c b/runloop.c index 7373b946ab..1848520e79 100644 --- a/runloop.c +++ b/runloop.c @@ -1027,7 +1027,7 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data) case RUNLOOP_CTL_IS_EXEC: return runloop_exec; case RUNLOOP_CTL_DATA_DEINIT: - rarch_task_deinit(); + task_ctl(TASK_CTL_DEINIT, NULL); break; case RUNLOOP_CTL_IS_CORE_OPTION_UPDATED: if (!runloop_system.core_options) diff --git a/tasks/tasks.c b/tasks/tasks.c index 860cfbbbaf..c518bc060c 100644 --- a/tasks/tasks.c +++ b/tasks/tasks.c @@ -25,12 +25,14 @@ #include "rthreads/rthreads.h" #endif -typedef struct { +typedef struct +{ rarch_task_t *front; rarch_task_t *back; } task_queue_t; -struct rarch_task_impl { +struct rarch_task_impl +{ void (*push_running)(rarch_task_t *); void (*reset)(void); void (*wait)(void); @@ -39,6 +41,7 @@ struct rarch_task_impl { void (*init)(void); void (*deinit)(void); }; + static task_queue_t tasks_running = {NULL, NULL}; static task_queue_t tasks_finished = {NULL, NULL}; @@ -48,10 +51,10 @@ static void task_queue_put(task_queue_t *queue, rarch_task_t *task) { task->next = NULL; - if (!queue->front) - queue->front = task; - else + if (queue->front) queue->back->next = task; + else + queue->front = task; queue->back = task; } @@ -74,6 +77,7 @@ void task_msg_queue_pushf(unsigned prio, unsigned duration, { char buf[1024]; va_list ap; + va_start(ap, fmt); vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); @@ -378,15 +382,6 @@ void rarch_task_init(void) impl_current->init(); } -void rarch_task_deinit(void) -{ - if (!impl_current) - return; - - impl_current->deinit(); - impl_current = NULL; -} - bool rarch_task_find(rarch_task_finder_t func, void *user_data) { return impl_current->find(func, user_data); @@ -396,6 +391,13 @@ bool task_ctl(enum task_ctl_state state, void *data) { switch (state) { + case TASK_CTL_DEINIT: + if (!impl_current) + return false; + + impl_current->deinit(); + impl_current = NULL; + break; case TASK_CTL_CHECK: { #ifdef HAVE_THREADS @@ -406,7 +408,7 @@ bool task_ctl(enum task_ctl_state state, void *data) if (want_threaded != current_threaded) { RARCH_LOG("Switching rarch_task implementation.\n"); - rarch_task_deinit(); + task_ctl(TASK_CTL_DEINIT, NULL); } if (impl_current == NULL) diff --git a/tasks/tasks.h b/tasks/tasks.h index d047d7e293..70d06a670c 100644 --- a/tasks/tasks.h +++ b/tasks/tasks.h @@ -29,6 +29,13 @@ enum task_ctl_state { TASK_CTL_NONE = 0, + /* Deinitializes the task system. + * This deinitializes the task system. + * The tasks that are running at + * the moment will stay on hold + * until TASK_CTL_INIT is called again. */ + TASK_CTL_DEINIT, + /* Blocks until all tasks have finished. * This must only be called from the main thread. */ TASK_CTL_WAIT, @@ -102,14 +109,6 @@ struct rarch_task */ void rarch_task_init(void); -/** - * @brief Deinitializes the task system - * - * This function deinitializes the task system. The tasks that are running at - * the moment will stay on hold until rarch_task_init() is called again. - */ -void rarch_task_deinit(void); - /** * @brief Calls func for every running task until it returns true. *