mirror of
https://github.com/libretro/RetroArch
synced 2025-03-30 07:20:36 +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';
|
||||
|
||||
if ( video_info.font_enable
|
||||
&& runloop_msg_queue_pull((const char**)&msg)
|
||||
&& runloop_msg_queue_pull((const char**)&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));
|
||||
#ifdef HAVE_THREADS
|
||||
runloop_msg_queue_unlock();
|
||||
#endif
|
||||
}
|
||||
|
||||
video_driver_active = current_video->frame(
|
||||
video_driver_data, data, width, height,
|
||||
|
35
retroarch.c
35
retroarch.c
@ -48,7 +48,6 @@
|
||||
#include <retro_miscellaneous.h>
|
||||
#include <queues/message_queue.h>
|
||||
#include <queues/task_queue.h>
|
||||
#include <rthreads/rthreads.h>
|
||||
#include <features/features_cpu.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;
|
||||
|
||||
#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)
|
||||
{
|
||||
#ifdef HAVE_THREADS
|
||||
runloop_msg_queue_lock();
|
||||
#endif
|
||||
|
||||
if (!runloop_msg_queue)
|
||||
return;
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
slock_lock(_runloop_msg_queue_lock);
|
||||
#endif
|
||||
|
||||
msg_queue_free(runloop_msg_queue);
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
slock_unlock(_runloop_msg_queue_lock);
|
||||
runloop_msg_queue_unlock();
|
||||
slock_free(_runloop_msg_queue_lock);
|
||||
_runloop_msg_queue_lock = NULL;
|
||||
#endif
|
||||
@ -2227,7 +2238,7 @@ void runloop_msg_queue_push(const char *msg,
|
||||
runloop_ctx_msg_info_t msg_info;
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
slock_lock(_runloop_msg_queue_lock);
|
||||
runloop_msg_queue_lock();
|
||||
#endif
|
||||
|
||||
if (flush)
|
||||
@ -2253,7 +2264,7 @@ void runloop_msg_queue_push(const char *msg,
|
||||
}
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
slock_unlock(_runloop_msg_queue_lock);
|
||||
runloop_msg_queue_unlock();
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -2269,14 +2280,14 @@ void runloop_get_status(bool *is_paused, bool *is_idle,
|
||||
|
||||
bool runloop_msg_queue_pull(const char **ret)
|
||||
{
|
||||
#ifdef HAVE_THREADS
|
||||
runloop_msg_queue_lock();
|
||||
#endif
|
||||
if (!ret)
|
||||
return false;
|
||||
#ifdef HAVE_THREADS
|
||||
slock_lock(_runloop_msg_queue_lock);
|
||||
#endif
|
||||
*ret = msg_queue_pull(runloop_msg_queue);
|
||||
#ifdef HAVE_THREADS
|
||||
slock_unlock(_runloop_msg_queue_lock);
|
||||
runloop_msg_queue_unlock();
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <retro_common_api.h>
|
||||
#include <retro_inline.h>
|
||||
#include <boolean.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);
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
void runloop_msg_queue_lock(void);
|
||||
|
||||
void runloop_msg_queue_unlock(void);
|
||||
#endif
|
||||
|
||||
RETRO_END_DECLS
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user