snprintf: lockless operation
Instead of having global variables put them on the stack. Change-Id: I462e3b245612ff2dfb077da1cbcc5ac88f8b8e48 Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com> Reviewed-on: http://review.coreboot.org/4288 Reviewed-by: Ronald G. Minnich <rminnich@gmail.com> Tested-by: build bot (Jenkins)
This commit is contained in:
parent
f421b33edb
commit
2267658db4
|
@ -20,32 +20,32 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <smp/spinlock.h>
|
|
||||||
#include <console/vtxprintf.h>
|
#include <console/vtxprintf.h>
|
||||||
#include <trace.h>
|
#include <trace.h>
|
||||||
|
|
||||||
DECLARE_SPIN_LOCK(vsprintf_lock)
|
struct vsprintf_context
|
||||||
|
|
||||||
static char *str_buf;
|
|
||||||
|
|
||||||
static void str_tx_byte(unsigned char byte)
|
|
||||||
{
|
{
|
||||||
*str_buf = byte;
|
char *str_buf;
|
||||||
str_buf++;
|
};
|
||||||
|
|
||||||
|
static void str_tx_byte(unsigned char byte, void *data)
|
||||||
|
{
|
||||||
|
struct vsprintf_context *ctx = data;
|
||||||
|
*ctx->str_buf = byte;
|
||||||
|
ctx->str_buf++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vsprintf(char *buf, const char *fmt, va_list args)
|
static int vsprintf(char *buf, const char *fmt, va_list args)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
struct vsprintf_context ctx;
|
||||||
|
|
||||||
DISABLE_TRACE;
|
DISABLE_TRACE;
|
||||||
spin_lock(&vsprintf_lock);
|
|
||||||
|
|
||||||
str_buf = buf;
|
ctx.str_buf = buf;
|
||||||
i = vtxprintf(str_tx_byte, fmt, args);
|
i = vtxdprintf(str_tx_byte, fmt, args, &ctx);
|
||||||
*str_buf = '\0';
|
*ctx.str_buf = '\0';
|
||||||
|
|
||||||
spin_unlock(&vsprintf_lock);
|
|
||||||
ENABLE_TRACE;
|
ENABLE_TRACE;
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
|
|
Loading…
Reference in New Issue