diff options
author | Olha Vorobiova (GitHub) <86727408+OlhaVorobiova@users.noreply.github.com> | 2022-03-09 21:56:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-09 14:56:35 -0500 |
commit | 15ddebb432041fd541f43e02de17b35083c2f169 (patch) | |
tree | 52e0de39e3b715219e7fcee761054325b7046df5 /src/components | |
parent | c55e2f28ff97fc031440e431da386ad5cd9e797f (diff) | |
download | sdl_core-15ddebb432041fd541f43e02de17b35083c2f169.tar.gz |
Add missed locks (#3864)
Diffstat (limited to 'src/components')
8 files changed, 66 insertions, 6 deletions
diff --git a/src/components/policy/policy_external/include/policy/policy_manager_impl.h b/src/components/policy/policy_external/include/policy/policy_manager_impl.h index 2be8183bfa..7822cc26f6 100644 --- a/src/components/policy/policy_external/include/policy/policy_manager_impl.h +++ b/src/components/policy/policy_external/include/policy/policy_manager_impl.h @@ -1266,6 +1266,11 @@ class PolicyManagerImpl : public PolicyManager { sync_primitives::Lock apps_registration_lock_; /** + * @brief lock guard for protecting policy table snapshot + */ + sync_primitives::Lock policy_table_lock_; + + /** * @brief lock guard for protecting application permissions access */ sync_primitives::Lock app_permissions_diff_lock_; diff --git a/src/components/policy/policy_external/src/access_remote_impl.cc b/src/components/policy/policy_external/src/access_remote_impl.cc index 037f4551f1..4effb991c8 100644 --- a/src/components/policy/policy_external/src/access_remote_impl.cc +++ b/src/components/policy/policy_external/src/access_remote_impl.cc @@ -98,6 +98,7 @@ bool AccessRemoteImpl::CheckModuleType(const PTString& app_id, return false; } + sync_primitives::AutoLock auto_lock(cache_->cache_lock_); const policy_table::ApplicationParams& app = cache_->pt_->policy_table.app_policies_section.apps[app_id]; if (!app.moduleType.is_initialized()) { @@ -168,6 +169,7 @@ void AccessRemoteImpl::SetDefaultHmiTypes(const ApplicationOnDevice& who, const policy_table::AppHMITypes& AccessRemoteImpl::HmiTypes( const ApplicationOnDevice& who) { SDL_LOG_AUTO_TRACE(); + sync_primitives::AutoLock auto_lock(cache_->cache_lock_); if (cache_->IsDefaultPolicy(who.app_id)) { return hmi_types_[who]; } else { @@ -240,6 +242,7 @@ void AccessRemoteImpl::GetGroupsIds(const std::string& device_id, bool AccessRemoteImpl::GetModuleTypes(const std::string& application_id, std::vector<std::string>* modules) { DCHECK(modules); + sync_primitives::AutoLock auto_lock(cache_->cache_lock_); policy_table::ApplicationPolicies& apps = cache_->pt_->policy_table.app_policies_section.apps; policy_table::ApplicationPolicies::iterator i = apps.find(application_id); diff --git a/src/components/policy/policy_external/src/cache_manager.cc b/src/components/policy/policy_external/src/cache_manager.cc index d5e1e61966..b6ea6e6e79 100644 --- a/src/components/policy/policy_external/src/cache_manager.cc +++ b/src/components/policy/policy_external/src/cache_manager.cc @@ -685,6 +685,7 @@ void CacheManager::ProcessUpdate( const std::string& app_id = initial_policy_iter->first; bool update_request_types = true; + sync_primitives::AutoLock auto_lock(cache_lock_); ApplicationParams& params = pt_->policy_table.app_policies_section.apps[app_id]; if (kPreDataConsentId == app_id) { @@ -1454,15 +1455,19 @@ CacheManager::GetRemovedVehicleDataItems() const { } Json::Value CacheManager::GetPolicyTableData() const { + SDL_LOG_AUTO_TRACE(); + sync_primitives::AutoLock auto_lock(cache_lock_); return pt_->policy_table.ToJsonValue(); } void CacheManager::GetEnabledCloudApps( std::vector<std::string>& enabled_apps) const { + SDL_LOG_AUTO_TRACE(); #if !defined(CLOUD_APP_WEBSOCKET_TRANSPORT_SUPPORT) enabled_apps.clear(); return; #else + sync_primitives::AutoLock auto_lock(cache_lock_); const policy_table::ApplicationPolicies& policies = pt_->policy_table.app_policies_section.apps; for (policy_table::ApplicationPolicies::const_iterator it = policies.begin(); @@ -1478,6 +1483,8 @@ void CacheManager::GetEnabledCloudApps( bool CacheManager::GetAppProperties(const std::string& policy_app_id, AppProperties& out_app_properties) const { + SDL_LOG_AUTO_TRACE(); + sync_primitives::AutoLock auto_lock(cache_lock_); const policy_table::ApplicationPolicies& policies = pt_->policy_table.app_policies_section.apps; policy_table::ApplicationPolicies::const_iterator policy_iter = @@ -1509,10 +1516,12 @@ bool CacheManager::GetAppProperties(const std::string& policy_app_id, } std::vector<std::string> CacheManager::GetEnabledLocalApps() const { + SDL_LOG_AUTO_TRACE(); #if !defined(WEBSOCKET_SERVER_TRANSPORT_SUPPORT) return std::vector<std::string>(); #else std::vector<std::string> enabled_apps; + sync_primitives::AutoLock auto_lock(cache_lock_); const policy_table::ApplicationPolicies& app_policies = pt_->policy_table.app_policies_section.apps; for (const auto& app_policies_item : app_policies) { @@ -1551,6 +1560,8 @@ void CacheManager::InitCloudApp(const std::string& policy_app_id) { void CacheManager::SetCloudAppEnabled(const std::string& policy_app_id, const bool enabled) { + SDL_LOG_AUTO_TRACE(); + sync_primitives::AutoLock auto_lock(cache_lock_); policy_table::ApplicationPolicies& policies = pt_->policy_table.app_policies_section.apps; policy_table::ApplicationPolicies::iterator policy_iter = @@ -1562,6 +1573,8 @@ void CacheManager::SetCloudAppEnabled(const std::string& policy_app_id, void CacheManager::SetAppAuthToken(const std::string& policy_app_id, const std::string& auth_token) { + SDL_LOG_AUTO_TRACE(); + sync_primitives::AutoLock auto_lock(cache_lock_); policy_table::ApplicationPolicies& policies = pt_->policy_table.app_policies_section.apps; policy_table::ApplicationPolicies::iterator policy_iter = @@ -1573,6 +1586,8 @@ void CacheManager::SetAppAuthToken(const std::string& policy_app_id, void CacheManager::SetAppCloudTransportType( const std::string& policy_app_id, const std::string& cloud_transport_type) { + SDL_LOG_AUTO_TRACE(); + sync_primitives::AutoLock auto_lock(cache_lock_); policy_table::ApplicationPolicies& policies = pt_->policy_table.app_policies_section.apps; policy_table::ApplicationPolicies::iterator policy_iter = @@ -1584,6 +1599,8 @@ void CacheManager::SetAppCloudTransportType( void CacheManager::SetAppEndpoint(const std::string& policy_app_id, const std::string& endpoint) { + SDL_LOG_AUTO_TRACE(); + sync_primitives::AutoLock auto_lock(cache_lock_); policy_table::ApplicationPolicies& policies = pt_->policy_table.app_policies_section.apps; policy_table::ApplicationPolicies::iterator policy_iter = @@ -1595,6 +1612,8 @@ void CacheManager::SetAppEndpoint(const std::string& policy_app_id, void CacheManager::SetAppNicknames(const std::string& policy_app_id, const StringArray& nicknames) { + SDL_LOG_AUTO_TRACE(); + sync_primitives::AutoLock auto_lock(cache_lock_); policy_table::ApplicationPolicies& policies = pt_->policy_table.app_policies_section.apps; policy_table::ApplicationPolicies::iterator policy_iter = @@ -1607,6 +1626,8 @@ void CacheManager::SetAppNicknames(const std::string& policy_app_id, void CacheManager::SetHybridAppPreference( const std::string& policy_app_id, const std::string& hybrid_app_preference) { + SDL_LOG_AUTO_TRACE(); + sync_primitives::AutoLock auto_lock(cache_lock_); policy_table::HybridAppPreference value; bool valid = EnumFromJsonString(hybrid_app_preference, &value); policy_table::ApplicationPolicies& policies = @@ -1622,6 +1643,7 @@ void CacheManager::GetAppServiceParameters( const std::string& policy_app_id, policy_table::AppServiceParameters* app_service_parameters) const { SDL_LOG_AUTO_TRACE(); + sync_primitives::AutoLock auto_lock(cache_lock_); const policy_table::ApplicationPolicies& policies = pt_->policy_table.app_policies_section.apps; policy_table::ApplicationPolicies::const_iterator policy_iter = @@ -1636,6 +1658,8 @@ void CacheManager::GetAppServiceParameters( bool CacheManager::UnknownRPCPassthroughAllowed( const std::string& policy_app_id) const { + SDL_LOG_AUTO_TRACE(); + sync_primitives::AutoLock auto_lock(cache_lock_); const policy_table::ApplicationPolicies& policies = pt_->policy_table.app_policies_section.apps; policy_table::ApplicationPolicies::const_iterator policy_iter = @@ -1747,6 +1771,7 @@ std::vector<UserFriendlyMessage> CacheManager::GetUserFriendlyMsg( void CacheManager::GetUpdateUrls(const uint32_t service_type, EndpointUrls& out_end_points) const { + SDL_LOG_AUTO_TRACE(); auto find_hexademical = [service_type](policy_table::ServiceEndpoints::value_type end_point) { uint32_t decimal; @@ -1754,6 +1779,7 @@ void CacheManager::GetUpdateUrls(const uint32_t service_type, return end_point.first.compare(0, 2, "0x") == 0 && decimal == service_type; }; + sync_primitives::AutoLock auto_lock(cache_lock_); auto& end_points = pt_->policy_table.module_config.endpoints; const auto end_point = std::find_if(end_points.begin(), end_points.end(), find_hexademical); @@ -1791,8 +1817,10 @@ void CacheManager::GetUpdateUrls(const std::string& service_type, } std::string CacheManager::GetIconUrl(const std::string& policy_app_id) const { + SDL_LOG_AUTO_TRACE(); CACHE_MANAGER_CHECK(std::string()); std::string url; + sync_primitives::AutoLock auto_lock(cache_lock_); const policy_table::ApplicationPolicies& policies = pt_->policy_table.app_policies_section.apps; policy_table::ApplicationPolicies::const_iterator policy_iter = @@ -2130,7 +2158,6 @@ std::shared_ptr<policy_table::Table> CacheManager::GenerateSnapshot() { snapshot_ = std::make_shared<policy_table::Table>(); sync_primitives::AutoLock auto_lock(cache_lock_); snapshot_->policy_table = pt_->policy_table; - if (pt_->policy_table.vehicle_data.is_initialized()) { snapshot_->policy_table.vehicle_data = rpc::Optional<policy_table::VehicleData>(); @@ -2138,7 +2165,6 @@ std::shared_ptr<policy_table::Table> CacheManager::GenerateSnapshot() { snapshot_->policy_table.vehicle_data->schema_version = pt_->policy_table.vehicle_data->schema_version; } - snapshot_->SetPolicyTableType(policy_table::PT_SNAPSHOT); CheckSnapshotInitialization(); @@ -2284,6 +2310,7 @@ int CacheManager::CountUnconsentedGroups(const std::string& policy_app_id, void CacheManager::SetPreloadedPtFlag(const bool is_preloaded) { SDL_LOG_AUTO_TRACE(); + sync_primitives::AutoLock auto_lock(cache_lock_); *pt_->policy_table.module_config.preloaded_pt = is_preloaded; Backup(); } @@ -2680,7 +2707,7 @@ bool CacheManager::Init(const std::string& file_name, result &= snapshot->is_valid(); SDL_LOG_DEBUG("Check if snapshot valid: " << std::boolalpha << result); - + sync_primitives::AutoLock auto_lock(cache_lock_); if (!UnwrapAppPolicies(pt_->policy_table.app_policies_section.apps)) { SDL_LOG_ERROR("Cannot unwrap application policies"); } diff --git a/src/components/policy/policy_external/src/policy_manager_impl.cc b/src/components/policy/policy_external/src/policy_manager_impl.cc index b975b83712..60ab5a389e 100644 --- a/src/components/policy/policy_external/src/policy_manager_impl.cc +++ b/src/components/policy/policy_external/src/policy_manager_impl.cc @@ -486,7 +486,9 @@ PolicyManager::PtProcessingResult PolicyManagerImpl::LoadPT( } cache_->SaveUpdateRequired(false); + sync_primitives::AutoLock lock(apps_registration_lock_); + sync_primitives::AutoLock policy_lock(policy_table_lock_); // Get current DB data, since it could be updated during awaiting of PTU auto policy_table_snapshot = cache_->GenerateSnapshot(); @@ -704,6 +706,7 @@ void PolicyManagerImpl::GetUpdateUrls(const uint32_t service_type, void PolicyManagerImpl::RequestPTUpdate() { SDL_LOG_AUTO_TRACE(); + sync_primitives::AutoLock policy_lock(policy_table_lock_); std::shared_ptr<policy_table::Table> policy_table_snapshot = cache_->GenerateSnapshot(); if (!policy_table_snapshot) { @@ -1772,6 +1775,7 @@ void PolicyManagerImpl::SendPermissionsToApp( Permissions notification_data; // Need to get rid of this call + sync_primitives::AutoLock policy_lock(policy_table_lock_); std::shared_ptr<policy_table::Table> policy_table_snapshot = cache_->GenerateSnapshot(); diff --git a/src/components/policy/policy_external/src/policy_table/types.cc b/src/components/policy/policy_external/src/policy_table/types.cc index fffa6a7848..c382016169 100644 --- a/src/components/policy/policy_external/src/policy_table/types.cc +++ b/src/components/policy/policy_external/src/policy_table/types.cc @@ -2,7 +2,6 @@ #include <algorithm> #include <regex> - #include "rpc_base/rpc_base_json_inl.h" namespace rpc { diff --git a/src/components/policy/policy_regular/include/policy/policy_manager_impl.h b/src/components/policy/policy_regular/include/policy/policy_manager_impl.h index 0d1a61ec89..16ab9417bb 100644 --- a/src/components/policy/policy_regular/include/policy/policy_manager_impl.h +++ b/src/components/policy/policy_regular/include/policy/policy_manager_impl.h @@ -1103,6 +1103,11 @@ class PolicyManagerImpl : public PolicyManager { sync_primitives::Lock apps_registration_lock_; /** + * @brief lock guard for protecting policy table snapshot + */ + sync_primitives::Lock policy_table_lock_; + + /** * @brief lock guard for protecting application permissions access */ sync_primitives::Lock app_permissions_diff_lock_; diff --git a/src/components/policy/policy_regular/src/cache_manager.cc b/src/components/policy/policy_regular/src/cache_manager.cc index 9cce86322a..4d066e9c32 100644 --- a/src/components/policy/policy_regular/src/cache_manager.cc +++ b/src/components/policy/policy_regular/src/cache_manager.cc @@ -742,6 +742,7 @@ CacheManager::GetRemovedVehicleDataItems() const { } Json::Value CacheManager::GetPolicyTableData() const { + sync_primitives::AutoLock auto_lock(cache_lock_); return pt_->policy_table.ToJsonValue(); } @@ -751,6 +752,7 @@ void CacheManager::GetEnabledCloudApps( enabled_apps.clear(); return; #else + sync_primitives::AutoLock auto_lock(cache_lock_); const policy_table::ApplicationPolicies& policies = pt_->policy_table.app_policies_section.apps; for (policy_table::ApplicationPolicies::const_iterator it = policies.begin(); @@ -769,6 +771,7 @@ std::vector<std::string> CacheManager::GetEnabledLocalApps() const { return std::vector<std::string>(); #else std::vector<std::string> enabled_apps; + sync_primitives::AutoLock auto_lock(cache_lock_); const policy_table::ApplicationPolicies& app_policies = pt_->policy_table.app_policies_section.apps; for (const auto& app_policies_item : app_policies) { @@ -788,6 +791,7 @@ std::vector<std::string> CacheManager::GetEnabledLocalApps() const { bool CacheManager::GetAppProperties(const std::string& policy_app_id, AppProperties& out_app_properties) const { + sync_primitives::AutoLock auto_lock(cache_lock_); const policy_table::ApplicationPolicies& policies = pt_->policy_table.app_policies_section.apps; policy_table::ApplicationPolicies::const_iterator policy_iter = @@ -841,6 +845,7 @@ void CacheManager::InitCloudApp(const std::string& policy_app_id) { void CacheManager::SetCloudAppEnabled(const std::string& policy_app_id, const bool enabled) { + sync_primitives::AutoLock auto_lock(cache_lock_); policy_table::ApplicationPolicies& policies = pt_->policy_table.app_policies_section.apps; policy_table::ApplicationPolicies::iterator policy_iter = @@ -852,6 +857,7 @@ void CacheManager::SetCloudAppEnabled(const std::string& policy_app_id, void CacheManager::SetAppAuthToken(const std::string& policy_app_id, const std::string& auth_token) { + sync_primitives::AutoLock auto_lock(cache_lock_); policy_table::ApplicationPolicies& policies = pt_->policy_table.app_policies_section.apps; policy_table::ApplicationPolicies::iterator policy_iter = @@ -863,6 +869,7 @@ void CacheManager::SetAppAuthToken(const std::string& policy_app_id, void CacheManager::SetAppCloudTransportType( const std::string& policy_app_id, const std::string& cloud_transport_type) { + sync_primitives::AutoLock auto_lock(cache_lock_); policy_table::ApplicationPolicies& policies = pt_->policy_table.app_policies_section.apps; policy_table::ApplicationPolicies::iterator policy_iter = @@ -874,6 +881,7 @@ void CacheManager::SetAppCloudTransportType( void CacheManager::SetAppEndpoint(const std::string& policy_app_id, const std::string& endpoint) { + sync_primitives::AutoLock auto_lock(cache_lock_); policy_table::ApplicationPolicies& policies = pt_->policy_table.app_policies_section.apps; policy_table::ApplicationPolicies::iterator policy_iter = @@ -885,6 +893,7 @@ void CacheManager::SetAppEndpoint(const std::string& policy_app_id, void CacheManager::SetAppNicknames(const std::string& policy_app_id, const StringArray& nicknames) { + sync_primitives::AutoLock auto_lock(cache_lock_); policy_table::ApplicationPolicies& policies = pt_->policy_table.app_policies_section.apps; policy_table::ApplicationPolicies::iterator policy_iter = @@ -897,6 +906,7 @@ void CacheManager::SetAppNicknames(const std::string& policy_app_id, void CacheManager::SetHybridAppPreference( const std::string& policy_app_id, const std::string& hybrid_app_preference) { + sync_primitives::AutoLock auto_lock(cache_lock_); policy_table::HybridAppPreference value; bool valid = EnumFromJsonString(hybrid_app_preference, &value); policy_table::ApplicationPolicies& policies = @@ -912,6 +922,7 @@ void CacheManager::GetAppServiceParameters( const std::string& policy_app_id, policy_table::AppServiceParameters* app_service_parameters) const { SDL_LOG_AUTO_TRACE(); + sync_primitives::AutoLock auto_lock(cache_lock_); const policy_table::ApplicationPolicies& policies = pt_->policy_table.app_policies_section.apps; policy_table::ApplicationPolicies::const_iterator policy_iter = @@ -926,6 +937,7 @@ void CacheManager::GetAppServiceParameters( bool CacheManager::UnknownRPCPassthroughAllowed( const std::string& policy_app_id) const { + sync_primitives::AutoLock auto_lock(cache_lock_); const policy_table::ApplicationPolicies& policies = pt_->policy_table.app_policies_section.apps; policy_table::ApplicationPolicies::const_iterator policy_iter = @@ -1047,6 +1059,7 @@ void CacheManager::GetUpdateUrls(const uint32_t service_type, return end_point.first.compare(0, 2, "0x") == 0 && decimal == service_type; }; + sync_primitives::AutoLock auto_lock(cache_lock_); auto& end_points = pt_->policy_table.module_config.endpoints; const auto end_point = std::find_if(end_points.begin(), end_points.end(), find_hexademical); @@ -1086,6 +1099,7 @@ void CacheManager::GetUpdateUrls(const std::string& service_type, std::string CacheManager::GetIconUrl(const std::string& policy_app_id) const { CACHE_MANAGER_CHECK(std::string()); std::string url; + sync_primitives::AutoLock auto_lock(cache_lock_); const policy_table::ApplicationPolicies& policies = pt_->policy_table.app_policies_section.apps; policy_table::ApplicationPolicies::const_iterator policy_iter = @@ -1462,7 +1476,6 @@ bool CacheManager::GetFunctionalGroupings( sync_primitives::AutoLock auto_lock(cache_lock_); const policy_table::FunctionalGroupings& f_groupings = pt_->policy_table.functional_groupings; - groups.insert(f_groupings.begin(), f_groupings.end()); return true; } @@ -1478,6 +1491,7 @@ int CacheManager::CountUnconsentedGroups(const std::string& policy_app_id, void CacheManager::SetPreloadedPtFlag(const bool is_preloaded) { SDL_LOG_AUTO_TRACE(); + sync_primitives::AutoLock auto_lock(cache_lock_); *(pt_->policy_table.module_config.preloaded_pt) = is_preloaded; Backup(); } @@ -1841,7 +1855,7 @@ bool CacheManager::Init(const std::string& file_name, SDL_LOG_DEBUG("Validation report: " << rpc::PrettyFormat(report)); return result; } - + sync_primitives::AutoLock auto_lock(cache_lock_); if (!UnwrapAppPolicies(pt_->policy_table.app_policies_section.apps)) { SDL_LOG_ERROR("Cannot unwrap application policies"); } diff --git a/src/components/policy/policy_regular/src/policy_manager_impl.cc b/src/components/policy/policy_regular/src/policy_manager_impl.cc index 3a41cfa08b..ccc3454708 100644 --- a/src/components/policy/policy_regular/src/policy_manager_impl.cc +++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc @@ -337,6 +337,7 @@ PolicyManager::PtProcessingResult PolicyManagerImpl::LoadPT( cache_->SaveUpdateRequired(false); sync_primitives::AutoLock lock(apps_registration_lock_); + sync_primitives::AutoLock policy_lock(policy_table_lock_); // Get current DB data, since it could be updated during awaiting of PTU auto policy_table_snapshot = cache_->GenerateSnapshot(); @@ -516,6 +517,7 @@ void PolicyManagerImpl::SendPermissionsToApp( Permissions notification_data; // Need to get rid of this call + sync_primitives::AutoLock policy_lock(policy_table_lock_); auto policy_table_snapshot = cache_->GenerateSnapshot(); PrepareNotificationData( @@ -585,6 +587,7 @@ bool PolicyManagerImpl::RequestPTUpdate(const PTUIterationType iteration_type) { SDL_LOG_AUTO_TRACE(); BinaryMessage update; if (PTUIterationType::DefaultIteration == iteration_type) { + sync_primitives::AutoLock policy_lock(policy_table_lock_); std::shared_ptr<policy_table::Table> policy_table_snapshot = cache_->GenerateSnapshot(); if (!policy_table_snapshot) { |