Add shared_mutex in DBHandler.
When it received get request, then use shared_lock.
So multiple thread is accessible.
On the other hand, when be received set request,
it use unique_lock.
Change-Id: Ifbf02d50713479d26372adaa4ad4772a030be2ef
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
namespace pkgmgr_common {
namespace database {
+std::shared_timed_mutex AbstractDBHandler::lock_;
+
AbstractDBHandler::AbstractDBHandler(uid_t uid, int pid) {
uid_ = uid;
pid_ = pid;
#ifndef ABSTRACT_DB_HANDLER_HH_
#define ABSTRACT_DB_HANDLER_HH_
+#include <shared_mutex>
#include <string>
#include <vector>
int GetPID();
std::vector<std::pair<sqlite3*, uid_t>> GetConnection();
std::string GetLocale();
-
+ static std::shared_timed_mutex lock_;
private:
std::vector<std::pair<std::string, uid_t>> GetDBPath();
DBType db_type_ = DB_TYPE_NONE;
#include "appinfo_db_handler.hh"
#include <vector>
+#include <shared_mutex>
#include "pkgmgrinfo_basic.h"
#include "pkgmgrinfo_internal.h"
}
int AppInfoDBHandler::Execute() {
+ std::shared_lock<std::shared_timed_mutex> s(lock_);
SetOpType(OPERATION_TYPE_READ);
SetDBType(DB_TYPE_FILE_PKGDB);
if (!Connect())
#include "cert_get_db_handler.hh"
+#include <shared_mutex>
#include <vector>
#include "pkgmgrinfo_debug.h"
}
int CertGetDBHandler::Execute() {
+ std::shared_lock<std::shared_timed_mutex> s(lock_);
SetOpType(OPERATION_TYPE_READ);
SetDBType(DB_TYPE_FILE_CERTDB);
if (!Connect()) {
}
int CertSetDBHandler::Execute() {
+ std::unique_lock<std::shared_timed_mutex> u(lock_);
SetOpType(OPERATION_TYPE_WRITE);
SetDBType(DB_TYPE_FILE_CERTDB);
if (!Connect())
static bool IsCrashedWriteRequest();
std::vector<std::pair<std::string, uid_t>> GetParserDBPath(int pid, bool write);
std::string GetCertDBPath(int pid, bool write);
- void SetMemoryMode(int pid, bool flag);
+ void SetMemoryMode(pid_t pid, bool flag);
private:
DBHandleProvider(uid_t uid);
#include "depinfo_db_handler.hh"
+#include <shared_mutex>
#include <vector>
#include "pkgmgrinfo_debug.h"
}
int DepInfoGetDBHandler::Execute() {
+ std::shared_lock<std::shared_timed_mutex> s(lock_);
SetOpType(OPERATION_TYPE_READ);
SetDBType(DB_TYPE_FILE_PKGDB);
#include "pkg_get_db_handler.hh"
+#include <shared_mutex>
#include <vector>
#include "pkgmgrinfo_debug.h"
}
int PkgGetDBHandler::Execute() {
+ std::shared_lock<std::shared_timed_mutex> s(lock_);
SetOpType(OPERATION_TYPE_READ);
SetDBType(DB_TYPE_FILE_PKGDB);
if (!Connect()) {
}
int PkgSetDBHandler::Execute() {
+ std::unique_lock<std::shared_timed_mutex> u(lock_);
SetOpType(OPERATION_TYPE_WRITE);
SetDBType(DB_TYPE_FILE_PKGDB);
#include "query_handler.hh"
+#include <shared_mutex>
#include <vector>
#include "pkgmgrinfo_debug.h"
}
int QueryHandler::Execute() {
+ std::shared_lock<std::shared_timed_mutex> s(lock_);
if (!Connect()) {
_LOGE("Failed to connect database");
return PMINFO_R_ERROR;