Observatory: reduce time with locked mutex
Reduces the time the messages mutex is held by re-arranging some function calls. Also fixes that in clear messages, message_count_ was not reset. !611 (merged) should be rebased on this change since in either case it would benefit as well.
I think in theory, there is still the faint possibility for a data race when clear is pressed and a message arrives, but I think it is highly unlikely:
- in
data(),message_count_.load()returns a number > 0 - in
clearMessages(),message_count_is set to 0 -
clearMessages()locks the mutex beforedata()for some very unlucky reason -
clearMessages()clears messages -
data()accessesmessages_with an invalid index