Remove unnecessary mutex 86/255386/3
authorChanggyu Choi <changyu.choi@samsung.com>
Thu, 18 Mar 2021 02:10:05 +0000 (11:10 +0900)
committerChanggyu Choi <changyu.choi@samsung.com>
Thu, 18 Mar 2021 02:14:05 +0000 (11:14 +0900)
Local lock is unnecessary because every critical section is global.

Change-Id: Ib33ae7a6bd7709e72fb23eb4884014b53b9a165c
igned-off-by: Changgyu Choi <changyu.choi@samsung.com>

src/common/database/db_handle_provider.cc
src/common/database/db_handle_provider.hh

index d7988cf..4ceb9d5 100644 (file)
@@ -66,7 +66,7 @@ std::string DBHandleProvider::cert_memory_db_path_ =
     "file:certdb?mode=memory&cache=shared";
 std::string DBHandleProvider::cert_file_db_path_;
 std::unordered_set<pid_t> DBHandleProvider::pid_list_;
-std::recursive_mutex DBHandleProvider::global_lock_;
+std::recursive_mutex DBHandleProvider::lock_;
 
 DBHandleProvider::DBHandleProvider(uid_t uid) : uid_(uid),
     is_memory_(false), parser_memory_db_handle_(nullptr, sqlite3_close_v2) {
@@ -103,7 +103,6 @@ DBHandleProvider& DBHandleProvider::GetInst(uid_t uid) {
 std::vector<std::pair<std::string, uid_t>> DBHandleProvider::GetParserDBPath(
     pid_t pid, bool write) {
   std::unique_lock<std::recursive_mutex> u(lock_);
-  std::unique_lock<std::recursive_mutex> gu(global_lock_);
   std::vector<std::pair<std::string, uid_t>> db_path_list;
   if (is_memory_ != is_memory_global_)
     SetMemoryMode(pid, is_memory_global_);
@@ -132,7 +131,6 @@ std::vector<std::pair<std::string, uid_t>> DBHandleProvider::GetParserDBPath(
 
 std::string DBHandleProvider::GetCertDBPath(pid_t pid, bool write) {
   std::unique_lock<std::recursive_mutex> u(lock_);
-  std::unique_lock<std::recursive_mutex> gu(global_lock_);
   if (is_memory_ != is_memory_global_)
     SetMemoryMode(pid, is_memory_global_);
 
@@ -178,7 +176,6 @@ sqlite3* DBHandleProvider::GetMemoryDBHandle(const std::string& filedb_path,
 
 void DBHandleProvider::SetMemoryMode(pid_t pid, bool flag) {
   std::unique_lock<std::recursive_mutex> u(lock_);
-  std::unique_lock<std::recursive_mutex> gu(global_lock_);
   if (flag == is_memory_global_ && flag == is_memory_)
     return;
 
index adc007d..a42bd04 100644 (file)
@@ -61,14 +61,13 @@ class EXPORT_API DBHandleProvider {
   static std::string cert_memory_db_path_;
   static std::string cert_file_db_path_;
   static std::unordered_set<pid_t> pid_list_;
-  static std::recursive_mutex global_lock_;
+  static std::recursive_mutex lock_;
 
   uid_t uid_;
   bool is_memory_;
   std::unique_ptr<sqlite3, decltype(sqlite3_close_v2)*> parser_memory_db_handle_;
   std::string parser_memory_db_path_;
   std::string parser_file_db_path_;
-  std::recursive_mutex lock_;
 };
 
 }  // namespace pkgmgr_common