We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents cd40e65 + b4304d5 commit 6bf1c92Copy full SHA for 6bf1c92
src/mgr/DaemonState.h
@@ -261,9 +261,12 @@ class DaemonStateIndex
261
template<typename Callback, typename...Args>
262
auto with_daemons_by_server(Callback&& cb, Args&&... args) const ->
263
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)...);
+ const decltype(by_server) by_server_copy = [&] {
+ // Don't hold the lock any longer than necessary
+ std::shared_lock l{lock};
267
+ return by_server;
268
+ }();
269
+ return std::forward<Callback>(cb)(by_server_copy, std::forward<Args>(args)...);
270
}
271
272
0 commit comments