Skip to content

Commit

Permalink
Tracing: Fix extra function calls when using FIFO tracing macros.
Browse files Browse the repository at this point in the history
Fixes issue where function returns being used as data arguments to
k_fifo tracing macros were being called mulitple times due to
preprocessor copying  macro arguments during expansion.

Signed-off-by: Anthony Williams <[email protected]>
  • Loading branch information
anthony289478 authored and kartben committed Dec 18, 2024
1 parent 913fddb commit 4272353
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions include/zephyr/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -2544,9 +2544,10 @@ struct k_fifo {
*/
#define k_fifo_put(fifo, data) \
({ \
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_fifo, put, fifo, data); \
k_queue_append(&(fifo)->_queue, data); \
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_fifo, put, fifo, data); \
void *_data = data; \
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_fifo, put, fifo, _data); \
k_queue_append(&(fifo)->_queue, _data); \
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_fifo, put, fifo, _data); \
})

/**
Expand All @@ -2567,9 +2568,10 @@ struct k_fifo {
*/
#define k_fifo_alloc_put(fifo, data) \
({ \
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_fifo, alloc_put, fifo, data); \
int fap_ret = k_queue_alloc_append(&(fifo)->_queue, data); \
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_fifo, alloc_put, fifo, data, fap_ret); \
void *_data = data; \
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_fifo, alloc_put, fifo, _data); \
int fap_ret = k_queue_alloc_append(&(fifo)->_queue, _data); \
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_fifo, alloc_put, fifo, _data, fap_ret); \
fap_ret; \
})

Expand Down Expand Up @@ -2766,9 +2768,10 @@ struct k_lifo {
*/
#define k_lifo_put(lifo, data) \
({ \
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_lifo, put, lifo, data); \
k_queue_prepend(&(lifo)->_queue, data); \
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_lifo, put, lifo, data); \
void *_data = data; \
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_lifo, put, lifo, _data); \
k_queue_prepend(&(lifo)->_queue, _data); \
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_lifo, put, lifo, _data); \
})

/**
Expand All @@ -2789,9 +2792,10 @@ struct k_lifo {
*/
#define k_lifo_alloc_put(lifo, data) \
({ \
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_lifo, alloc_put, lifo, data); \
int lap_ret = k_queue_alloc_prepend(&(lifo)->_queue, data); \
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_lifo, alloc_put, lifo, data, lap_ret); \
void *_data = data; \
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_lifo, alloc_put, lifo, _data); \
int lap_ret = k_queue_alloc_prepend(&(lifo)->_queue, _data); \
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_lifo, alloc_put, lifo, _data, lap_ret); \
lap_ret; \
})

Expand Down

0 comments on commit 4272353

Please sign in to comment.