diff --git a/3rdParty/fuerte/include/fuerte/connection.h b/3rdParty/fuerte/include/fuerte/connection.h index 685cb99d97..28901aadae 100644 --- a/3rdParty/fuerte/include/fuerte/connection.h +++ b/3rdParty/fuerte/include/fuerte/connection.h @@ -61,7 +61,7 @@ class Connection : public std::enable_shared_from_this { /// @brief Send a request to the server and wait into a response it received. /// @param r request that is copied std::unique_ptr sendRequest(Request const& r) { - std::unique_ptr copy(new Request(r)); + auto copy = std::make_unique(r); return sendRequest(std::move(copy)); } @@ -77,7 +77,7 @@ class Connection : public std::enable_shared_from_this { /// callbackis called. The callback is executed on a specific /// IO-Thread for this connection. MessageID sendRequest(Request const& r, RequestCallback cb) { - std::unique_ptr copy(new Request(r)); + auto copy = std::make_unique(r); return sendRequest(std::move(copy), cb); } diff --git a/3rdParty/fuerte/src/HttpConnection.cpp b/3rdParty/fuerte/src/HttpConnection.cpp index 5065ea2bef..ad77052ae2 100644 --- a/3rdParty/fuerte/src/HttpConnection.cpp +++ b/3rdParty/fuerte/src/HttpConnection.cpp @@ -201,7 +201,7 @@ MessageID HttpConnection::sendRequest(std::unique_ptr req, static std::atomic ticketId(1); // construct RequestItem - std::unique_ptr item(new RequestItem()); + auto item = std::make_unique(); // requestItem->_response later uint64_t mid = ticketId.fetch_add(1, std::memory_order_relaxed); item->requestHeader = buildRequestBody(*req); diff --git a/3rdParty/fuerte/src/VstConnection.cpp b/3rdParty/fuerte/src/VstConnection.cpp index 6387fb8e0d..afb7a18838 100644 --- a/3rdParty/fuerte/src/VstConnection.cpp +++ b/3rdParty/fuerte/src/VstConnection.cpp @@ -60,7 +60,7 @@ MessageID VstConnection::sendRequest(std::unique_ptr 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 item(new RequestItem()); + auto item = std::make_unique(); item->_messageID = mid; item->_request = std::move(req); item->_callback = cb; @@ -485,7 +485,7 @@ std::unique_ptr VstConnection::createResponse( ResponseHeader header = parser::responseHeaderFromSlice(VPackSlice(itemCursor)); - std::unique_ptr response(new Response(std::move(header))); + auto response = std::make_unique(std::move(header)); response->setPayload(std::move(*responseBuffer), /*offset*/ headerLength); return response; diff --git a/3rdParty/fuerte/src/requests.cpp b/3rdParty/fuerte/src/requests.cpp index 9eaa73939e..f1711f30be 100644 --- a/3rdParty/fuerte/src/requests.cpp +++ b/3rdParty/fuerte/src/requests.cpp @@ -27,8 +27,7 @@ namespace arangodb { namespace fuerte { inline namespace v1 { std::unique_ptr createRequest(RestVerb verb, ContentType contentType) { - std::unique_ptr request(new Request()); - + auto request = std::make_unique(); request->header.restVerb = verb; request->header.contentType(contentType); request->header.acceptType(contentType); diff --git a/3rdParty/fuerte/src/vst.cpp b/3rdParty/fuerte/src/vst.cpp index 197521b43c..4d2091a493 100644 --- a/3rdParty/fuerte/src/vst.cpp +++ b/3rdParty/fuerte/src/vst.cpp @@ -623,8 +623,7 @@ std::unique_ptr> RequestItem::assemble() { if (!reject) { FUERTE_LOG_VSTCHUNKTRACE << "RequestItem::assemble: fast-path, chunks are in order" << std::endl; - return std::unique_ptr>( - new VPackBuffer(std::move(_buffer))); + return std::make_unique>(std::move(_buffer)); } // We now have all chunks. Sort them by index. diff --git a/lib/Futures/Future.h b/lib/Futures/Future.h index 3f827b43d0..c56f2964f3 100644 --- a/lib/Futures/Future.h +++ b/lib/Futures/Future.h @@ -141,9 +141,9 @@ void waitImpl(Future& f) { Promise p; Future ret = p.getFuture(); - f.thenFinal([&p, &cv, &m](Try&& t) { - p.setTry(std::move(t)); + f.thenFinal([p(std::move(p)), &cv, &m](Try&& t) mutable { std::lock_guard guard(m); + p.setTry(std::move(t)); cv.notify_one(); }); std::unique_lock lock(m); diff --git a/lib/Futures/Promise.h b/lib/Futures/Promise.h index 5308b8131a..d8d77fbb62 100644 --- a/lib/Futures/Promise.h +++ b/lib/Futures/Promise.h @@ -62,6 +62,7 @@ class Promise { detach(); _state = std::move(o._state); _retrieved = o._retrieved; + o._retrieved = false; o._state = nullptr; } return *this; diff --git a/lib/Futures/SharedState.h b/lib/Futures/SharedState.h index 040c1460c0..e6fa22bf69 100644 --- a/lib/Futures/SharedState.h +++ b/lib/Futures/SharedState.h @@ -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& getTry() { + Try& getTry() noexcept { TRI_ASSERT(hasResult()); return _result; } - Try const& getTry() const { + Try 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