New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use std::unique_ptr instead of auto_ptr. #7983
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
With C++11 available, we can use std::unique_ptr instead of the (now deprecated) std::auto_ptr. Also use std::unique_ptr in httpserver.cpp to resolve an XXX remark there and simplify the code.
have you seen #7964?
|
Ah, this contains parts of my patch, but not the |
Perhaps also see #7966.
|
diff between the existing pulls and this one: diff --git a/src/chain.h b/src/chain.h
index 017d4fe..5b9605a 100644
--- a/src/chain.h
+++ b/src/chain.h
@@ -54,7 +54,7 @@ struct CDiskBlockPos
};
-enum BlockStatus: uint32_t {
+enum BlockStatus {
//! Unused.
BLOCK_VALID_UNKNOWN = 0,
diff --git a/src/httpserver.cpp b/src/httpserver.cpp
index 55c81c1..64a0c31 100644
--- a/src/httpserver.cpp
+++ b/src/httpserver.cpp
@@ -34,6 +34,10 @@
#endif
#endif
+#include <deque>
+#include <memory>
+#include <utility>
+
#include <boost/algorithm/string/case_conv.hpp> // for to_lower()
#include <boost/foreach.hpp>
#include <boost/scoped_ptr.hpp>
@@ -100,20 +104,14 @@ public:
numThreads(0)
{
}
- /*( Precondition: worker threads have all stopped
- * (call WaitExit)
- */
- ~WorkQueue()
- {
- }
/** Enqueue a work item */
- bool Enqueue(std::unique_ptr<WorkItem> item)
+ bool Enqueue(WorkItem* item)
{
boost::unique_lock<boost::mutex> lock(cs);
if (queue.size() >= maxDepth) {
return false;
}
- queue.push_back(std::move(item));
+ queue.push_back(std::unique_ptr<WorkItem>(item));
cond.notify_one();
return true;
}
@@ -284,7 +282,9 @@ static void http_request_cb(struct evhttp_request* req, void* arg)
if (i != iend) {
std::unique_ptr<HTTPWorkItem> item(new HTTPWorkItem(hreq.release(), path, i->handler));
assert(workQueue);
- if (!workQueue->Enqueue(std::move(item)))
+ if (workQueue->Enqueue(item.get()))
+ item.release(); /* if true, queue took ownership */
+ else
item->req->WriteReply(HTTP_INTERNAL, "Work queue depth exceeded");
} else {
hreq->WriteReply(HTTP_NOTFOUND);
diff --git a/src/miner.cpp b/src/miner.cpp
index eaf29a7..d4aec3c 100644
--- a/src/miner.cpp
+++ b/src/miner.cpp
@@ -27,6 +27,7 @@
#include <boost/thread.hpp>
#include <boost/tuple/tuple.hpp>
+#include <memory>
#include <queue>
using namespace std;
diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp
index 9a7d9d5..eeb8675 100644
--- a/src/rpc/mining.cpp
+++ b/src/rpc/mining.cpp
@@ -21,6 +21,7 @@
#include "utilstrencodings.h"
#include "validationinterface.h"
+#include <memory>
#include <stdint.h>
#include <boost/assign/list_of.hpp> |
Well, ok, I guess then nothing remains of this patch and the PR can be closed.... |
Right, the overlap with other pulls is too large, closing. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With C++11 available, we can use
std::unique_ptr
instead of the (now deprecated)std::auto_ptr
. Also usestd::unique_ptr
inhttpserver.cpp
to resolve an "XXX remark" there and simplify the code.