1
0
Fork 0

Bug fix/some future massaging (#10285)

This commit is contained in:
Jan 2019-10-21 09:16:15 +02:00 committed by GitHub
parent 1c7a60a587
commit ddb08ed045
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 14 additions and 23 deletions

View File

@ -61,7 +61,7 @@ class Connection : public std::enable_shared_from_this<Connection> {
/// @brief Send a request to the server and wait into a response it received.
/// @param r request that is copied
std::unique_ptr<Response> sendRequest(Request const& r) {
std::unique_ptr<Request> copy(new Request(r));
auto copy = std::make_unique<Request>(r);
return sendRequest(std::move(copy));
}
@ -77,7 +77,7 @@ class Connection : public std::enable_shared_from_this<Connection> {
/// callbackis called. The callback is executed on a specific
/// IO-Thread for this connection.
MessageID sendRequest(Request const& r, RequestCallback cb) {
std::unique_ptr<Request> copy(new Request(r));
auto copy = std::make_unique<Request>(r);
return sendRequest(std::move(copy), cb);
}

View File

@ -201,7 +201,7 @@ MessageID HttpConnection<ST>::sendRequest(std::unique_ptr<Request> req,
static std::atomic<uint64_t> ticketId(1);
// construct RequestItem
std::unique_ptr<RequestItem> item(new RequestItem());
auto item = std::make_unique<RequestItem>();
// requestItem->_response later
uint64_t mid = ticketId.fetch_add(1, std::memory_order_relaxed);
item->requestHeader = buildRequestBody(*req);

View File

@ -60,7 +60,7 @@ MessageID VstConnection<ST>::sendRequest(std::unique_ptr<Request> req,
// it does not matter if IDs are reused on different connections
uint64_t mid = vstMessageId.fetch_add(1, std::memory_order_relaxed);
// Create RequestItem from parameters
std::unique_ptr<RequestItem> item(new RequestItem());
auto item = std::make_unique<RequestItem>();
item->_messageID = mid;
item->_request = std::move(req);
item->_callback = cb;
@ -485,7 +485,7 @@ std::unique_ptr<fu::Response> VstConnection<ST>::createResponse(
ResponseHeader header =
parser::responseHeaderFromSlice(VPackSlice(itemCursor));
std::unique_ptr<Response> response(new Response(std::move(header)));
auto response = std::make_unique<Response>(std::move(header));
response->setPayload(std::move(*responseBuffer), /*offset*/ headerLength);
return response;

View File

@ -27,8 +27,7 @@ namespace arangodb { namespace fuerte { inline namespace v1 {
std::unique_ptr<Request> createRequest(RestVerb verb,
ContentType contentType) {
std::unique_ptr<Request> request(new Request());
auto request = std::make_unique<Request>();
request->header.restVerb = verb;
request->header.contentType(contentType);
request->header.acceptType(contentType);

View File

@ -623,8 +623,7 @@ std::unique_ptr<VPackBuffer<uint8_t>> RequestItem::assemble() {
if (!reject) {
FUERTE_LOG_VSTCHUNKTRACE
<< "RequestItem::assemble: fast-path, chunks are in order" << std::endl;
return std::unique_ptr<VPackBuffer<uint8_t>>(
new VPackBuffer<uint8_t>(std::move(_buffer)));
return std::make_unique<VPackBuffer<uint8_t>>(std::move(_buffer));
}
// We now have all chunks. Sort them by index.

View File

@ -141,9 +141,9 @@ void waitImpl(Future<T>& f) {
Promise<T> p;
Future<T> ret = p.getFuture();
f.thenFinal([&p, &cv, &m](Try<T>&& t) {
p.setTry(std::move(t));
f.thenFinal([p(std::move(p)), &cv, &m](Try<T>&& t) mutable {
std::lock_guard<std::mutex> guard(m);
p.setTry(std::move(t));
cv.notify_one();
});
std::unique_lock<std::mutex> lock(m);

View File

@ -62,6 +62,7 @@ class Promise {
detach();
_state = std::move(o._state);
_retrieved = o._retrieved;
o._retrieved = false;
o._state = nullptr;
}
return *this;

View File

@ -130,11 +130,11 @@ class SharedState {
/// but the referenced result may or may not have been modified, including
/// possibly moved-out, depending on what the callback did; some but not
/// all callbacks modify (possibly move-out) the result.)
Try<T>& getTry() {
Try<T>& getTry() noexcept {
TRI_ASSERT(hasResult());
return _result;
}
Try<T> const& getTry() const {
Try<T> const& getTry() const noexcept {
TRI_ASSERT(hasResult());
return _result;
}
@ -163,18 +163,14 @@ class SharedState {
return;
}
TRI_ASSERT(state == State::OnlyResult); // race with setResult
#ifndef _MSC_VER
[[fallthrough]];
#endif
case State::OnlyResult:
if (_state.compare_exchange_strong(state, State::Done, std::memory_order_acquire)) {
if (_state.compare_exchange_strong(state, State::Done, std::memory_order_release)) {
doCallback();
return;
}
#ifndef _MSC_VER
[[fallthrough]];
#endif
default:
TRI_ASSERT(false); // unexpected state
@ -203,18 +199,14 @@ class SharedState {
return;
}
TRI_ASSERT(state == State::OnlyCallback); // race with setCallback
#ifndef _MSC_VER
[[fallthrough]];
#endif
case State::OnlyCallback:
if (_state.compare_exchange_strong(state, State::Done, std::memory_order_acquire)) {
if (_state.compare_exchange_strong(state, State::Done, std::memory_order_release)) {
doCallback();
return;
}
#ifndef _MSC_VER
[[fallthrough]];
#endif
default:
TRI_ASSERT(false); // unexpected state