Skip to content

Commit a588042

Browse files
kwd-doodlingnashif
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 5e5baa5 commit a588042

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
@@ -397,12 +397,12 @@ static inline char z_log_minimal_level_to_char(int level)
397397
#define LOG_FILTER_SLOT_GET(_filters, _id) \
398398
((*(_filters) >> LOG_FILTER_SLOT_SHIFT(_id)) & LOG_FILTER_SLOT_MASK)
399399

400-
#define LOG_FILTER_SLOT_SET(_filters, _id, _filter) \
401-
do { \
402-
*(_filters) &= ~(LOG_FILTER_SLOT_MASK << \
403-
LOG_FILTER_SLOT_SHIFT(_id)); \
404-
*(_filters) |= ((_filter) & LOG_FILTER_SLOT_MASK) << \
405-
LOG_FILTER_SLOT_SHIFT(_id); \
400+
#define LOG_FILTER_SLOT_SET(_filters, _id, _filter) \
401+
do { \
402+
uint32_t others = *(_filters) & ~(LOG_FILTER_SLOT_MASK << \
403+
LOG_FILTER_SLOT_SHIFT(_id)); \
404+
*(_filters) = others | (((_filter) & LOG_FILTER_SLOT_MASK) << \
405+
LOG_FILTER_SLOT_SHIFT(_id)); \
406406
} while (false)
407407

408408
#define LOG_FILTER_AGGR_SLOT_IDX 0

0 commit comments

Comments
 (0)