diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-05-22 13:31:14 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-05-22 13:31:14 +0100 |
commit | 621ca5c09444edd9279e14245b9b9b6b387800ec (patch) | |
tree | e6db74cdad79b9ccf93c9f152e9d4dca8cbcddf6 | |
parent | waitOnWriteRangeAndThen can have auto return type (diff) | |
download | netfs-621ca5c09444edd9279e14245b9b9b6b387800ec.tar.bz2 netfs-621ca5c09444edd9279e14245b9b9b6b387800ec.tar.xz netfs-621ca5c09444edd9279e14245b9b9b6b387800ec.zip |
Std algo write overlap testing
-rw-r--r-- | netfs/fuse/fuseFiles.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/netfs/fuse/fuseFiles.cpp b/netfs/fuse/fuseFiles.cpp index eeb5423..7cc6413 100644 --- a/netfs/fuse/fuseFiles.cpp +++ b/netfs/fuse/fuseFiles.cpp @@ -123,23 +123,27 @@ namespace NetFS { while (true) { std::unique_lock lock(of->mutex); // Acquire operations to wait for - auto R = of->bg.equal_range(key); + const auto R = of->bg.equal_range(key); if (R.first == R.second) { // Perform operation return f(key); } else { - std::vector<std::shared_ptr<OpenFile::WriteState>> overlap; - overlap.reserve(safe {std::distance(R.first, R.second)}); - for (auto i = R.first; i != R.second; i++) { - overlap.push_back(i->second); - } + const auto overlap = std::transform_reduce( + R.first, R.second, std::vector<std::shared_future<void>> {}, + [](auto && v, auto && i) { + v.push_back(i); + return std::forward<decltype(v)>(v); + }, + [](auto && i) { + return i.second->future; + }); // Wait for them whilst unlocked lock.release()->unlock(); try { - for (const auto & r : overlap) { - r->future.get(); - } + std::for_each(overlap.begin(), overlap.end(), [](auto && r) { + r.get(); + }); } catch (const SystemError &) { throw; |