From 3698d559b4322fea0153e049552c163c3b594909 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 11 Jan 2023 10:55:05 +0000 Subject: [PATCH] Use tizen_base::SharedQueue To remove duplicated codes about shared queue, we add a tizen-shared-queue library. This patch uses the tizen_base::SharedQueue and removes duplicated shared queue codes. Change-Id: I43e1aa4ecce2c97524046145b0db02e3cb3e1d0d Signed-off-by: Hwankyu Jhun --- CMakeLists.txt | 1 + packaging/rpc-port.spec | 1 + src/CMakeLists.txt | 1 + src/debug-port-internal.cc | 8 ++--- src/shared-queue-internal.hh | 79 -------------------------------------------- 5 files changed, 7 insertions(+), 83 deletions(-) delete mode 100644 src/shared-queue-internal.hh diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a5a157..33f92a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,7 @@ PKG_CHECK_MODULES(GMOCK_DEPS REQUIRED gmock) PKG_CHECK_MODULES(LIBTZPLATFORM_CONFIG_DEPS REQUIRED libtzplatform-config) PKG_CHECK_MODULES(PARCEL_DEPS REQUIRED parcel) PKG_CHECK_MODULES(PKGMGR_INFO_DEPS REQUIRED pkgmgr-info) +PKG_CHECK_MODULES(TIZEN_SHARED_QUEUE_DEPS REQUIRED tizen-shared-queue) PKG_CHECK_MODULES(UUID_DEPS REQUIRED uuid) ADD_SUBDIRECTORY(src) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index d5b8dbc..ae8b751 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -18,6 +18,7 @@ BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(parcel) BuildRequires: pkgconfig(pkgmgr) BuildRequires: pkgconfig(pkgmgr-info) +BuildRequires: pkgconfig(tizen-shared-queue) BuildRequires: pkgconfig(uuid) %if 0%{?gcov:1} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1061211..46b286d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,6 +21,7 @@ APPLY_PKG_CONFIG(${TARGET_RPC_PORT} PUBLIC LIBTZPLATFORM_CONFIG_DEPS PARCEL_DEPS PKGMGR_INFO_DEPS + TIZEN_SHARED_QUEUE_DEPS UUID_DEPS ) diff --git a/src/debug-port-internal.cc b/src/debug-port-internal.cc index 06e44dc..df51d5b 100644 --- a/src/debug-port-internal.cc +++ b/src/debug-port-internal.cc @@ -33,9 +33,10 @@ #include #include +#include + #include "log-private.hh" #include "port-internal.hh" -#include "shared-queue-internal.hh" namespace rpc_port { namespace internal { @@ -119,7 +120,7 @@ class DebugPortImpl { std::list> sessions_; std::thread thread_; std::atomic is_running_ { false }; - SharedQueue> queue_; + tizen_base::SharedQueue> queue_; mutable std::recursive_mutex mutex_; aul_app_com_connection_h conn_ = nullptr; }; @@ -325,8 +326,7 @@ void DebugPortImpl::CreateThread() { thread_ = std::thread([&]() { _W("START"); do { - std::shared_ptr parcel; - queue_.WaitAndPop(parcel); + std::shared_ptr parcel = queue_.WaitAndPop(); int len = parcel->GetDataSize(); if (len == 0) { _W("Done"); diff --git a/src/shared-queue-internal.hh b/src/shared-queue-internal.hh deleted file mode 100644 index 4cd0d95..0000000 --- a/src/shared-queue-internal.hh +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2020 - 2021 Samsung Electronics Co., Ltd. - * - * 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 SHARED_QUEUE_INTERNAL_HH_ -#define SHARED_QUEUE_INTERNAL_HH_ - -#include -#include -#include -#include - -namespace rpc_port { -namespace internal { - -template -class SharedQueue { - public: - SharedQueue() = default; - virtual ~SharedQueue() = default; - - void Push(T item) { - std::lock_guard lock(mutex_); - queue_.push(item); - cond_var_.notify_one(); - } - - bool TryAndPop(T& item) { - std::lock_guard lock(mutex_); - if (queue_.empty()) - return false; - - item = queue_.front(); - queue_.pop_front(); - - return true; - } - - void WaitAndPop(T& item) { - std::unique_lock lock(mutex_); - while (queue_.empty()) - cond_var_.wait(lock); - - item = queue_.front(); - queue_.pop(); - } - - bool Empty() { - std::lock_guard lock(mutex_); - return queue_.empty(); - } - - int Size() { - std::lock_guard lock(mutex_); - return queue_.size(); - } - - private: - std::queue queue_; - mutable std::mutex mutex_; - std::condition_variable cond_var_; -}; - -} // namespace internal -} // namespace rpc_port - -#endif // SHARED_QUEUE_INTERNAL_HH_ -- 2.7.4