Use wait-in-destruct future everywhere

Summary:
Before we used `utils::Future` only where it's created by our `ThreadPool`.
I suggest in this diff that we use it everywhere, it's a bit more defensive and
should not have any downsides.

Reviewers: msantl, teon.banek

Reviewed By: msantl

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D1316
This commit is contained in:
florijan 2018-03-26 12:17:17 +02:00
parent 29ba055b64
commit a88c598822
5 changed files with 5 additions and 22 deletions

View File

@ -1,5 +1,4 @@
#include <functional>
#include <future>
#include "glog/logging.h"

View File

@ -1,7 +1,6 @@
#include "query/plan/operator.hpp"
#include <algorithm>
#include <future>
#include <limits>
#include <queue>
#include <random>
@ -26,7 +25,6 @@
#include "query/path.hpp"
#include "utils/algorithm.hpp"
#include "utils/exceptions.hpp"
#include "utils/future.hpp"
DEFINE_HIDDEN_int32(remote_pull_sleep_micros, 10,
"Sleep between remote result pulling in microseconds");
@ -553,10 +551,9 @@ bool Expand::ExpandCursor::Pull(Frame &frame, Context &context) {
};
auto find_ready_future = [this]() {
return std::find_if(future_expands_.begin(), future_expands_.end(),
[](const auto &future) {
return utils::IsFutureReady(future.edge_to);
});
return std::find_if(
future_expands_.begin(), future_expands_.end(),
[](const auto &future) { return future.edge_to.IsReady(); });
};
auto put_future_edge_on_frame = [this, &frame](auto &future) {

View File

@ -3,7 +3,6 @@
#pragma once
#include <experimental/optional>
#include <future>
#include <memory>
#include <unordered_map>
#include <unordered_set>
@ -24,6 +23,7 @@
#include "query/typed_value.hpp"
#include "storage/types.hpp"
#include "utils/bound.hpp"
#include "utils/future.hpp"
#include "utils/hashing/fnv.hpp"
#include "utils/visitor.hpp"
@ -828,7 +828,7 @@ class Expand : public LogicalOperator, public ExpandCommon {
private:
struct FutureExpand {
std::future<std::pair<EdgeAccessor, VertexAccessor>> edge_to;
utils::Future<std::pair<EdgeAccessor, VertexAccessor>> edge_to;
std::vector<TypedValue> frame_elems;
};

View File

@ -3,7 +3,6 @@
#include <condition_variable>
#include <functional>
#include <future>
#include <memory>
#include <mutex>
#include <queue>

View File

@ -2,7 +2,6 @@
#include <algorithm>
#include <chrono>
#include <future>
#include <string>
#include <utility>
@ -125,15 +124,4 @@ class Iterable {
TIterator end_;
};
/**
* Returns true if the future has the result available.
* NOTE: The behaviour is undefined if future isn't valid, i.e.
* `future.valid() == false`.
*/
template <typename T>
bool IsFutureReady(const std::future<T> &future) {
auto status = future.wait_for(std::chrono::seconds(0));
return status == std::future_status::ready;
}
} // namespace utils