logging: improve log_flush() robustness
The 'log_flush()' function is used to wait for all pending log messages
to be processed by the background thread. This is performed by polling
the 'log_data_pending()' function, which scans all available buffers.
The log core already provides a 'buffered_cnt' variable that keeps track
of the number of pending messages. This variable is updated atomically
and could be a more efficient implementation for that check.
This commit moves the 'buffered_cnt' decrement _after_ the message
processing and buffer release, to ensure that the variable reflects
the number of pending messages at any moment in time.
The 'log_data_pending()' function is then replaced with a direct check
of the 'buffered_cnt' variable.
Signed-off-by:
Luca Burelli <l.burelli@arduino.cc>
Loading
Please sign in to comment