From b673321322941f4bb84332f94487c5c701020237 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 22 Feb 2015 08:24:10 +0100 Subject: [PATCH] (nbio interface) Don't immediately free data buffer of nbio handle - in the case of images we need to retain this data buffer until it's time to free it. We set nbio_handle->is_blocking to true to indicate to the nbio interface that we want to 'block' on the nbio interface (i.e. don't free, iterate or create a new nbio transfer). If nbio_handle->is_finished is set to true, we cleanup and free the nbio transfer handle. --- general.h | 2 ++ runloop.c | 32 +++++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/general.h b/general.h index 4a8c3ba8c1..43bde3bb9a 100644 --- a/general.h +++ b/general.h @@ -594,6 +594,8 @@ struct global struct { + bool is_blocking; + bool is_finished; transfer_cb_t cb; struct nbio_t *handle; msg_queue_t *msg_queue; diff --git a/runloop.c b/runloop.c index f2e25c6cc2..dca6f64a3a 100644 --- a/runloop.c +++ b/runloop.c @@ -888,6 +888,21 @@ static int rarch_main_iterate_nbio_transfer(void) return 0; } +static int rarch_main_iterate_nbio_parse_free(void) +{ + if (!g_extern.nbio.is_finished) + return -1; + + nbio_free(g_extern.nbio.handle); + g_extern.nbio.handle = NULL; + g_extern.nbio.is_blocking = false; + g_extern.nbio.is_finished = false; + + msg_queue_clear(g_extern.nbio.msg_queue); + + return 0; +} + static int rarch_main_iterate_nbio_parse(void) { size_t len; @@ -896,11 +911,6 @@ static int rarch_main_iterate_nbio_parse(void) if (data && g_extern.nbio.cb) g_extern.nbio.cb(data, len); - nbio_free(g_extern.nbio.handle); - g_extern.nbio.handle = NULL; - - msg_queue_clear(g_extern.nbio.msg_queue); - return 0; } @@ -1026,6 +1036,9 @@ static int cb_nbio_default(void *data, size_t len) (void)data; (void)len; + g_extern.nbio.is_blocking = false; + g_extern.nbio.is_finished = true; + return 0; } @@ -1211,8 +1224,13 @@ int rarch_main_iterate(void) if (g_extern.nbio.handle) { - if (!rarch_main_iterate_nbio_transfer()) - rarch_main_iterate_nbio_parse(); + if (!g_extern.nbio.is_blocking) + { + if (!rarch_main_iterate_nbio_transfer()) + rarch_main_iterate_nbio_parse(); + } + else if (g_extern.nbio.is_finished) + rarch_main_iterate_nbio_parse_free(); } else rarch_main_iterate_nbio_poll();