Fix thread synchronization when clear cache 36/266836/2
authorIlho Kim <ilho159.kim@samsung.com>
Fri, 19 Nov 2021 08:15:18 +0000 (17:15 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Fri, 19 Nov 2021 08:24:24 +0000 (17:24 +0900)
RemoveCache operation need to get lock before operation
for syncronization with other read threads

Change-Id: I3cd78d81e6d4612a6f19531d8c7bda5e8cf883f5
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/server/database/remove_cache_db_handler.cc [new file with mode: 0644]
src/server/database/remove_cache_db_handler.hh [new file with mode: 0644]
src/server/request_handler/command_request_handler.cc

diff --git a/src/server/database/remove_cache_db_handler.cc b/src/server/database/remove_cache_db_handler.cc
new file mode 100644 (file)
index 0000000..d16a085
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "remove_cache_db_handler.hh"
+
+#include "db_handle_provider.hh"
+
+namespace pkgmgr_server {
+namespace database {
+
+RemoveCacheDBHandler::RemoveCacheDBHandler(uid_t uid, int pid)
+    : AbstractDBHandler(uid, pid) {}
+
+int RemoveCacheDBHandler::Execute() {
+  std::unique_lock<std::shared_timed_mutex> u(lock_);
+
+  database::DBHandleProvider::GetInst(GetUID()).UnsetMemoryMode(GetPID());
+
+  return PMINFO_R_OK;
+}
+
+}  // namespace database
+}  // namespace pkgmgr_server
diff --git a/src/server/database/remove_cache_db_handler.hh b/src/server/database/remove_cache_db_handler.hh
new file mode 100644 (file)
index 0000000..65f56cf
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef REMOVE_CACHE_DB_HANDLER_HH_
+#define REMOVE_CACHE_DB_HANDLER_HH_
+
+#include <sys/types.h>
+
+#include "abstract_db_handler.hh"
+
+namespace pkgmgr_server {
+namespace database {
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+class EXPORT_API RemoveCacheDBHandler : public AbstractDBHandler {
+ public:
+  RemoveCacheDBHandler(uid_t uid, int pid);
+  int Execute() override;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // REMOVE_CACHE_DB_HANDLER_HH_
+
index e928b93..0fe00ab 100644 (file)
@@ -9,6 +9,7 @@
 #include "db_handle_provider.hh"
 #include "parcelable_factory.hh"
 #include "pkginfo_parcelable.hh"
+#include "remove_cache_db_handler.hh"
 #include "utils/logging.hh"
 
 #include "pkgmgrinfo_debug.h"
@@ -41,10 +42,10 @@ bool CommandRequestHandler::HandleRequest(unsigned char* data, int size,
   }
 
   if (parcel->GetCmd() == CommandType::RemoveCache) {
-    database::DBHandleProvider::GetInst(
-        parcel->GetUid()).UnsetMemoryMode(GetPID());
+    database::RemoveCacheDBHandler db(parcel->GetUid(), GetPID());
+    int ret = db.Execute();
     result_ = std::make_shared<pcp::ResultParcelable>(
-        PMINFO_R_OK, std::vector<pcp::StrArgs>{});
+        ret, std::vector<pcp::StrArgs>{});
     return true;
   }