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: ...@@ -205,6 +205,10 @@ public:
return nullptr; return nullptr;
} }
std::unique_ptr<Entry> popSafe() {
return std::unique_ptr<Entry>(pop());
}
private: private:
std::atomic<Entry *> head; std::atomic<Entry *> head;
Entry *tail; Entry *tail;
......
...@@ -213,7 +213,7 @@ void ...@@ -213,7 +213,7 @@ void
Transport::handleRequestsQueue() { Transport::handleRequestsQueue() {
// Let's drain the queue // Let's drain the queue
for (;;) { for (;;) {
std::unique_ptr<PollableQueue<InflightRequest>::Entry> entry(requestsQueue.pop()); auto entry = requestsQueue.popSafe();
if (!entry) break; if (!entry) break;
auto &req = entry->data(); auto &req = entry->data();
...@@ -224,7 +224,7 @@ Transport::handleRequestsQueue() { ...@@ -224,7 +224,7 @@ Transport::handleRequestsQueue() {
void void
Transport::handleConnectionQueue() { Transport::handleConnectionQueue() {
for (;;) { for (;;) {
std::unique_ptr<PollableQueue<PendingConnection>::Entry> entry(connectionsQueue.pop()); auto entry = connectionsQueue.popSafe();
if (!entry) break; if (!entry) break;
auto &conn = entry->data(); auto &conn = entry->data();
...@@ -402,7 +402,7 @@ Connection::performImpl( ...@@ -402,7 +402,7 @@ Connection::performImpl(
void void
Connection::processRequestQueue() { Connection::processRequestQueue() {
for (;;) { for (;;) {
std::unique_ptr<Queue<RequestData>::Entry> entry(requestsQueue.pop()); auto entry = requestsQueue.popSafe();
if (!entry) break; if (!entry) break;
auto &req = entry->data(); auto &req = entry->data();
...@@ -595,7 +595,7 @@ Client::processRequestQueue() { ...@@ -595,7 +595,7 @@ Client::processRequestQueue() {
auto conn = pool.pickConnection(); auto conn = pool.pickConnection();
if (!conn) break; if (!conn) break;
std::unique_ptr<Queue<Connection::RequestData>::Entry> entry(requestsQueue.pop()); auto entry = requestsQueue.popSafe();
if (!entry) { if (!entry) {
pool.releaseConnection(conn); pool.releaseConnection(conn);
break; break;
......
...@@ -273,7 +273,7 @@ void ...@@ -273,7 +273,7 @@ void
Transport::handleWriteQueue() { Transport::handleWriteQueue() {
// Let's drain the queue // Let's drain the queue
for (;;) { for (;;) {
std::unique_ptr<PollableQueue<OnHoldWrite>::Entry> entry(writesQueue.pop()); auto entry = writesQueue.popSafe();
if (!entry) break; if (!entry) break;
auto &write = entry->data(); auto &write = entry->data();
...@@ -284,7 +284,7 @@ Transport::handleWriteQueue() { ...@@ -284,7 +284,7 @@ Transport::handleWriteQueue() {
void void
Transport::handleTimerQueue() { Transport::handleTimerQueue() {
for (;;) { for (;;) {
std::unique_ptr<PollableQueue<TimerEntry>::Entry> entry(timersQueue.pop()); auto entry = timersQueue.popSafe();
if (!entry) break; if (!entry) break;
auto &timer = entry->data(); 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