Skip to content

Commit

Permalink
feat(printf): add atomic_printf (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang-Haojin authored Dec 26, 2024
1 parent 74bbc7f commit c5d690d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 6 additions & 0 deletions libs/klib/include/printf.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ void _putchar(char character);
#define printf printf_
int printf_(const char* format, ...);

/**
* Atomic version of printf
*/
#define atomic_printf atomic_printf_
int atomic_printf_(const char* format, ...);


/**
* Tiny sprintf implementation
Expand Down
17 changes: 16 additions & 1 deletion libs/klib/src/printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -859,10 +859,20 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const

///////////////////////////////////////////////////////////////////////////////
#ifndef NOPRINT
int printf_(const char* format, ...)
{
va_list va;
va_start(va, format);
char buffer[1];
const int ret = _vsnprintf(_out_char, buffer, (size_t)-1, format, va);
va_end(va);
return ret;
}

void lock(volatile uint64_t *);
void release(volatile uint64_t *);
volatile uint64_t print_lock = 0;
int printf_(const char* format, ...)
int atomic_printf_(const char* format, ...)
{
va_list va;
lock(&print_lock);
Expand All @@ -878,6 +888,11 @@ int printf_(const char* format, ...)
{
return 0;
}

int atomic_printf_(const char *format, ...)
{
return 0;
}
#endif


Expand Down

0 comments on commit c5d690d

Please sign in to comment.