lib: os: printk: Minor refactoring

Refactoring to remove code redundancy caused by splitted
handling based on USERSPACE enabled.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruscinski 2022-01-19 07:31:25 +01:00 committed by Carles Cufí
commit 09fef8e7d2

View file

@ -22,6 +22,11 @@
#include <sys/cbprintf.h>
#include <sys/types.h>
/* Option present only when CONFIG_USERSPACE enabled. */
#ifndef CONFIG_PRINTK_BUFFER_SIZE
#define CONFIG_PRINTK_BUFFER_SIZE 0
#endif
#if defined(CONFIG_PRINTK_SYNC) && \
!(defined(CONFIG_LOG_PRINTK) && defined(CONFIG_LOG2))
static struct k_spinlock lock;
@ -77,7 +82,6 @@ void *__printk_get_hook(void)
#if defined(CONFIG_PRINTK) && \
!(defined(CONFIG_LOG_PRINTK) && defined(CONFIG_LOG2))
#ifdef CONFIG_USERSPACE
struct buf_out_context {
int count;
unsigned int buf_count;
@ -102,7 +106,6 @@ static int buf_char_out(int c, void *ctx_p)
return c;
}
#endif /* CONFIG_USERSPACE */
struct out_context {
int count;
@ -116,7 +119,6 @@ static int char_out(int c, void *ctx_p)
return _char_out(c);
}
#ifdef CONFIG_USERSPACE
void vprintk(const char *fmt, va_list ap)
{
if (k_is_user_context()) {
@ -140,21 +142,6 @@ void vprintk(const char *fmt, va_list ap)
#endif
}
}
#else
void vprintk(const char *fmt, va_list ap)
{
struct out_context ctx = { 0 };
#ifdef CONFIG_PRINTK_SYNC
k_spinlock_key_t key = k_spin_lock(&lock);
#endif
cbvprintf(char_out, &ctx, fmt, ap);
#ifdef CONFIG_PRINTK_SYNC
k_spin_unlock(&lock, key);
#endif
}
#endif /* CONFIG_USERSPACE */
void z_impl_k_str_out(char *c, size_t n)
{