Commit 7e3ff879 authored by octal's avatar octal

Added a safe poping interface to the wait-free queue that returns an unique_ptr

parent b72ea357
......@@ -205,6 +205,10 @@ public:
return nullptr;
}
std::unique_ptr<Entry> popSafe() {
return std::unique_ptr<Entry>(pop());
}
private:
std::atomic<Entry *> head;
Entry *tail;
......
......@@ -213,7 +213,7 @@ void
Transport::handleRequestsQueue() {
// Let's drain the queue
for (;;) {
std::unique_ptr<PollableQueue<InflightRequest>::Entry> entry(requestsQueue.pop());
auto entry = requestsQueue.popSafe();
if (!entry) break;
auto &req = entry->data();
......@@ -224,7 +224,7 @@ Transport::handleRequestsQueue() {
void
Transport::handleConnectionQueue() {
for (;;) {
std::unique_ptr<PollableQueue<PendingConnection>::Entry> entry(connectionsQueue.pop());
auto entry = connectionsQueue.popSafe();
if (!entry) break;
auto &conn = entry->data();
......@@ -402,7 +402,7 @@ Connection::performImpl(
void
Connection::processRequestQueue() {
for (;;) {
std::unique_ptr<Queue<RequestData>::Entry> entry(requestsQueue.pop());
auto entry = requestsQueue.popSafe();
if (!entry) break;
auto &req = entry->data();
......@@ -595,7 +595,7 @@ Client::processRequestQueue() {
auto conn = pool.pickConnection();
if (!conn) break;
std::unique_ptr<Queue<Connection::RequestData>::Entry> entry(requestsQueue.pop());
auto entry = requestsQueue.popSafe();
if (!entry) {
pool.releaseConnection(conn);
break;
......
......@@ -273,7 +273,7 @@ void
Transport::handleWriteQueue() {
// Let's drain the queue
for (;;) {
std::unique_ptr<PollableQueue<OnHoldWrite>::Entry> entry(writesQueue.pop());
auto entry = writesQueue.popSafe();
if (!entry) break;
auto &write = entry->data();
......@@ -284,7 +284,7 @@ Transport::handleWriteQueue() {
void
Transport::handleTimerQueue() {
for (;;) {
std::unique_ptr<PollableQueue<TimerEntry>::Entry> entry(timersQueue.pop());
auto entry = timersQueue.popSafe();
if (!entry) break;
auto &timer = entry->data();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment