Put g_driver on heap and make it a pointer

This commit is contained in:
twinaphex 2015-03-22 01:16:57 +01:00
parent 248d985ae6
commit 2a8f9fdfc0
4 changed files with 41 additions and 5 deletions

View File

@ -30,7 +30,38 @@
#include "config.h"
#endif
static driver_t g_driver;
static driver_t *g_driver;
void driver_free(void)
{
driver_t *driver = driver_get_ptr();
if (!driver)
return;
free(driver);
}
static driver_t *driver_alloc(void)
{
driver_t *driver = (driver_t*)calloc(1, sizeof(driver_t));
if (!driver)
return NULL;
return driver;
}
void driver_clear_state(void)
{
driver_free();
g_driver = driver_alloc();
}
driver_t *driver_get_ptr(void)
{
return g_driver;
}
/**
* find_driver_nonempty:
@ -441,7 +472,3 @@ void uninit_drivers(int flags)
driver->audio_data = NULL;
}
driver_t *driver_get_ptr(void)
{
return &g_driver;
}

View File

@ -394,6 +394,10 @@ bool driver_update_system_av_info(const struct retro_system_av_info *info);
int find_driver_index(const char * label, const char *drv);
driver_t *driver_get_ptr(void);
void driver_free(void);
void driver_clear_state(void);
#ifdef __cplusplus
}

View File

@ -121,6 +121,8 @@ void main_exit(args_type() args)
if (driver->frontend_ctx && driver->frontend_ctx->shutdown)
driver->frontend_ctx->shutdown(false);
driver_free();
}
static void check_defaults_dirs(void)

View File

@ -1009,6 +1009,7 @@ runloop_t *rarch_main_get_ptr(void)
return g_runloop;
}
void rarch_main_state_deinit(void)
{
runloop_t *runloop = rarch_main_get_ptr();
@ -1074,6 +1075,8 @@ static runloop_t *rarch_main_state_init(void)
void rarch_main_clear_state(void)
{
driver_clear_state();
rarch_main_state_deinit();
g_runloop = rarch_main_state_init();