mirror of
https://github.com/libretro/RetroArch
synced 2025-04-25 09:02:44 +00:00
allow easier scheduling of tasks in single threaded mode by adding a
condition callback to task_queue_wait.
This commit is contained in:
parent
dd5bc1a951
commit
b00776b09e
@ -57,6 +57,8 @@ typedef void (*retro_task_queue_msg_t)(const char *msg,
|
|||||||
|
|
||||||
typedef bool (*retro_task_retriever_t)(retro_task_t *task, void *data);
|
typedef bool (*retro_task_retriever_t)(retro_task_t *task, void *data);
|
||||||
|
|
||||||
|
typedef bool (*retro_task_condition_fn_t)(void *data);
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char *source_file;
|
char *source_file;
|
||||||
@ -200,9 +202,12 @@ void task_queue_check(void);
|
|||||||
* The task will start as soon as possible. */
|
* The task will start as soon as possible. */
|
||||||
void task_queue_push(retro_task_t *task);
|
void task_queue_push(retro_task_t *task);
|
||||||
|
|
||||||
/* Blocks until all tasks have finished.
|
/* Blocks until all tasks have finished
|
||||||
|
* will return early if cond is not NULL
|
||||||
|
* and cond(data) returns false.
|
||||||
* This must only be called from the main thread. */
|
* This must only be called from the main thread. */
|
||||||
void task_queue_wait(void);
|
void task_queue_wait(retro_task_condition_fn_t cond, void* data);
|
||||||
|
|
||||||
|
|
||||||
/* Sends a signal to terminate all the tasks.
|
/* Sends a signal to terminate all the tasks.
|
||||||
*
|
*
|
||||||
|
@ -47,7 +47,7 @@ struct retro_task_impl
|
|||||||
void (*push_running)(retro_task_t *);
|
void (*push_running)(retro_task_t *);
|
||||||
void (*cancel)(void *);
|
void (*cancel)(void *);
|
||||||
void (*reset)(void);
|
void (*reset)(void);
|
||||||
void (*wait)(void);
|
void (*wait)(retro_task_condition_fn_t, void *);
|
||||||
void (*gather)(void);
|
void (*gather)(void);
|
||||||
bool (*find)(retro_task_finder_t, void*);
|
bool (*find)(retro_task_finder_t, void*);
|
||||||
void (*retrieve)(task_retriever_data_t *data);
|
void (*retrieve)(task_retriever_data_t *data);
|
||||||
@ -189,9 +189,9 @@ static void retro_task_regular_gather(void)
|
|||||||
retro_task_internal_gather();
|
retro_task_internal_gather();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void retro_task_regular_wait(void)
|
static void retro_task_regular_wait(retro_task_condition_fn_t cond, void* data)
|
||||||
{
|
{
|
||||||
while (tasks_running.front)
|
while (tasks_running.front && (!cond || cond(data)))
|
||||||
retro_task_regular_gather();
|
retro_task_regular_gather();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,7 +373,7 @@ static void retro_task_threaded_gather(void)
|
|||||||
slock_unlock(property_lock);
|
slock_unlock(property_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void retro_task_threaded_wait(void)
|
static void retro_task_threaded_wait(retro_task_condition_fn_t cond, void* data)
|
||||||
{
|
{
|
||||||
bool wait = false;
|
bool wait = false;
|
||||||
|
|
||||||
@ -382,7 +382,8 @@ static void retro_task_threaded_wait(void)
|
|||||||
retro_task_threaded_gather();
|
retro_task_threaded_gather();
|
||||||
|
|
||||||
slock_lock(running_lock);
|
slock_lock(running_lock);
|
||||||
wait = (tasks_running.front != NULL);
|
wait = (tasks_running.front != NULL) &&
|
||||||
|
(!cond || cond(data));
|
||||||
slock_unlock(running_lock);
|
slock_unlock(running_lock);
|
||||||
} while (wait);
|
} while (wait);
|
||||||
}
|
}
|
||||||
@ -637,9 +638,9 @@ void task_queue_push(retro_task_t *task)
|
|||||||
impl_current->push_running(task);
|
impl_current->push_running(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
void task_queue_wait(void)
|
void task_queue_wait(retro_task_condition_fn_t cond, void* data)
|
||||||
{
|
{
|
||||||
impl_current->wait();
|
impl_current->wait(cond, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void task_queue_reset(void)
|
void task_queue_reset(void)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user