logging: log_output: Improve immediate mode handling

When in immediate mode ensure that buffering is not used in log output.
Every byte is pushed to the transport.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruscinski 2019-11-20 14:28:06 +01:00 committed by Andrew Boie
commit 117fab3004
4 changed files with 54 additions and 26 deletions

View file

@ -102,16 +102,23 @@ static int out_func(int c, void *ctx)
{
const struct log_output *out_ctx =
(const struct log_output *)ctx;
int idx;
out_ctx->buf[out_ctx->control_block->offset] = (u8_t)c;
out_ctx->control_block->offset++;
__ASSERT_NO_MSG(out_ctx->control_block->offset <= out_ctx->size);
if (IS_ENABLED(CONFIG_LOG_IMMEDIATE)) {
/* Backend must be thread safe in synchronous operation. */
out_ctx->func((u8_t *)&c, 1, out_ctx->control_block->ctx);
return 0;
}
if (out_ctx->control_block->offset == out_ctx->size) {
log_output_flush(out_ctx);
}
idx = atomic_inc(&out_ctx->control_block->offset);
out_ctx->buf[idx] = (u8_t)c;
__ASSERT_NO_MSG(out_ctx->control_block->offset <= out_ctx->size);
return 0;
}
@ -145,6 +152,7 @@ static void buffer_write(log_output_func_t outf, u8_t *buf, size_t len,
} while (len != 0);
}
void log_output_flush(const struct log_output *log_output)
{
buffer_write(log_output->func, log_output->buf,