summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorFranklin Wei <franklin@rockbox.org>2019-08-02 22:54:52 -0400
committerFranklin Wei <franklin@rockbox.org>2019-08-03 05:05:35 +0200
commit7ba2ef566e1de4046c75b160bf6ea5aa4a087a32 (patch)
tree1b46235deb99067577c524850cb8a31ad7b060de /apps
parentfee68fc612a3c6c67c55aa194223002bdfda7261 (diff)
sdl: use mutex in printf()
This prevents lines of output being overwritten by different threads. Change-Id: I24cee52238b53c8a4b2536e082bb4bcd103d8d60
Diffstat (limited to 'apps')
-rw-r--r--apps/plugins/sdl/wrappers.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/apps/plugins/sdl/wrappers.c b/apps/plugins/sdl/wrappers.c
index 02e9db1992..efa29ea7b8 100644
--- a/apps/plugins/sdl/wrappers.c
+++ b/apps/plugins/sdl/wrappers.c
@@ -333,11 +333,24 @@ int fscanf_wrapper(FILE *f, const char *fmt, ...)
return 1;
}
+
/* stolen from doom */
// Here is a hacked up printf command to get the output from the game.
int printf_wrapper(const char *fmt, ...)
{
- static int p_xtpt;
+ static volatile struct mutex printf_mutex;
+ static volatile int mutex_init = 0;
+
+ if(!mutex_init)
+ {
+ rb->mutex_init(&printf_mutex);
+ mutex_init = 1;
+ }
+
+ static volatile int p_xtpt;
+
+ rb->mutex_lock(&printf_mutex);
+
char p_buf[256];
rb->yield();
va_list ap;
@@ -362,6 +375,9 @@ int printf_wrapper(const char *fmt, ...)
rb->lcd_clear_display();
}
}
+
+ rb->mutex_unlock(&printf_mutex);
+
return 1;
}