Merge pull request #4958 from aliaspider/master

allow easier scheduling of tasks in single threaded mode.
This commit is contained in:
Twinaphex 2017-05-22 12:50:43 +02:00 committed by GitHub
commit fce0ca2a3a
4 changed files with 39 additions and 16 deletions

View File

@ -48,6 +48,7 @@
#include <sys/iosupport.h>
#include <wiiu/os/foreground.h>
#include <wiiu/gx2/event.h>
#include <wiiu/procui.h>
#include <wiiu/sysapp.h>
#include <wiiu/ios.h>
@ -383,6 +384,16 @@ void SaveCallback()
OSSavesDone_ReadyToRelease();
}
static bool swap_is_pending(void* start_time)
{
uint32_t swap_count, flip_count;
OSTime last_flip , last_vsync;
GX2GetSwapStatus(&swap_count, &flip_count, &last_flip, &last_vsync);
return last_vsync < *(OSTime*)start_time;
}
int main(int argc, char **argv)
{
#if 1
@ -447,12 +458,20 @@ int main(int argc, char **argv)
do
{
unsigned sleep_ms = 0;
if(video_driver_get_ptr(false))
{
OSTime start_time = OSGetSystemTime();
task_queue_wait(swap_is_pending, &start_time);
}
else
task_queue_wait(NULL, NULL);
int ret = runloop_iterate(&sleep_ms);
if (ret == 1 && sleep_ms > 0)
retro_sleep(sleep_ms);
task_queue_wait();
if (ret == -1)
break;

View File

@ -502,12 +502,6 @@ static bool wiiu_gfx_frame(void* data, const void* frame,
wiiu_video_t* wiiu = (wiiu_video_t*) data;
if (!width || !height)
{
GX2WaitForVsync();
return true;
}
if(wiiu->vsync)
{
uint32_t swap_count;
@ -527,6 +521,10 @@ static bool wiiu_gfx_frame(void* data, const void* frame,
}
GX2WaitForFlip();
if (!width || !height)
return true;
static u32 lastTick , currentTick;
currentTick = OSGetSystemTick();
u32 diff = currentTick - lastTick;

View File

@ -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_condition_fn_t)(void *data);
typedef struct
{
char *source_file;
@ -200,9 +202,12 @@ void task_queue_check(void);
* The task will start as soon as possible. */
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. */
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.
*

View File

@ -47,7 +47,7 @@ struct retro_task_impl
void (*push_running)(retro_task_t *);
void (*cancel)(void *);
void (*reset)(void);
void (*wait)(void);
void (*wait)(retro_task_condition_fn_t, void *);
void (*gather)(void);
bool (*find)(retro_task_finder_t, void*);
void (*retrieve)(task_retriever_data_t *data);
@ -189,9 +189,9 @@ static void retro_task_regular_gather(void)
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();
}
@ -373,7 +373,7 @@ static void retro_task_threaded_gather(void)
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;
@ -382,7 +382,8 @@ static void retro_task_threaded_wait(void)
retro_task_threaded_gather();
slock_lock(running_lock);
wait = (tasks_running.front != NULL);
wait = (tasks_running.front != NULL) &&
(!cond || cond(data));
slock_unlock(running_lock);
} while (wait);
}
@ -637,9 +638,9 @@ void task_queue_push(retro_task_t *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)