fix: Avoid deadlock in ProgressBar::redraw()

This commit is contained in:
Robert Hensing 2024-09-08 11:44:24 +02:00
parent e10ea78f93
commit c955563b64

View file

@ -75,11 +75,11 @@ private:
bool active = true;
bool paused = false;
bool haveUpdate = true;
/** Helps avoid unnecessary redraws, see `draw()` */
std::string lastOutput;
};
/** Helps avoid unnecessary redraws, see `redraw()` */
Sync<std::string> lastOutput_;
Sync<State> state_;
std::thread updateThread;
@ -371,10 +371,10 @@ public:
*/
void redraw(std::string newOutput)
{
auto state(state_.lock());
if (newOutput != state->lastOutput) {
auto lastOutput(lastOutput_.lock());
if (newOutput != *lastOutput) {
writeToStderr(newOutput);
state->lastOutput = std::move(newOutput);
*lastOutput = std::move(newOutput);
}
}