-
Notifications
You must be signed in to change notification settings - Fork 37.7k
http: Do a pending c++11 simplification handling work items #7966
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
Conversation
@@ -71,8 +71,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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, in C++11, you no longer need to avoid the '>>' in Template1<Template2<Template3>>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just about to ask why the space is there...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@paveljanik because >>
is an operator. But yes with c++11 this is apparently parsed differently so will remove the space.
c0c7d8b
to
3fc99f4
Compare
@@ -106,19 +105,15 @@ class WorkQueue | |||
*/ | |||
~WorkQueue() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need an empty destructor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, I'm going to keep it, the precondition comment is still relevant.
fa1b71a
to
d16d992
Compare
Decided to forget about using std::move to move items conditionally into the queue, the resulting code was too complex, the old code is cleaner. |
827a36f
to
867bc6d
Compare
@@ -118,7 +112,7 @@ class WorkQueue | |||
if (queue.size() >= maxDepth) { | |||
return false; | |||
} | |||
queue.push_back(item); | |||
queue.push_back(std::unique_ptr<WorkItem>(item)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: queue.emplace_back(item);
ut ACK, other than the little nit |
Use std::unique_ptr for handling work items. This makes the code more RAII and, as mentioned in the comment, is what I planned when I wrote the code in the first place.
More useful error reporting.
No need for boost here.
Thanks to Cory Fields for the idea.
867bc6d
to
f0188f9
Compare
Fixed @theuni's nit, thanks |
f0188f9 http: use std::move to move HTTPRequest into HTTPWorkItem (Wladimir J. van der Laan) 37b2137 http: Change boost::scoped_ptr to std::unique_ptr in HTTPRequest (Wladimir J. van der Laan) f97b410 http: Add log message when work queue is full (Wladimir J. van der Laan) 091d6e0 http: Do a pending c++11 simplification (Wladimir J. van der Laan)
@@ -118,7 +112,7 @@ class WorkQueue | |||
if (queue.size() >= maxDepth) { | |||
return false; | |||
} | |||
queue.push_back(item); | |||
queue.emplace_back(std::unique_ptr<WorkItem>(item)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating the unique_ptr here defeats the purpose of the emplace :)
Passing it item directly would mean that the unique_ptr would be constructed in-place. As is, it's moved instead.
Not worth worrying about, just pointing it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes by all means feel free to improve this further.
…work items f0188f9 http: use std::move to move HTTPRequest into HTTPWorkItem (Wladimir J. van der Laan) 37b2137 http: Change boost::scoped_ptr to std::unique_ptr in HTTPRequest (Wladimir J. van der Laan) f97b410 http: Add log message when work queue is full (Wladimir J. van der Laan) 091d6e0 http: Do a pending c++11 simplification (Wladimir J. van der Laan)
HTTP Server cherries from Core: bitcoin/bitcoin#6719 - Make HTTP server shutdown more graceful bitcoin/bitcoin#6859 - http: Restrict maximum size of http + headers bitcoin/bitcoin#6990 - http: speed up shutdown bitcoin/bitcoin#7966 - http: Do a pending c++11 simplification handling work items bitcoin/bitcoin#8421 - httpserver: drop boost (#8023 dependency) bitcoin/bitcoin#11006 - Improve shutdown process
HTTP Server cherries from Core: bitcoin/bitcoin#6719 - Make HTTP server shutdown more graceful bitcoin/bitcoin#6859 - http: Restrict maximum size of http + headers bitcoin/bitcoin#6990 - http: speed up shutdown bitcoin/bitcoin#7966 - http: Do a pending c++11 simplification handling work items bitcoin/bitcoin#8421 - httpserver: drop boost (#8023 dependency) bitcoin/bitcoin#11006 - Improve shutdown process
Small httpserver.cpp backports Also includes a change to the `uiInterface.NotifyBlockTip` signal API. These remove merge conflicts from subsequent backports for `sync.h`. Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#6859 - bitcoin/bitcoin#7112 - Only the non-QT changes. - bitcoin/bitcoin#7966 - bitcoin/bitcoin#8421 - We already backported the second commit in #2555
Use
std::unique_ptr
for handling http work items, andstd::move
to move them into and out of the queue.This makes the code more RAII and, as mentioned in the comment, is what I planned when I wrote the code in the first place.