Skip to content

Commit

Permalink
RedisConnection#Connect(): get rid of spin lock
Browse files Browse the repository at this point in the history
Instead of IoEngine::YieldCurrentCoroutine(yc) until m_Queues.FutureResponseActions.empty(), async-wait a CV which is updated along with m_Queues.FutureResponseActions.
  • Loading branch information
Al2Klimov committed Jan 29, 2025
1 parent 364cc6e commit fd24514
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
12 changes: 3 additions & 9 deletions lib/icingadb/redisconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,6 @@ void RedisConnection::Connect(asio::yield_context& yc)

boost::asio::deadline_timer timer (m_Strand.context());

auto waitForReadLoop ([this, &yc]() {
while (!m_Queues.FutureResponseActions.empty()) {
IoEngine::YieldCurrentCoroutine(yc);
}
});

for (;;) {
try {
if (m_Path.IsEmpty()) {
Expand Down Expand Up @@ -339,7 +333,7 @@ void RedisConnection::Connect(asio::yield_context& yc)
}

Handshake(conn, yc);
waitForReadLoop();
m_QueuedReads.Wait(yc, false);
m_TlsConn = std::move(conn);
} else {
Log(m_Parent ? LogNotice : LogInformation, "IcingaDB")
Expand All @@ -350,7 +344,7 @@ void RedisConnection::Connect(asio::yield_context& yc)

icinga::Connect(conn->next_layer(), m_Host, Convert::ToString(m_Port), yc);
Handshake(conn, yc);
waitForReadLoop();
m_QueuedReads.Wait(yc, false);
m_TcpConn = std::move(conn);
}
} else {
Expand All @@ -362,7 +356,7 @@ void RedisConnection::Connect(asio::yield_context& yc)

conn->next_layer().async_connect(Unix::endpoint(m_Path.CStr()), yc);
Handshake(conn, yc);
waitForReadLoop();
m_QueuedReads.Wait(yc, false);
m_UnixConn = std::move(conn);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/icingadb/redisconnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ namespace icinga
std::set<QueryPriority> m_SuppressedQueryKinds;

// Indicate that there's something to send/receive
AsioEvent m_QueuedWrites, m_QueuedReads;
AsioEvent m_QueuedWrites;
AsioSymmetricEvent m_QueuedReads;

std::function<void(boost::asio::yield_context& yc)> m_ConnectedCallback;

Expand Down

0 comments on commit fd24514

Please sign in to comment.