Add cleanup handler for tasks to free allocated resources after the task finished.

This commit is contained in:
Torsten Paul 2016-05-22 22:27:58 +02:00
parent 4c3281bd39
commit 845dcef6ab
3 changed files with 8 additions and 0 deletions

View File

@ -123,6 +123,10 @@ struct retro_task
/* always called from the main loop */
retro_task_callback_t callback;
/* task cleanup handler to free allocated resources, will
* be called immediately after running the main callback */
retro_task_handler_t cleanup;
/* set to true by the handler to signal
* the task has finished executing. */
bool finished;

View File

@ -126,6 +126,9 @@ static void retro_task_internal_gather(void)
if (task->callback)
task->callback(task->task_data, task->user_data, task->error);
if (task->cleanup)
task->cleanup(task);
if (task->error)
free(task->error);

View File

@ -383,6 +383,7 @@ bool rarch_task_push_image_load(const char *fullpath,
t->state = nbio;
t->handler = rarch_task_file_load_handler;
t->cleanup = rarch_task_image_load_free;
t->callback = cb;
t->user_data = user_data;