Skip to content
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
wants to merge 1 commit into from

Conversation

domob1812
Copy link
Contributor

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.

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.
@sipa
Copy link
Member

sipa commented May 1, 2016 via email

@domob1812
Copy link
Contributor Author

Ah, this contains parts of my patch, but not the WorkQueue change. I suggest to rebase this once #7964 is merged.

@sipa
Copy link
Member

sipa commented May 1, 2016 via email

@maflcko
Copy link
Member

maflcko commented May 1, 2016

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>

@domob1812
Copy link
Contributor Author

Well, ok, I guess then nothing remains of this patch and the PR can be closed....

@laanwj laanwj closed this May 2, 2016
@laanwj
Copy link
Member

laanwj commented May 2, 2016

Right, the overlap with other pulls is too large, closing.

@domob1812 domob1812 deleted the unique-ptr branch May 2, 2016 16:02
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants