Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions src/httpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -71,8 +75,7 @@ class WorkQueue
/** Mutex protects entire object */
CWaitableCriticalSection cs;
CConditionVariable cond;
/* XXX in C++11 we can use std::unique_ptr here and avoid manual cleanup */
std::deque<WorkItem*> queue;
std::deque<std::unique_ptr<WorkItem>> queue;
bool running;
size_t maxDepth;
int numThreads;
Expand Down Expand Up @@ -101,24 +104,14 @@ class WorkQueue
numThreads(0)
{
}
/*( Precondition: worker threads have all stopped
* (call WaitExit)
*/
~WorkQueue()
{
while (!queue.empty()) {
delete queue.front();
queue.pop_front();
}
}
/** Enqueue a work item */
bool Enqueue(WorkItem* item)
{
boost::unique_lock<boost::mutex> lock(cs);
if (queue.size() >= maxDepth) {
return false;
}
queue.push_back(item);
queue.push_back(std::unique_ptr<WorkItem>(item));
cond.notify_one();
return true;
}
Expand All @@ -127,18 +120,17 @@ class WorkQueue
{
ThreadCounter count(*this);
while (running) {
WorkItem* i = 0;
std::unique_ptr<WorkItem> i;
{
boost::unique_lock<boost::mutex> lock(cs);
while (running && queue.empty())
cond.wait(lock);
if (!running)
break;
i = queue.front();
i = std::move(queue.front());
queue.pop_front();
}
(*i)();
delete i;
}
}
/** Interrupt and exit loops */
Expand Down Expand Up @@ -252,7 +244,7 @@ static std::string RequestMethodString(HTTPRequest::RequestMethod m)
/** HTTP request callback */
static void http_request_cb(struct evhttp_request* req, void* arg)
{
std::auto_ptr<HTTPRequest> hreq(new HTTPRequest(req));
std::unique_ptr<HTTPRequest> hreq(new HTTPRequest(req));

LogPrint("http", "Received a %s request for %s from %s\n",
RequestMethodString(hreq->GetRequestMethod()), hreq->GetURI(), hreq->GetPeer().ToString());
Expand Down Expand Up @@ -288,7 +280,7 @@ static void http_request_cb(struct evhttp_request* req, void* arg)

// Dispatch to worker thread
if (i != iend) {
std::auto_ptr<HTTPWorkItem> item(new HTTPWorkItem(hreq.release(), path, i->handler));
std::unique_ptr<HTTPWorkItem> item(new HTTPWorkItem(hreq.release(), path, i->handler));
assert(workQueue);
if (workQueue->Enqueue(item.get()))
item.release(); /* if true, queue took ownership */
Expand Down
3 changes: 2 additions & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <boost/thread.hpp>
#include <boost/tuple/tuple.hpp>
#include <memory>
#include <queue>

using namespace std;
Expand Down Expand Up @@ -74,7 +75,7 @@ int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParam
CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const CScript& scriptPubKeyIn)
{
// Create new block
auto_ptr<CBlockTemplate> pblocktemplate(new CBlockTemplate());
std::unique_ptr<CBlockTemplate> pblocktemplate(new CBlockTemplate());
if(!pblocktemplate.get())
return NULL;
CBlock *pblock = &pblocktemplate->block; // pointer for convenience
Expand Down
3 changes: 2 additions & 1 deletion src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "utilstrencodings.h"
#include "validationinterface.h"

#include <memory>
#include <stdint.h>

#include <boost/assign/list_of.hpp>
Expand Down Expand Up @@ -111,7 +112,7 @@ UniValue generateBlocks(boost::shared_ptr<CReserveScript> coinbaseScript, int nG
UniValue blockHashes(UniValue::VARR);
while (nHeight < nHeightEnd)
{
auto_ptr<CBlockTemplate> pblocktemplate(CreateNewBlock(Params(), coinbaseScript->reserveScript));
std::unique_ptr<CBlockTemplate> pblocktemplate(CreateNewBlock(Params(), coinbaseScript->reserveScript));
if (!pblocktemplate.get())
throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block");
CBlock *pblock = &pblocktemplate->block;
Expand Down