Skip to content

Commit 5601c18

Browse files
kwd-doodlingkartben
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 0b4672f commit 5601c18

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
@@ -401,12 +401,12 @@ static inline char z_log_minimal_level_to_char(int level)
401401
#define LOG_FILTER_SLOT_GET(_filters, _id) \
402402
((*(_filters) >> LOG_FILTER_SLOT_SHIFT(_id)) & LOG_FILTER_SLOT_MASK)
403403

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

412412
#define LOG_FILTER_AGGR_SLOT_IDX 0

0 commit comments

Comments
 (0)