Use crude ref-counting for driver handles.

This commit is contained in:
Themaister 2012-12-25 23:18:19 +01:00
parent 4e61543203
commit e3378c219c
3 changed files with 26 additions and 3 deletions

View File

@ -207,9 +207,6 @@ void engine_handle_cmd(struct android_app* android_app, int32_t cmd)
if(g_extern.lifecycle_state & (1ULL << RARCH_REENTRANT))
{
uninit_drivers();
driver.video_data = NULL;
driver.audio_data = NULL;
driver.input_data = NULL;
g_android.window_ready = false;
}

View File

@ -254,6 +254,10 @@ void driver_set_monitor_refresh_rate(float hz)
void init_drivers(void)
{
driver.video_data_own = !driver.video_data;
driver.audio_data_own = !driver.audio_data;
driver.input_data_own = !driver.input_data;
adjust_system_rates();
init_video_input();
@ -264,6 +268,17 @@ void uninit_drivers(void)
{
uninit_audio();
uninit_video_input();
if (driver.video_data_own)
driver.video_data = NULL;
if (driver.audio_data_own)
driver.audio_data = NULL;
if (driver.input_data_own)
driver.input_data = NULL;
driver.video_data_own = false;
driver.audio_data_own = false;
driver.input_data_own = false;
}
#ifdef HAVE_DYLIB

View File

@ -267,6 +267,17 @@ typedef struct driver
void *video_data;
void *input_data;
// Set if the respective handles are owned by RetroArch driver core.
// Consoles upper logic will generally intialize the drivers before
// the driver core initializes. It will then be up to upper logic
// to finally free() up the driver handles.
// Driver core will still call init() and free(), but in this case
// these calls should be seen as "reinit() + ref_count++" and "ref_count--"
// respectively.
bool video_data_own;
bool audio_data_own;
bool input_data_own;
#ifdef HAVE_COMMAND
rarch_cmd_t *command;
#endif