mirror of
https://github.com/libretro/RetroArch
synced 2025-04-10 06:44:27 +00:00
fix race condition reading OSD message in video driver
This commit is contained in:
parent
ade710a331
commit
fc856c76a8
@ -2380,9 +2380,18 @@ void video_driver_frame(const void *data, unsigned width,
|
|||||||
video_driver_msg[0] = '\0';
|
video_driver_msg[0] = '\0';
|
||||||
|
|
||||||
if ( video_info.font_enable
|
if ( video_info.font_enable
|
||||||
&& runloop_msg_queue_pull((const char**)&msg)
|
&& runloop_msg_queue_pull((const char**)&msg)
|
||||||
&& msg)
|
&& msg)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_THREADS
|
||||||
|
/* the msg pointer may point to data modified by another thread */
|
||||||
|
runloop_msg_queue_lock();
|
||||||
|
#endif
|
||||||
strlcpy(video_driver_msg, msg, sizeof(video_driver_msg));
|
strlcpy(video_driver_msg, msg, sizeof(video_driver_msg));
|
||||||
|
#ifdef HAVE_THREADS
|
||||||
|
runloop_msg_queue_unlock();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
video_driver_active = current_video->frame(
|
video_driver_active = current_video->frame(
|
||||||
video_driver_data, data, width, height,
|
video_driver_data, data, width, height,
|
||||||
|
35
retroarch.c
35
retroarch.c
@ -48,7 +48,6 @@
|
|||||||
#include <retro_miscellaneous.h>
|
#include <retro_miscellaneous.h>
|
||||||
#include <queues/message_queue.h>
|
#include <queues/message_queue.h>
|
||||||
#include <queues/task_queue.h>
|
#include <queues/task_queue.h>
|
||||||
#include <rthreads/rthreads.h>
|
|
||||||
#include <features/features_cpu.h>
|
#include <features/features_cpu.h>
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
@ -249,19 +248,31 @@ static retro_time_t frame_limit_last_time = 0.0;
|
|||||||
|
|
||||||
extern bool input_driver_flushing_input;
|
extern bool input_driver_flushing_input;
|
||||||
|
|
||||||
|
#ifdef HAVE_THREADS
|
||||||
|
void runloop_msg_queue_lock(void)
|
||||||
|
{
|
||||||
|
slock_lock(_runloop_msg_queue_lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
void runloop_msg_queue_unlock(void)
|
||||||
|
{
|
||||||
|
slock_unlock(_runloop_msg_queue_lock);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void retroarch_msg_queue_deinit(void)
|
static void retroarch_msg_queue_deinit(void)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_THREADS
|
||||||
|
runloop_msg_queue_lock();
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!runloop_msg_queue)
|
if (!runloop_msg_queue)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#ifdef HAVE_THREADS
|
|
||||||
slock_lock(_runloop_msg_queue_lock);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
msg_queue_free(runloop_msg_queue);
|
msg_queue_free(runloop_msg_queue);
|
||||||
|
|
||||||
#ifdef HAVE_THREADS
|
#ifdef HAVE_THREADS
|
||||||
slock_unlock(_runloop_msg_queue_lock);
|
runloop_msg_queue_unlock();
|
||||||
slock_free(_runloop_msg_queue_lock);
|
slock_free(_runloop_msg_queue_lock);
|
||||||
_runloop_msg_queue_lock = NULL;
|
_runloop_msg_queue_lock = NULL;
|
||||||
#endif
|
#endif
|
||||||
@ -2227,7 +2238,7 @@ void runloop_msg_queue_push(const char *msg,
|
|||||||
runloop_ctx_msg_info_t msg_info;
|
runloop_ctx_msg_info_t msg_info;
|
||||||
|
|
||||||
#ifdef HAVE_THREADS
|
#ifdef HAVE_THREADS
|
||||||
slock_lock(_runloop_msg_queue_lock);
|
runloop_msg_queue_lock();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (flush)
|
if (flush)
|
||||||
@ -2253,7 +2264,7 @@ void runloop_msg_queue_push(const char *msg,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_THREADS
|
#ifdef HAVE_THREADS
|
||||||
slock_unlock(_runloop_msg_queue_lock);
|
runloop_msg_queue_unlock();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2269,14 +2280,14 @@ void runloop_get_status(bool *is_paused, bool *is_idle,
|
|||||||
|
|
||||||
bool runloop_msg_queue_pull(const char **ret)
|
bool runloop_msg_queue_pull(const char **ret)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_THREADS
|
||||||
|
runloop_msg_queue_lock();
|
||||||
|
#endif
|
||||||
if (!ret)
|
if (!ret)
|
||||||
return false;
|
return false;
|
||||||
#ifdef HAVE_THREADS
|
|
||||||
slock_lock(_runloop_msg_queue_lock);
|
|
||||||
#endif
|
|
||||||
*ret = msg_queue_pull(runloop_msg_queue);
|
*ret = msg_queue_pull(runloop_msg_queue);
|
||||||
#ifdef HAVE_THREADS
|
#ifdef HAVE_THREADS
|
||||||
slock_unlock(_runloop_msg_queue_lock);
|
runloop_msg_queue_unlock();
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <retro_common_api.h>
|
#include <retro_common_api.h>
|
||||||
|
#include <retro_inline.h>
|
||||||
#include <boolean.h>
|
#include <boolean.h>
|
||||||
|
|
||||||
#include "core_type.h"
|
#include "core_type.h"
|
||||||
@ -349,6 +350,12 @@ bool retroarch_is_on_main_thread(void);
|
|||||||
|
|
||||||
rarch_system_info_t *runloop_get_system_info(void);
|
rarch_system_info_t *runloop_get_system_info(void);
|
||||||
|
|
||||||
|
#ifdef HAVE_THREADS
|
||||||
|
void runloop_msg_queue_lock(void);
|
||||||
|
|
||||||
|
void runloop_msg_queue_unlock(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
RETRO_END_DECLS
|
RETRO_END_DECLS
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user