Skip to content

Commit b4304d5

Browse files
committed
mgr/DaemonState: Minimise time we hold the DaemonStateIndex lock
Calling back into python functions whilst holding the lock can result in this thread being queued for the GIL and resulting in extended delays for threads waiting to acquire the lock. Fixes: https://tracker.ceph.com/issues/72337 Signed-off-by: Brad Hubbard <[email protected]>
1 parent f5aafe0 commit b4304d5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/mgr/DaemonState.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,12 @@ class DaemonStateIndex
261261
template<typename Callback, typename...Args>
262262
auto with_daemons_by_server(Callback&& cb, Args&&... args) const ->
263263
decltype(cb(by_server, std::forward<Args>(args)...)) {
264-
std::shared_lock l{lock};
265-
266-
return std::forward<Callback>(cb)(by_server, std::forward<Args>(args)...);
264+
const decltype(by_server) by_server_copy = [&] {
265+
// Don't hold the lock any longer than necessary
266+
std::shared_lock l{lock};
267+
return by_server;
268+
}();
269+
return std::forward<Callback>(cb)(by_server_copy, std::forward<Args>(args)...);
267270
}
268271

269272
template<typename Callback, typename...Args>

0 commit comments

Comments
 (0)