Skip to content

Commit 6f4f289

Browse files
committed
Replace KJ_DEFER with kj::defer
1 parent 7a8a99c commit 6f4f289

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

include/mp/type-context.h

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -103,25 +103,27 @@ auto PassField(Priority<1>, TypeList<>, ServerContext& server_context, const Fn&
103103
// recursive call (IPC call calling back to the caller which
104104
// makes another IPC call), so avoid modifying the map.
105105
const bool erase_thread{inserted};
106-
KJ_DEFER(if (erase_thread) {
107-
// Erase the request_threads entry on the event loop
108-
// thread with loop->sync(), so if the connection is
109-
// broken there is not a race between this thread and
110-
// the disconnect handler trying to destroy the thread
111-
// client object.
112-
server.m_context.loop->sync([&] {
113-
// Look up the thread again without using existing
114-
// iterator since entry may no longer be there after
115-
// a disconnect. Destroy node after releasing
116-
// Waiter::m_mutex, so the ProxyClient<Thread>
117-
// destructor is able to use EventLoop::mutex
118-
// without violating lock order.
119-
ConnThreads::node_type removed;
120-
{
121-
std::unique_lock<std::mutex> lock(thread_context.waiter->m_mutex);
122-
removed = request_threads.extract(server.m_context.connection);
123-
}
124-
});
106+
[[maybe_unused]] const auto _cleanup = kj::defer([&] {
107+
if (erase_thread) {
108+
// Erase the request_threads entry on the event loop
109+
// thread with loop->sync(), so if the connection is
110+
// broken there is not a race between this thread and
111+
// the disconnect handler trying to destroy the thread
112+
// client object.
113+
server.m_context.loop->sync([&] {
114+
// Look up the thread again without using existing
115+
// iterator since entry may no longer be there after
116+
// a disconnect. Destroy node after releasing
117+
// Waiter::m_mutex, so the ProxyClient<Thread>
118+
// destructor is able to use EventLoop::mutex
119+
// without violating lock order.
120+
ConnThreads::node_type removed;
121+
{
122+
std::unique_lock<std::mutex> lock(thread_context.waiter->m_mutex);
123+
removed = request_threads.extract(server.m_context.connection);
124+
}
125+
});
126+
}
125127
});
126128
fn.invoke(server_context, args...);
127129
}

src/mp/proxy.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,9 @@ void EventLoop::loop()
223223
{
224224
assert(!g_thread_context.loop_thread);
225225
g_thread_context.loop_thread = true;
226-
KJ_DEFER(g_thread_context.loop_thread = false);
226+
[[maybe_unused]] const auto _cleanup = kj::defer([&] {
227+
g_thread_context.loop_thread = false;
228+
});
227229

228230
{
229231
const Lock lock(m_mutex);

0 commit comments

Comments
 (0)