Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nix
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 88571219d97f
Choose a base ref
...
head repository: NixOS/nix
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 324a5dc92f8e
Choose a head ref
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Jun 25, 2019

  1. ProgressBar: Fix updating

    'updateCV.notify_one()' does nothing if the update thread is not
    waiting for updateCV (in particular this happens when it is sleeping
    on quitCV). So also set a variable to ensure that the update isn't
    lost.
    edolstra committed Jun 25, 2019
    Copy the full SHA
    324a5dc View commit details
Showing with 15 additions and 11 deletions.
  1. +15 −11 src/nix/progress-bar.cc
26 changes: 15 additions & 11 deletions src/nix/progress-bar.cc
Original file line number Diff line number Diff line change
@@ -62,6 +62,7 @@ class ProgressBar : public Logger
uint64_t corruptedPaths = 0, untrustedPaths = 0;

bool active = true;
bool haveUpdate = true;
};

Sync<State> state_;
@@ -83,7 +84,8 @@ class ProgressBar : public Logger
updateThread = std::thread([&]() {
auto state(state_.lock());
while (state->active) {
state.wait(updateCV);
if (!state->haveUpdate)
state.wait(updateCV);
draw(*state);
state.wait_for(quitCV, std::chrono::milliseconds(50));
}
@@ -178,7 +180,7 @@ class ProgressBar : public Logger
|| (type == actCopyPath && hasAncestor(*state, actSubstitute, parent)))
i->visible = false;

update();
update(*state);
}

/* Check whether an activity has an ancestore with the specified
@@ -213,7 +215,7 @@ class ProgressBar : public Logger
state->its.erase(i);
}

update();
update(*state);
}

void result(ActivityId act, ResultType type, const std::vector<Field> & fields) override
@@ -223,7 +225,7 @@ class ProgressBar : public Logger
if (type == resFileLinked) {
state->filesLinked++;
state->bytesLinked += getI(fields, 0);
update();
update(*state);
}

else if (type == resBuildLogLine) {
@@ -239,26 +241,26 @@ class ProgressBar : public Logger
info.lastLine = lastLine;
state->activities.emplace_back(info);
i->second = std::prev(state->activities.end());
update();
update(*state);
}
}
}

else if (type == resUntrustedPath) {
state->untrustedPaths++;
update();
update(*state);
}

else if (type == resCorruptedPath) {
state->corruptedPaths++;
update();
update(*state);
}

else if (type == resSetPhase) {
auto i = state->its.find(act);
assert(i != state->its.end());
i->second->phase = getS(fields, 0);
update();
update(*state);
}

else if (type == resProgress) {
@@ -269,7 +271,7 @@ class ProgressBar : public Logger
actInfo.expected = getI(fields, 1);
actInfo.running = getI(fields, 2);
actInfo.failed = getI(fields, 3);
update();
update(*state);
}

else if (type == resSetExpected) {
@@ -281,17 +283,19 @@ class ProgressBar : public Logger
state->activitiesByType[type].expected -= j;
j = getI(fields, 1);
state->activitiesByType[type].expected += j;
update();
update(*state);
}
}

void update()
void update(State & state)
{
state.haveUpdate = true;
updateCV.notify_one();
}

void draw(State & state)
{
state.haveUpdate = false;
if (!state.active) return;

std::string line;