mirror of
https://github.com/libretro/RetroArch
synced 2025-03-24 13:43:32 +00:00
Refactor thrading code in runloop_data.c
This commit is contained in:
parent
8d0297dfe1
commit
58cf81d1d8
@ -72,6 +72,11 @@ typedef struct nbio_handle
|
|||||||
msg_queue_t *msg_queue;
|
msg_queue_t *msg_queue;
|
||||||
} nbio_handle_t;
|
} nbio_handle_t;
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
THREAD_CODE_INIT = 0,
|
||||||
|
THREAD_CODE_ALIVE,
|
||||||
|
} thread_code_enum;
|
||||||
|
|
||||||
typedef struct data_runloop
|
typedef struct data_runloop
|
||||||
{
|
{
|
||||||
@ -92,7 +97,8 @@ typedef struct data_runloop
|
|||||||
|
|
||||||
#ifdef HAVE_THREADS
|
#ifdef HAVE_THREADS
|
||||||
bool thread_inited;
|
bool thread_inited;
|
||||||
bool thread_quit;
|
unsigned thread_code;
|
||||||
|
bool alive;
|
||||||
|
|
||||||
slock_t *lock;
|
slock_t *lock;
|
||||||
slock_t *cond_lock;
|
slock_t *cond_lock;
|
||||||
@ -752,9 +758,9 @@ static void data_runloop_thread_deinit(data_runloop_t *runloop)
|
|||||||
if (!runloop->thread_inited)
|
if (!runloop->thread_inited)
|
||||||
{
|
{
|
||||||
slock_lock(runloop->cond_lock);
|
slock_lock(runloop->cond_lock);
|
||||||
runloop->thread_quit = true;
|
runloop->alive = false;
|
||||||
slock_unlock(runloop->cond_lock);
|
|
||||||
scond_signal(runloop->cond);
|
scond_signal(runloop->cond);
|
||||||
|
slock_unlock(runloop->cond_lock);
|
||||||
sthread_join(runloop->thread);
|
sthread_join(runloop->thread);
|
||||||
|
|
||||||
slock_free(runloop->lock);
|
slock_free(runloop->lock);
|
||||||
@ -811,7 +817,7 @@ static void data_thread_loop(void *data)
|
|||||||
{
|
{
|
||||||
slock_lock(runloop->lock);
|
slock_lock(runloop->lock);
|
||||||
|
|
||||||
if (runloop->thread_quit)
|
if (!runloop->alive)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
data_runloop_iterate(true, runloop);
|
data_runloop_iterate(true, runloop);
|
||||||
@ -839,8 +845,11 @@ static void rarch_main_data_thread_init(void)
|
|||||||
|
|
||||||
g_data_runloop.thread_inited = (g_data_runloop.thread != NULL);
|
g_data_runloop.thread_inited = (g_data_runloop.thread != NULL);
|
||||||
|
|
||||||
if (g_data_runloop.thread_inited)
|
if (!g_data_runloop.thread_inited)
|
||||||
g_data_runloop.thread_quit = false;
|
return;
|
||||||
|
|
||||||
|
g_data_runloop.alive = true;
|
||||||
|
g_data_runloop.thread_code = THREAD_CODE_ALIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rarch_main_data_iterate(void)
|
void rarch_main_data_iterate(void)
|
||||||
@ -849,14 +858,16 @@ void rarch_main_data_iterate(void)
|
|||||||
#if 0
|
#if 0
|
||||||
if (g_settings.menu.threaded_data_runloop_enable)
|
if (g_settings.menu.threaded_data_runloop_enable)
|
||||||
{
|
{
|
||||||
if (g_data_runloop.thread_inited
|
switch (g_data_runloop.thread_code)
|
||||||
&& !g_data_runloop.thread_quit)
|
{
|
||||||
return;
|
case THREAD_CODE_ALIVE:
|
||||||
|
if (g_data_runloop.alive)
|
||||||
if (g_data_runloop.thread_inited)
|
return;
|
||||||
data_runloop_thread_deinit(&g_data_runloop);
|
break;
|
||||||
else
|
case THREAD_CODE_INIT:
|
||||||
rarch_main_data_thread_init();
|
rarch_main_data_thread_init();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
@ -872,7 +883,7 @@ static void rarch_main_data_init(void)
|
|||||||
memset(&g_data_runloop, 0, sizeof(g_data_runloop));
|
memset(&g_data_runloop, 0, sizeof(g_data_runloop));
|
||||||
|
|
||||||
g_data_runloop.thread_inited = false;
|
g_data_runloop.thread_inited = false;
|
||||||
g_data_runloop.thread_quit = true;
|
g_data_runloop.alive = false;
|
||||||
|
|
||||||
g_data_runloop.inited = true;
|
g_data_runloop.inited = true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user