[lldb] [MainLoopPosix] Fix crash upon adding lots of pending callbacks
authorMichał Górny <mgorny@gentoo.org>
Sat, 8 Oct 2022 16:25:49 +0000 (18:25 +0200)
committerMichał Górny <mgorny@gentoo.org>
Mon, 17 Oct 2022 15:48:44 +0000 (17:48 +0200)
commite8ee0f121dbc2dc20a9de326531c4d4d061a20d8
treecc086646c8ef6369900a7c3b2c794d22adf12c68
parent7712ae0a02da98b5c028af7be769a8aef99f83e3
[lldb] [MainLoopPosix] Fix crash upon adding lots of pending callbacks

If lots of pending callbacks are added while the main loop has exited
already, the trigger pipe buffer fills in, causing the write to fail
and the related assertion to fail.  To avoid this, add a boolean member
indicating whether the callbacks have been triggered already.
If the trigger was done, avoid writing to the pipe until loops proceeds
to run them and resets the variable.

Besides fixing the issue, this also avoids writing to the pipe multiple
times if callbacks are added faster than the loop is able to process
them.  Previously, this would lead to the loop performing multiple read
iterations from pipe unnecessarily.

Sponsored by: The FreeBSD Foundation

Differential Revision: https://reviews.llvm.org/D135516
lldb/include/lldb/Host/posix/MainLoopPosix.h
lldb/source/Host/posix/MainLoopPosix.cpp
lldb/unittests/Host/MainLoopTest.cpp