From 90536e27e16c5f62dab2517e06e7b3382b9cd9c0 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sat, 9 Nov 2024 01:17:28 +0100 Subject: [PATCH] libstore: simplify TransferSource::awaitData don't pass in a lock that's only used inside this function. Change-Id: I15c01e9cfe343cf13828ae3b3742c36ae697291f --- src/libstore/filetransfer.cc | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc index a713e7490..53a811542 100644 --- a/src/libstore/filetransfer.cc +++ b/src/libstore/filetransfer.cc @@ -893,11 +893,13 @@ struct curlFileTransfer : public FileTransfer } } - void awaitData(Sync::Lock & state) + void awaitData() { /* Grab data if available, otherwise wait for the download thread to wake us up. */ while (buffered.empty()) { + auto state(_state->lock()); + if (state->data.empty()) { if (state->done) { if (state->exc) { @@ -929,10 +931,7 @@ struct curlFileTransfer : public FileTransfer size_t total = readPartial(data, len); while (total < len) { - { - auto state(_state->lock()); - awaitData(state); - } + awaitData(); const auto current = readPartial(data + total, len - total); total += current; if (total == 0 || current == 0) { @@ -950,8 +949,7 @@ struct curlFileTransfer : public FileTransfer auto metadata = item->metadataPromise.get_future().get(); auto source = make_box_ptr(_state, item); - auto lock(_state->lock()); - source->awaitData(lock); + source->awaitData(); return {std::move(metadata), std::move(source)}; }