std::string DBHandleProvider::cert_filedb_path_;
std::unordered_set<pid_t> DBHandleProvider::writer_pid_list_;
std::recursive_mutex DBHandleProvider::lock_;
-std::mutex DBHandleProvider::pid_list_lock_;
+std::shared_mutex DBHandleProvider::pid_list_lock_;
DBHandleProvider::DBHandleProvider(uid_t uid)
: uid_(uid),
}
DBHandleProvider& DBHandleProvider::GetInst(uid_t uid) {
- static std::mutex singleton_lock_;
- std::unique_lock<std::mutex> u(singleton_lock_);
+ static std::shared_mutex singleton_lock_;
+ std::shared_lock<std::shared_mutex> s(singleton_lock_);
uid = ConvertUID(uid);
+ auto it = provider_map_.find(uid);
+ if (it != provider_map_.end())
+ return *(it->second);
+
+ s.unlock();
+ std::unique_lock<std::shared_mutex> u(singleton_lock_);
auto& prov = provider_map_[uid];
if (prov == nullptr)
prov.reset(new DBHandleProvider(uid));
}
bool DBHandleProvider::IsCrashedWriteRequest() {
- std::unique_lock<std::mutex> u(pid_list_lock_);
+ std::unique_lock<std::shared_mutex> u(pid_list_lock_);
if (writer_pid_list_.empty())
return false;
}
bool DBHandleProvider::IsMemoryDBActive(pid_t pid, bool write) {
- std::unique_lock<std::mutex> u(pid_list_lock_);
+ std::unique_lock<std::shared_mutex> u(pid_list_lock_);
if (!is_user_memdb_set_)
return false;
}
bool DBHandleProvider::IsWriter(pid_t pid) {
- std::unique_lock<std::mutex> u(pid_list_lock_);
+ std::unique_lock<std::shared_mutex> s(pid_list_lock_);
return writer_pid_list_.find(pid) != writer_pid_list_.end();
}
}
std::vector<std::shared_ptr<package_x>> DBHandleProvider::GetPackages(
- pid_t pid, bool write, pkgmgrinfo_filter_x* filter,
+ pid_t pid, pkgmgrinfo_filter_x* filter,
const std::string& package) {
std::vector<std::shared_ptr<package_x>> ret;
auto map_it = pkg_map_.find(package);
}
std::vector<std::shared_ptr<application_x>> DBHandleProvider::GetApplications(
- pid_t pid, bool write, pkgmgrinfo_filter_x* filter,
+ pid_t pid, pkgmgrinfo_filter_x* filter,
const std::string& app) {
/* make metadata filter map */
std::unordered_map<std::string, std::string> metadata_map;
}
void DBHandleProvider::InsertPID(pid_t pid) {
- std::unique_lock<std::mutex> u(pid_list_lock_);
+ std::unique_lock<std::shared_mutex> u(pid_list_lock_);
writer_pid_list_.insert(pid);
}
bool DBHandleProvider::ErasePID(pid_t pid) {
- std::unique_lock<std::mutex> u(pid_list_lock_);
+ std::unique_lock<std::shared_mutex> u(pid_list_lock_);
return writer_pid_list_.erase(pid) == 1;
}