1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 12:06:01 +01:00

Encapsulate curlFileTransfer::State:quit

It is allowed to read it, and to set it to `false`, but not to set it
to `true`.
This commit is contained in:
John Ericson 2025-09-29 16:35:59 -04:00
parent 823c0d1140
commit d5402b8527

View file

@ -594,10 +594,21 @@ struct curlFileTransfer : public FileTransfer
} }
}; };
bool quit = false;
std:: std::
priority_queue<std::shared_ptr<TransferItem>, std::vector<std::shared_ptr<TransferItem>>, EmbargoComparator> priority_queue<std::shared_ptr<TransferItem>, std::vector<std::shared_ptr<TransferItem>>, EmbargoComparator>
incoming; incoming;
private:
bool quitting = false;
public:
void quit()
{
quitting = true;
}
bool isQuitting()
{
return quitting;
}
}; };
Sync<State> state_; Sync<State> state_;
@ -649,7 +660,7 @@ struct curlFileTransfer : public FileTransfer
/* Signal the worker thread to exit. */ /* Signal the worker thread to exit. */
{ {
auto state(state_.lock()); auto state(state_.lock());
state->quit = true; state->quit();
} }
#ifndef _WIN32 // TODO need graceful async exit support on Windows? #ifndef _WIN32 // TODO need graceful async exit support on Windows?
writeFull(wakeupPipe.writeSide.get(), " ", false); writeFull(wakeupPipe.writeSide.get(), " ", false);
@ -750,7 +761,7 @@ struct curlFileTransfer : public FileTransfer
break; break;
} }
} }
quit = state->quit; quit = state->isQuitting();
} }
for (auto & item : incoming) { for (auto & item : incoming) {
@ -778,7 +789,7 @@ struct curlFileTransfer : public FileTransfer
auto state(state_.lock()); auto state(state_.lock());
while (!state->incoming.empty()) while (!state->incoming.empty())
state->incoming.pop(); state->incoming.pop();
state->quit = true; state->quit();
} }
} }
@ -789,7 +800,7 @@ struct curlFileTransfer : public FileTransfer
{ {
auto state(state_.lock()); auto state(state_.lock());
if (state->quit) if (state->isQuitting())
throw nix::Error("cannot enqueue download request because the download thread is shutting down"); throw nix::Error("cannot enqueue download request because the download thread is shutting down");
state->incoming.push(item); state->incoming.push(item);
} }
@ -845,7 +856,7 @@ ref<FileTransfer> getFileTransfer()
{ {
static ref<curlFileTransfer> fileTransfer = makeCurlFileTransfer(); static ref<curlFileTransfer> fileTransfer = makeCurlFileTransfer();
if (fileTransfer->state_.lock()->quit) if (fileTransfer->state_.lock()->isQuitting())
fileTransfer = makeCurlFileTransfer(); fileTransfer = makeCurlFileTransfer();
return fileTransfer; return fileTransfer;