Skip to content

Commit 8e5b4ae

Browse files
committed
[nrf fromlist] logging: log_output: Move flushing and writing to the header
Move log_output_flush and log_output_write (renamed internal buffer_write() function) to the header as inline functions. Those function are used by log_output_dict.c and there are cases when log_output.c is not compiled in. Upstream PR: zephyrproject-rtos/zephyr#79506 Signed-off-by: Krzysztof Chruściński <[email protected]>
1 parent 6f6b0e4 commit 8e5b4ae

File tree

3 files changed

+32
-42
lines changed

3 files changed

+32
-42
lines changed

include/zephyr/logging/log_output.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,35 @@ void log_output_msg_syst_process(const struct log_output *log_output,
190190
*/
191191
void log_output_dropped_process(const struct log_output *output, uint32_t cnt);
192192

193+
/** @brief Write to the output buffer.
194+
*
195+
* @param outf Output function.
196+
* @param buf Buffer.
197+
* @param len Buffer length.
198+
* @param ctx Context passed to the %p outf.
199+
*/
200+
static inline void log_output_write(log_output_func_t outf, uint8_t *buf, size_t len, void *ctx)
201+
{
202+
int processed;
203+
204+
while (len != 0) {
205+
processed = outf(buf, len, ctx);
206+
len -= processed;
207+
buf += processed;
208+
}
209+
}
210+
193211
/** @brief Flush output buffer.
194212
*
195213
* @param output Pointer to the log output instance.
196214
*/
197-
void log_output_flush(const struct log_output *output);
215+
static inline void log_output_flush(const struct log_output *output)
216+
{
217+
log_output_write(output->func, output->buf,
218+
output->control_block->offset,
219+
output->control_block->ctx);
220+
output->control_block->offset = 0;
221+
}
198222

199223
/** @brief Function for setting user context passed to the output function.
200224
*

subsys/logging/log_output.c

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -148,28 +148,6 @@ static int print_formatted(const struct log_output *output,
148148
return length;
149149
}
150150

151-
static void buffer_write(log_output_func_t outf, uint8_t *buf, size_t len,
152-
void *ctx)
153-
{
154-
int processed;
155-
156-
while (len != 0) {
157-
processed = outf(buf, len, ctx);
158-
len -= processed;
159-
buf += processed;
160-
}
161-
}
162-
163-
164-
void log_output_flush(const struct log_output *output)
165-
{
166-
buffer_write(output->func, output->buf,
167-
output->control_block->offset,
168-
output->control_block->ctx);
169-
170-
output->control_block->offset = 0;
171-
}
172-
173151
static inline bool is_leap_year(uint32_t year)
174152
{
175153
return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0));
@@ -741,10 +719,10 @@ void log_output_dropped_process(const struct log_output *output, uint32_t cnt)
741719
cnt = MIN(cnt, 9999);
742720
len = snprintk(buf, sizeof(buf), "%d", cnt);
743721

744-
buffer_write(outf, (uint8_t *)prefix, sizeof(prefix) - 1,
722+
log_output_write(outf, (uint8_t *)prefix, sizeof(prefix) - 1,
745723
output->control_block->ctx);
746-
buffer_write(outf, buf, len, output->control_block->ctx);
747-
buffer_write(outf, (uint8_t *)postfix, sizeof(postfix) - 1,
724+
log_output_write(outf, buf, len, output->control_block->ctx);
725+
log_output_write(outf, (uint8_t *)postfix, sizeof(postfix) - 1,
748726
output->control_block->ctx);
749727
}
750728

subsys/logging/log_output_dict.c

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,6 @@
1212
#include <zephyr/sys/__assert.h>
1313
#include <zephyr/sys/util.h>
1414

15-
static void buffer_write(log_output_func_t outf, uint8_t *buf, size_t len,
16-
void *ctx)
17-
{
18-
int processed;
19-
20-
do {
21-
processed = outf(buf, len, ctx);
22-
len -= processed;
23-
buf += processed;
24-
} while (len != 0);
25-
}
26-
2715
void log_dict_output_msg_process(const struct log_output *output,
2816
struct log_msg *msg, uint32_t flags)
2917
{
@@ -44,19 +32,19 @@ void log_dict_output_msg_process(const struct log_output *output,
4432
log_const_source_id(source)) :
4533
0U;
4634

47-
buffer_write(output->func, (uint8_t *)&output_hdr, sizeof(output_hdr),
35+
log_output_write(output->func, (uint8_t *)&output_hdr, sizeof(output_hdr),
4836
(void *)output->control_block->ctx);
4937

5038
size_t len;
5139
uint8_t *data = log_msg_get_package(msg, &len);
5240

5341
if (len > 0U) {
54-
buffer_write(output->func, data, len, (void *)output->control_block->ctx);
42+
log_output_write(output->func, data, len, (void *)output->control_block->ctx);
5543
}
5644

5745
data = log_msg_get_data(msg, &len);
5846
if (len > 0U) {
59-
buffer_write(output->func, data, len, (void *)output->control_block->ctx);
47+
log_output_write(output->func, data, len, (void *)output->control_block->ctx);
6048
}
6149

6250
log_output_flush(output);
@@ -69,6 +57,6 @@ void log_dict_output_dropped_process(const struct log_output *output, uint32_t c
6957
msg.type = MSG_DROPPED_MSG;
7058
msg.num_dropped_messages = MIN(cnt, 9999);
7159

72-
buffer_write(output->func, (uint8_t *)&msg, sizeof(msg),
60+
log_output_write(output->func, (uint8_t *)&msg, sizeof(msg),
7361
(void *)output->control_block->ctx);
7462
}

0 commit comments

Comments
 (0)