subsys: logging: fix trigger threshold corner case
subsys: logging: fix trigger threshold corner case

The CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD option can be used to wake up
the background log processing thread when a given number of messages
have been queued.

Currently, the msg_finalize() routine which is responsible for
queueing a log message for later handling appends messages to the
global list after performing the threshold check and waking up the
thread.

This leads to a race condition with undesirable behavior if the
threshold == 1:

- the msg_finalize() thread is scheduled out by calling k_wakeup()
- the log processing thread wakes up, notice that no messages are
  queued, and goes back to sleep
- the msg_finalize() thread is scheduled back in and the message is
  queued for processing

This defers the handling of the message until the processing thread
wakes up again after the CONFIG_LOG_PROCESS_THREAD_SLEEP_MS timeout,
which is not what the user wants.

Fix this by queueing the message before waking up the handler thread.
(This also may improve responsiveness for larger threshold values.)

Signed-off-by: Marti Bolivar <fd5da480b758a78208111e6ae5c6806e1f887137@foundries.io>

zephyrproject-rtos/zephyr,punitvara/zephyr,punitvara/zephyr,Vudentz/zephyr,explora26/zephyr,zephyrproject-rtos/zephyr,galak/zephyr,kraj/zephyr,GiulianoFranchetto/zephyr,kraj/zephyr,Vudentz/zephyr,nashif/zephyr,Vudentz/zephyr,GiulianoFranchetto/zephyr,galak/zephyr,punitvara/zephyr,finikorg/zephyr,nashif/zephyr,nashif/zephyr,nashif/zephyr,punitvara/zephyr,finikorg/zephyr,finikorg/zephyr,finikorg/zephyr,galak/zephyr,zephyrproject-rtos/zephyr,ldts/zephyr,ldts/zephyr,Vudentz/zephyr,zephyrproject-rtos/zephyr,explora26/zephyr,Vudentz/zephyr,kraj/zephyr,galak/zephyr,ldts/zephyr,finikorg/zephyr,galak/zephyr,ldts/zephyr,kraj/zephyr,GiulianoFranchetto/zephyr,ldts/zephyr,kraj/zephyr,explora26/zephyr,Vudentz/zephyr,GiulianoFranchetto/zephyr,nashif/zephyr,zephyrproject-rtos/zephyr,explora26/zephyr,punitvara/zephyr,explora26/zephyr,GiulianoFranchetto/zephyr