Skip to content

Commit 6445144

Browse files
kwd-doodlingdkalowsk
authored andcommitted
logging: Ensure atomic update of log filter slot in LOG_FILTER_SLOT_SET
Replaced the read-modify-write sequence with a single read and write operation, preventing the intermediate value is wrongly used to filter out logs of another thread with higher priority that preempts the current thread. Signed-off-by: Dong Wang <[email protected]> (cherry picked from commit 872f363)
1 parent 79696d4 commit 6445144

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

include/zephyr/logging/log_core.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,12 @@ static inline char z_log_minimal_level_to_char(int level)
400400
#define LOG_FILTER_SLOT_GET(_filters, _id) \
401401
((*(_filters) >> LOG_FILTER_SLOT_SHIFT(_id)) & LOG_FILTER_SLOT_MASK)
402402

403-
#define LOG_FILTER_SLOT_SET(_filters, _id, _filter) \
404-
do { \
405-
*(_filters) &= ~(LOG_FILTER_SLOT_MASK << \
406-
LOG_FILTER_SLOT_SHIFT(_id)); \
407-
*(_filters) |= ((_filter) & LOG_FILTER_SLOT_MASK) << \
408-
LOG_FILTER_SLOT_SHIFT(_id); \
403+
#define LOG_FILTER_SLOT_SET(_filters, _id, _filter) \
404+
do { \
405+
uint32_t others = *(_filters) & ~(LOG_FILTER_SLOT_MASK << \
406+
LOG_FILTER_SLOT_SHIFT(_id)); \
407+
*(_filters) = others | (((_filter) & LOG_FILTER_SLOT_MASK) << \
408+
LOG_FILTER_SLOT_SHIFT(_id)); \
409409
} while (false)
410410

411411
#define LOG_FILTER_AGGR_SLOT_IDX 0

0 commit comments

Comments
 (0)