diff --git a/Makefile.common b/Makefile.common index ceb4ebde0f..e8dbfc7b03 100644 --- a/Makefile.common +++ b/Makefile.common @@ -123,7 +123,6 @@ OBJ += frontend/frontend.o \ intl/msg_hash_us.o \ runloop.o \ runloop_data.o \ - runloop_msg.o \ tasks/tasks.o \ tasks/task_file_transfer.o \ content.o \ diff --git a/griffin/griffin.c b/griffin/griffin.c index 9cc2e1e2fa..e4a71dd612 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -698,7 +698,6 @@ RETROARCH #include "../retroarch.c" #include "../runloop.c" #include "../runloop_data.c" -#include "../runloop_msg.c" #include "../system.c" #include "../tasks/tasks.c" diff --git a/runloop.c b/runloop.c index 7ee7f02455..7284424847 100644 --- a/runloop.c +++ b/runloop.c @@ -16,10 +16,16 @@ * If not, see . */ +#include #include #include #include +#include +#include +#ifdef HAVE_THREADS +#include +#endif #include @@ -60,6 +66,114 @@ static unsigned main_max_frames; static retro_time_t frame_limit_last_time; static retro_time_t frame_limit_minimum_time; +static msg_queue_t *g_msg_queue; + +#ifdef HAVE_THREADS +static slock_t *mq_lock = NULL; +#endif + +const char *rarch_main_msg_queue_pull(void) +{ + const char *ret = NULL; + +#ifdef HAVE_THREADS + slock_lock(mq_lock); +#endif + + ret = msg_queue_pull(g_msg_queue); + +#ifdef HAVE_THREADS + slock_unlock(mq_lock); +#endif + + return ret; +} + +void rarch_main_msg_queue_push_new(uint32_t hash, unsigned prio, unsigned duration, + bool flush) +{ + const char *msg = msg_hash_to_str(hash); + + if (!msg) + return; + + rarch_main_msg_queue_push(msg, prio, duration, flush); +} + +void rarch_main_msg_queue_push(const char *msg, unsigned prio, unsigned duration, + bool flush) +{ + settings_t *settings; + settings = config_get_ptr(); + if(!settings->video.font_enable) + return; + if (!g_msg_queue) + return; + +#ifdef HAVE_THREADS + slock_lock(mq_lock); +#endif + + if (flush) + msg_queue_clear(g_msg_queue); + msg_queue_push(g_msg_queue, msg, prio, duration); + +#ifdef HAVE_THREADS + slock_unlock(mq_lock); +#endif + + if (ui_companion_is_on_foreground()) + { + const ui_companion_driver_t *ui = ui_companion_get_ptr(); + if (ui->msg_queue_push) + ui->msg_queue_push(msg, prio, duration, flush); + } +} + +void rarch_main_msg_queue_pushf(unsigned prio, unsigned duration, + bool flush, const char *fmt, ...) +{ + char buf[1024]; + va_list ap; + va_start(ap, fmt); + vsnprintf(buf, sizeof(buf), fmt, ap); + va_end(ap); + rarch_main_msg_queue_push(buf, prio, duration, flush); +} + +static void rarch_main_msg_queue_free(void) +{ + if (!g_msg_queue) + return; + +#ifdef HAVE_THREADS + slock_lock(mq_lock); +#endif + + msg_queue_free(g_msg_queue); + +#ifdef HAVE_THREADS + slock_unlock(mq_lock); + slock_free(mq_lock); +#endif + + g_msg_queue = NULL; +} + +static void rarch_main_msg_queue_init(void) +{ + if (g_msg_queue) + return; + + g_msg_queue = msg_queue_new(8); + retro_assert(g_msg_queue); + +#ifdef HAVE_THREADS + mq_lock = slock_new(); + retro_assert(mq_lock); +#endif +} + static bool check_focus(settings_t *settings) { if (settings->pause_nonactive) diff --git a/runloop.h b/runloop.h index 48fef02493..c286df9825 100644 --- a/runloop.h +++ b/runloop.h @@ -356,10 +356,6 @@ void rarch_main_msg_queue_push_new(uint32_t hash, unsigned prio, const char *rarch_main_msg_queue_pull(void); -void rarch_main_msg_queue_free(void); - -void rarch_main_msg_queue_init(void); - bool rarch_main_ctl(enum rarch_main_ctl_state state, void *data); #ifdef __cplusplus diff --git a/runloop_msg.c b/runloop_msg.c index 8c501920f3..e69de29bb2 100644 --- a/runloop_msg.c +++ b/runloop_msg.c @@ -1,136 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2010-2014 - Hans-Kristian Arntzen - * Copyright (C) 2011-2015 - Daniel De Matteis - * Copyright (C) 2012-2015 - Michael Lelli - * Copyright (C) 2014-2015 - Jay McCarthy - * - * RetroArch is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with RetroArch. - * If not, see . - */ - -#include - -#include -#include -#ifdef HAVE_THREADS -#include -#endif - -#include "msg_hash.h" -#include "runloop.h" - -static msg_queue_t *g_msg_queue; - -#ifdef HAVE_THREADS -static slock_t *mq_lock = NULL; -#endif - -const char *rarch_main_msg_queue_pull(void) -{ - const char *ret = NULL; - -#ifdef HAVE_THREADS - slock_lock(mq_lock); -#endif - - ret = msg_queue_pull(g_msg_queue); - -#ifdef HAVE_THREADS - slock_unlock(mq_lock); -#endif - - return ret; -} - -void rarch_main_msg_queue_push_new(uint32_t hash, unsigned prio, unsigned duration, - bool flush) -{ - const char *msg = msg_hash_to_str(hash); - - if (!msg) - return; - - rarch_main_msg_queue_push(msg, prio, duration, flush); -} - -void rarch_main_msg_queue_push(const char *msg, unsigned prio, unsigned duration, - bool flush) -{ - settings_t *settings; - settings = config_get_ptr(); - if(!settings->video.font_enable) - return; - if (!g_msg_queue) - return; - -#ifdef HAVE_THREADS - slock_lock(mq_lock); -#endif - - if (flush) - msg_queue_clear(g_msg_queue); - msg_queue_push(g_msg_queue, msg, prio, duration); - -#ifdef HAVE_THREADS - slock_unlock(mq_lock); -#endif - - if (ui_companion_is_on_foreground()) - { - const ui_companion_driver_t *ui = ui_companion_get_ptr(); - if (ui->msg_queue_push) - ui->msg_queue_push(msg, prio, duration, flush); - } -} - -void rarch_main_msg_queue_pushf(unsigned prio, unsigned duration, - bool flush, const char *fmt, ...) -{ - char buf[1024]; - va_list ap; - va_start(ap, fmt); - vsnprintf(buf, sizeof(buf), fmt, ap); - va_end(ap); - rarch_main_msg_queue_push(buf, prio, duration, flush); -} - -void rarch_main_msg_queue_free(void) -{ - if (!g_msg_queue) - return; - -#ifdef HAVE_THREADS - slock_lock(mq_lock); -#endif - - msg_queue_free(g_msg_queue); - -#ifdef HAVE_THREADS - slock_unlock(mq_lock); - slock_free(mq_lock); -#endif - - g_msg_queue = NULL; -} - -void rarch_main_msg_queue_init(void) -{ - if (g_msg_queue) - return; - - g_msg_queue = msg_queue_new(8); - retro_assert(g_msg_queue); - -#ifdef HAVE_THREADS - mq_lock = slock_new(); - retro_assert(mq_lock); -#endif -}