From a1a4bc405725d89e1702d748700354ff7938332c Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 8 Jul 2015 20:04:16 +0200 Subject: [PATCH] task_file_transfer.c - decouple 'nbio' state from runloop data struct --- runloop_data.c | 25 +++++++++++----- runloop_data.h | 3 +- tasks/task_file_transfer.c | 61 ++++++++++++++++++++++++++++++++------ tasks/tasks.h | 12 ++++++++ 4 files changed, 84 insertions(+), 17 deletions(-) diff --git a/runloop_data.c b/runloop_data.c index 777946178c..29240abc11 100644 --- a/runloop_data.c +++ b/runloop_data.c @@ -88,6 +88,8 @@ void rarch_main_data_free(void) { data_runloop_t *runloop = rarch_main_data_get_ptr(); + rarch_main_data_nbio_uninit(); + if (runloop) free(runloop); runloop = NULL; @@ -119,7 +121,7 @@ bool rarch_main_data_active(data_runloop_t *runloop) bool db_active = false; driver_t *driver = driver_get_ptr(); - nbio_handle_t *nbio = runloop ? &runloop->nbio : NULL; + nbio_handle_t *nbio = (nbio_handle_t*)rarch_main_data_nbio_get_ptr(); #ifdef HAVE_RPNG nbio_image_handle_t *image = nbio ? &nbio->image : NULL; #endif @@ -297,6 +299,7 @@ static data_runloop_t *rarch_main_data_new(void) runloop->inited = true; + return runloop; } @@ -305,8 +308,14 @@ void rarch_main_data_clear_state(void) rarch_main_data_deinit(); rarch_main_data_free(); g_data_runloop = rarch_main_data_new(); + + if (!g_data_runloop) + return; + + rarch_main_data_nbio_init(); } + void rarch_main_data_init_queues(void) { data_runloop_t *runloop = rarch_main_data_get_ptr(); @@ -314,16 +323,14 @@ void rarch_main_data_init_queues(void) if (!runloop->http.msg_queue) rarch_assert(runloop->http.msg_queue = msg_queue_new(8)); #endif - if (!runloop->nbio.msg_queue) - rarch_assert(runloop->nbio.msg_queue = msg_queue_new(8)); - if (!runloop->nbio.image.msg_queue) - rarch_assert(runloop->nbio.image.msg_queue = msg_queue_new(8)); + rarch_main_data_nbio_init_msg_queue(); #ifdef HAVE_LIBRETRODB if (!runloop->db.msg_queue) rarch_assert(runloop->db.msg_queue = msg_queue_new(8)); #endif } + void rarch_main_data_msg_queue_push(unsigned type, const char *msg, const char *msg2, unsigned prio, unsigned duration, bool flush) @@ -337,11 +344,15 @@ void rarch_main_data_msg_queue_push(unsigned type, case DATA_TYPE_NONE: break; case DATA_TYPE_FILE: - queue = runloop->nbio.msg_queue; + queue = rarch_main_data_nbio_get_msg_queue_ptr(); + if (!queue) + return; snprintf(new_msg, sizeof(new_msg), "%s|%s", msg, msg2); break; case DATA_TYPE_IMAGE: - queue = runloop->nbio.image.msg_queue; + queue = rarch_main_data_nbio_image_get_msg_queue_ptr(); + if (!queue) + return; snprintf(new_msg, sizeof(new_msg), "%s|%s", msg, msg2); break; #ifdef HAVE_NETWORKING diff --git a/runloop_data.h b/runloop_data.h index c08e56314f..66bf57cbce 100644 --- a/runloop_data.h +++ b/runloop_data.h @@ -151,7 +151,6 @@ typedef struct data_runloop db_handle_t db; #endif - nbio_handle_t nbio; bool inited; #ifdef HAVE_THREADS @@ -181,6 +180,8 @@ void rarch_main_data_free(void); void rarch_main_data_init_queues(void); +void rarch_main_data_init(void); + bool rarch_main_data_active(data_runloop_t *runloop); data_runloop_t *rarch_main_data_get_ptr(void); diff --git a/tasks/task_file_transfer.c b/tasks/task_file_transfer.c index 18ac99d795..6ba99b533b 100644 --- a/tasks/task_file_transfer.c +++ b/tasks/task_file_transfer.c @@ -21,12 +21,34 @@ #include #include -#include "../runloop_data.h" #include "tasks.h" #define CB_MENU_WALLPAPER 0xb476e505U #define CB_MENU_BOXART 0x68b307cdU +static nbio_handle_t *nbio_ptr; + +void *rarch_main_data_nbio_get_ptr(void) +{ + return nbio_ptr; +} + +msg_queue_t *rarch_main_data_nbio_get_msg_queue_ptr(void) +{ + nbio_handle_t *nbio = rarch_main_data_nbio_get_ptr(); + if (!nbio) + return NULL; + return nbio->msg_queue; +} + +msg_queue_t *rarch_main_data_nbio_image_get_msg_queue_ptr(void) +{ + nbio_handle_t *nbio = rarch_main_data_nbio_get_ptr(); + if (!nbio) + return NULL; + return nbio->image.msg_queue; +} + #ifdef HAVE_MENU #include "../menu/menu_driver.h" @@ -252,8 +274,7 @@ static int rarch_main_data_image_iterate_transfer_parse(nbio_handle_t *nbio) void rarch_main_data_nbio_image_iterate(bool is_thread, void *data) { - data_runloop_t *runloop = (data_runloop_t*)data; - nbio_handle_t *nbio = runloop ? &runloop->nbio : NULL; + nbio_handle_t *nbio = rarch_main_data_nbio_get_ptr(); nbio_image_handle_t *image = nbio ? &nbio->image : NULL; if (!image || !nbio) @@ -288,11 +309,10 @@ void rarch_main_data_nbio_image_iterate(bool is_thread, void *data) void rarch_main_data_nbio_image_upload_iterate(bool is_thread, void *data) { - data_runloop_t *runloop = (data_runloop_t*)data; - nbio_handle_t *nbio = runloop ? &runloop->nbio : NULL; + nbio_handle_t *nbio = rarch_main_data_nbio_get_ptr(); nbio_image_handle_t *image = nbio ? &nbio->image : NULL; - if (!image || !nbio || !runloop) + if (!image || !nbio) return; (void)is_thread; @@ -529,9 +549,8 @@ static int rarch_main_data_nbio_iterate_parse(nbio_handle_t *nbio) void rarch_main_data_nbio_iterate(bool is_thread, void *data) { - data_runloop_t *runloop = (data_runloop_t*)data; - nbio_handle_t *nbio = runloop ? &runloop->nbio : NULL; - if (!nbio || !runloop) + nbio_handle_t *nbio = rarch_main_data_nbio_get_ptr(); + if (!nbio) return; switch (nbio->status) @@ -555,3 +574,27 @@ void rarch_main_data_nbio_iterate(bool is_thread, void *data) break; } } + +void rarch_main_data_nbio_init_msg_queue(void) +{ + nbio_handle_t *nbio = rarch_main_data_nbio_get_ptr(); + if (!nbio) + return; + + if (!nbio->msg_queue) + rarch_assert(nbio->msg_queue = msg_queue_new(8)); + if (!nbio->image.msg_queue) + rarch_assert(nbio->image.msg_queue = msg_queue_new(8)); +} + +void rarch_main_data_nbio_uninit(void) +{ + if (nbio_ptr) + free(nbio_ptr); + nbio_ptr = NULL; +} + +void rarch_main_data_nbio_init(void) +{ + nbio_ptr = (nbio_handle_t*)calloc(1, sizeof(*nbio_ptr)); +} diff --git a/tasks/tasks.h b/tasks/tasks.h index f7ae231c98..9301c3c940 100644 --- a/tasks/tasks.h +++ b/tasks/tasks.h @@ -24,6 +24,18 @@ extern "C" { #endif +void rarch_main_data_nbio_uninit(void); + +void rarch_main_data_nbio_init(void); + +void rarch_main_data_nbio_init_msg_queue(void); + +msg_queue_t *rarch_main_data_nbio_get_msg_queue_ptr(void); + +msg_queue_t *rarch_main_data_nbio_image_get_msg_queue_ptr(void); + +void *rarch_main_data_nbio_get_ptr(void); + #ifdef HAVE_NETWORKING /** * rarch_main_data_http_iterate_transfer: