diff --git a/backend/library/include/adminive/managed.hpp b/backend/library/include/adminive/managed.hpp index 25d5230..21cfed7 100644 --- a/backend/library/include/adminive/managed.hpp +++ b/backend/library/include/adminive/managed.hpp @@ -302,9 +302,9 @@ public: } template decltype(auto) read(Function&& function) const requires std::invocable && detail::Managed_Callback_Result> { - const auto& keys = detail::managed_key_array(); - auto guard = this->lock_shared(std::span{keys}); - return std::invoke(std::forward(function), std::as_const(value_)); + return this->with_all_readable_locked([&](const auto&) -> decltype(auto) { + return std::invoke(std::forward(function), std::as_const(value_)); + }); } template decltype(auto) write(Function&& function) requires std::invocable && detail::Managed_Callback_Result> { @@ -362,15 +362,12 @@ public: explicit Managed_Field(Managed& owner) : owner_(&owner) {} template decltype(auto) read(Function&& function) const requires std::invocable && detail::Managed_Callback_Result> { - if constexpr(detail::managed_path_requires_synchronization()) { - const auto key = detail::Managed_Key_Attribute::value.view(); - auto guard = owner_->lock_shared({key}); - const auto& value = detail::managed_path_value(owner_->unsafe_value()); - return std::invoke(std::forward(function), value); - } else { - const auto& value = detail::managed_path_value(owner_->unsafe_value()); - return std::invoke(std::forward(function), value); - } + return owner_->template with_read_index([&](const auto& root_value) -> decltype(auto) { + if constexpr(sizeof...(Members) == 0) + return std::invoke(std::forward(function), root_value); + else + return std::invoke(std::forward(function), detail::path_value(root_value)); + }); } template decltype(auto) write(Function&& function) requires (!std::is_const_v) && (detail::managed_path_writable()) && std::invocable && detail::Managed_Callback_Result> {