summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShobhit Adlakha <ShobhitAd@users.noreply.github.com>2018-10-11 13:55:24 -0400
committerGitHub <noreply@github.com>2018-10-11 13:55:24 -0400
commitc9697970a6ad6300936fe893efe7f3acae92a7c0 (patch)
tree10ef0d9684931ee6ebe5c4ac4938dd288124fcfe
parent8da2a76d7dbde7845c1116034f8a60490f4fad0c (diff)
parent5e5c4299dbac4edac0c59983e274b502c702ec47 (diff)
downloadsdl_core-c9697970a6ad6300936fe893efe7f3acae92a7c0.tar.gz
Merge pull request #1569 from LitvinenkoIra/fix/crushes_with_DCHECK_set_sizes_equal
Make Size() function thread safe to avoid core dump
-rw-r--r--src/components/application_manager/include/application_manager/request_info.h3
-rw-r--r--src/components/application_manager/src/request_info.cc13
2 files changed, 8 insertions, 8 deletions
diff --git a/src/components/application_manager/include/application_manager/request_info.h b/src/components/application_manager/include/application_manager/request_info.h
index da1bd0a2ee..be28bad63c 100644
--- a/src/components/application_manager/include/application_manager/request_info.h
+++ b/src/components/application_manager/include/application_manager/request_info.h
@@ -264,8 +264,7 @@ class RequestInfoSet {
TimeSortedRequestInfoSet time_sorted_pending_requests_;
HashSortedRequestInfoSet hash_sorted_pending_requests_;
- // the lock caled this_lock_, since the class represent collection by itself.
- sync_primitives::Lock this_lock_;
+ sync_primitives::Lock pending_requests_lock_;
};
/**
diff --git a/src/components/application_manager/src/request_info.cc b/src/components/application_manager/src/request_info.cc
index cd99a42508..bbcda06b43 100644
--- a/src/components/application_manager/src/request_info.cc
+++ b/src/components/application_manager/src/request_info.cc
@@ -122,7 +122,7 @@ bool RequestInfoSet::Add(RequestInfoPtr request_info) {
logger_,
"Add request app_id = " << request_info->app_id()
<< "; corr_id = " << request_info->requestId());
- sync_primitives::AutoLock lock(this_lock_);
+ sync_primitives::AutoLock lock(pending_requests_lock_);
CheckSetSizes();
const std::pair<HashSortedRequestInfoSet::iterator, bool>& insert_resilt =
hash_sorted_pending_requests_.insert(request_info);
@@ -153,7 +153,7 @@ RequestInfoPtr RequestInfoSet::Find(const uint32_t connection_key,
std::shared_ptr<FakeRequestInfo> request_info_for_search(
new FakeRequestInfo(connection_key, correlation_id));
- sync_primitives::AutoLock lock(this_lock_);
+ sync_primitives::AutoLock lock(pending_requests_lock_);
HashSortedRequestInfoSet::iterator it =
hash_sorted_pending_requests_.find(request_info_for_search);
if (it != hash_sorted_pending_requests_.end()) {
@@ -165,7 +165,7 @@ RequestInfoPtr RequestInfoSet::Find(const uint32_t connection_key,
RequestInfoPtr RequestInfoSet::Front() {
RequestInfoPtr result;
- sync_primitives::AutoLock lock(this_lock_);
+ sync_primitives::AutoLock lock(pending_requests_lock_);
TimeSortedRequestInfoSet::iterator it = time_sorted_pending_requests_.begin();
if (it != time_sorted_pending_requests_.end()) {
result = *it;
@@ -175,7 +175,7 @@ RequestInfoPtr RequestInfoSet::Front() {
RequestInfoPtr RequestInfoSet::FrontWithNotNullTimeout() {
LOG4CXX_AUTO_TRACE(logger_);
- sync_primitives::AutoLock lock(this_lock_);
+ sync_primitives::AutoLock lock(pending_requests_lock_);
RequestInfoPtr result;
TimeSortedRequestInfoSet::iterator it = time_sorted_pending_requests_.begin();
while (it != time_sorted_pending_requests_.end()) {
@@ -219,7 +219,7 @@ bool RequestInfoSet::Erase(const RequestInfoPtr request_info) {
}
bool RequestInfoSet::RemoveRequest(const RequestInfoPtr request_info) {
- sync_primitives::AutoLock lock(this_lock_);
+ sync_primitives::AutoLock lock(pending_requests_lock_);
return Erase(request_info);
}
@@ -228,7 +228,7 @@ uint32_t RequestInfoSet::RemoveRequests(
LOG4CXX_AUTO_TRACE(logger_);
uint32_t erased = 0;
- sync_primitives::AutoLock lock(this_lock_);
+ sync_primitives::AutoLock lock(pending_requests_lock_);
HashSortedRequestInfoSet::iterator it =
std::find_if(hash_sorted_pending_requests_.begin(),
hash_sorted_pending_requests_.end(),
@@ -256,6 +256,7 @@ uint32_t RequestInfoSet::RemoveMobileRequests() {
}
const size_t RequestInfoSet::Size() {
+ sync_primitives::AutoLock lock(pending_requests_lock_);
CheckSetSizes();
return time_sorted_pending_requests_.size();
}