Create runloop_msg.c

This commit is contained in:
twinaphex 2015-07-01 01:19:14 +02:00
parent fab966d768
commit b96e02db75
5 changed files with 101 additions and 89 deletions

View File

@ -115,6 +115,7 @@ OBJ += frontend/frontend.o \
command_event.o \
runloop.o \
runloop_data.o \
runloop_msg.o \
tasks/task_file_transfer.o \
content.o \
libretro-common/file/file_list.o \

View File

@ -668,6 +668,7 @@ RETROARCH
#include "../retroarch_info.c"
#include "../runloop.c"
#include "../runloop_data.c"
#include "../runloop_msg.c"
#include "../system.c"

View File

@ -45,10 +45,6 @@
static struct runloop *g_runloop = NULL;
static struct global *g_extern = NULL;
#ifdef HAVE_THREADS
static slock_t *mq_lock = NULL;
#endif
/**
* check_pause:
* @pressed : was libretro pause key pressed?
@ -872,88 +868,6 @@ static void rarch_main_iterate_linefeed_overlay(void)
}
#endif
const char *rarch_main_msg_queue_pull(void)
{
runloop_t *runloop = rarch_main_get_ptr();
const char *ret = NULL;
if (!runloop)
return NULL;
#ifdef HAVE_THREADS
slock_lock(mq_lock);
#endif
ret = msg_queue_pull(runloop->msg_queue);
#ifdef HAVE_THREADS
slock_unlock(mq_lock);
#endif
return ret;
}
void rarch_main_msg_queue_push(const char *msg, unsigned prio, unsigned duration,
bool flush)
{
runloop_t *runloop = rarch_main_get_ptr();
if (!runloop->msg_queue)
return;
#ifdef HAVE_THREADS
slock_lock(mq_lock);
#endif
if (flush)
msg_queue_clear(runloop->msg_queue);
msg_queue_push(runloop->msg_queue, msg, prio, duration);
#ifdef HAVE_THREADS
slock_unlock(mq_lock);
#endif
}
void rarch_main_msg_queue_free(void)
{
runloop_t *runloop = rarch_main_get_ptr();
if (!runloop)
return;
if (runloop->msg_queue)
{
#ifdef HAVE_THREADS
slock_lock(mq_lock);
#endif
msg_queue_free(runloop->msg_queue);
#ifdef HAVE_THREADS
slock_unlock(mq_lock);
slock_free(mq_lock);
#endif
}
runloop->msg_queue = NULL;
}
void rarch_main_msg_queue_init(void)
{
runloop_t *runloop = rarch_main_get_ptr();
if (!runloop)
return;
if (!runloop->msg_queue)
{
runloop->msg_queue = msg_queue_new(8);
rarch_assert(runloop->msg_queue);
#ifdef HAVE_THREADS
mq_lock = slock_new();
rarch_assert(mq_lock);
#endif
}
}
global_t *global_get_ptr(void)
{
return g_extern;

View File

@ -16,7 +16,6 @@
#ifndef __RETROARCH_RUNLOOP_H
#define __RETROARCH_RUNLOOP_H
#include <queues/message_queue.h>
#include <setjmp.h>
#include "libretro.h"
#include "core_info.h"
@ -56,8 +55,6 @@ typedef struct runloop
retro_time_t last_time;
} limit;
} frames;
msg_queue_t *msg_queue;
} runloop_t;
typedef struct rarch_resolution

99
runloop_msg.c Normal file
View File

@ -0,0 +1,99 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
#include <queues/message_queue.h>
#ifdef HAVE_THREADS
#include <rthreads/rthreads.h>
#endif
#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(const char *msg, unsigned prio, unsigned duration,
bool flush)
{
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
}
void rarch_main_msg_queue_free(void)
{
if (g_msg_queue)
{
#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)
{
g_msg_queue = msg_queue_new(8);
rarch_assert(g_msg_queue);
#ifdef HAVE_THREADS
mq_lock = slock_new();
rarch_assert(mq_lock);
#endif
}
}