Add TASK_CTL_DEINIT
This commit is contained in:
parent
7a5fbc6948
commit
b008750f18
|
@ -1027,7 +1027,7 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data)
|
||||||
case RUNLOOP_CTL_IS_EXEC:
|
case RUNLOOP_CTL_IS_EXEC:
|
||||||
return runloop_exec;
|
return runloop_exec;
|
||||||
case RUNLOOP_CTL_DATA_DEINIT:
|
case RUNLOOP_CTL_DATA_DEINIT:
|
||||||
rarch_task_deinit();
|
task_ctl(TASK_CTL_DEINIT, NULL);
|
||||||
break;
|
break;
|
||||||
case RUNLOOP_CTL_IS_CORE_OPTION_UPDATED:
|
case RUNLOOP_CTL_IS_CORE_OPTION_UPDATED:
|
||||||
if (!runloop_system.core_options)
|
if (!runloop_system.core_options)
|
||||||
|
|
|
@ -25,12 +25,14 @@
|
||||||
#include "rthreads/rthreads.h"
|
#include "rthreads/rthreads.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct
|
||||||
|
{
|
||||||
rarch_task_t *front;
|
rarch_task_t *front;
|
||||||
rarch_task_t *back;
|
rarch_task_t *back;
|
||||||
} task_queue_t;
|
} task_queue_t;
|
||||||
|
|
||||||
struct rarch_task_impl {
|
struct rarch_task_impl
|
||||||
|
{
|
||||||
void (*push_running)(rarch_task_t *);
|
void (*push_running)(rarch_task_t *);
|
||||||
void (*reset)(void);
|
void (*reset)(void);
|
||||||
void (*wait)(void);
|
void (*wait)(void);
|
||||||
|
@ -39,6 +41,7 @@ struct rarch_task_impl {
|
||||||
void (*init)(void);
|
void (*init)(void);
|
||||||
void (*deinit)(void);
|
void (*deinit)(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
static task_queue_t tasks_running = {NULL, NULL};
|
static task_queue_t tasks_running = {NULL, NULL};
|
||||||
static task_queue_t tasks_finished = {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;
|
task->next = NULL;
|
||||||
|
|
||||||
if (!queue->front)
|
if (queue->front)
|
||||||
queue->front = task;
|
|
||||||
else
|
|
||||||
queue->back->next = task;
|
queue->back->next = task;
|
||||||
|
else
|
||||||
|
queue->front = task;
|
||||||
|
|
||||||
queue->back = task;
|
queue->back = task;
|
||||||
}
|
}
|
||||||
|
@ -74,6 +77,7 @@ void task_msg_queue_pushf(unsigned prio, unsigned duration,
|
||||||
{
|
{
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
vsnprintf(buf, sizeof(buf), fmt, ap);
|
vsnprintf(buf, sizeof(buf), fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
@ -378,15 +382,6 @@ void rarch_task_init(void)
|
||||||
impl_current->init();
|
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)
|
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);
|
||||||
|
@ -396,6 +391,13 @@ bool task_ctl(enum task_ctl_state state, void *data)
|
||||||
{
|
{
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
|
case TASK_CTL_DEINIT:
|
||||||
|
if (!impl_current)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
impl_current->deinit();
|
||||||
|
impl_current = NULL;
|
||||||
|
break;
|
||||||
case TASK_CTL_CHECK:
|
case TASK_CTL_CHECK:
|
||||||
{
|
{
|
||||||
#ifdef HAVE_THREADS
|
#ifdef HAVE_THREADS
|
||||||
|
@ -406,7 +408,7 @@ bool task_ctl(enum task_ctl_state state, void *data)
|
||||||
if (want_threaded != current_threaded)
|
if (want_threaded != current_threaded)
|
||||||
{
|
{
|
||||||
RARCH_LOG("Switching rarch_task implementation.\n");
|
RARCH_LOG("Switching rarch_task implementation.\n");
|
||||||
rarch_task_deinit();
|
task_ctl(TASK_CTL_DEINIT, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (impl_current == NULL)
|
if (impl_current == NULL)
|
||||||
|
|
|
@ -29,6 +29,13 @@ enum task_ctl_state
|
||||||
{
|
{
|
||||||
TASK_CTL_NONE = 0,
|
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.
|
/* 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,
|
||||||
|
@ -102,14 +109,6 @@ struct rarch_task
|
||||||
*/
|
*/
|
||||||
void rarch_task_init(void);
|
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.
|
* @brief Calls func for every running task until it returns true.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue