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)
#include <thread>
#include <utility>
+#include <shared-queue.hpp>
+
#include "log-private.hh"
#include "port-internal.hh"
-#include "shared-queue-internal.hh"
namespace rpc_port {
namespace internal {
std::list<std::shared_ptr<Session>> sessions_;
std::thread thread_;
std::atomic<bool> is_running_ { false };
- SharedQueue<std::shared_ptr<tizen_base::Parcel>> queue_;
+ tizen_base::SharedQueue<std::shared_ptr<tizen_base::Parcel>> queue_;
mutable std::recursive_mutex mutex_;
aul_app_com_connection_h conn_ = nullptr;
};
thread_ = std::thread([&]() {
_W("START");
do {
- std::shared_ptr<tizen_base::Parcel> parcel;
- queue_.WaitAndPop(parcel);
+ std::shared_ptr<tizen_base::Parcel> parcel = queue_.WaitAndPop();
int len = parcel->GetDataSize();
if (len == 0) {
_W("Done");
+++ /dev/null
-/*
- * 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 <condition_variable>
-#include <mutex>
-#include <queue>
-#include <thread>
-
-namespace rpc_port {
-namespace internal {
-
-template <class T>
-class SharedQueue {
- public:
- SharedQueue() = default;
- virtual ~SharedQueue() = default;
-
- void Push(T item) {
- std::lock_guard<std::mutex> lock(mutex_);
- queue_.push(item);
- cond_var_.notify_one();
- }
-
- bool TryAndPop(T& item) {
- std::lock_guard<std::mutex> lock(mutex_);
- if (queue_.empty())
- return false;
-
- item = queue_.front();
- queue_.pop_front();
-
- return true;
- }
-
- void WaitAndPop(T& item) {
- std::unique_lock<std::mutex> lock(mutex_);
- while (queue_.empty())
- cond_var_.wait(lock);
-
- item = queue_.front();
- queue_.pop();
- }
-
- bool Empty() {
- std::lock_guard<std::mutex> lock(mutex_);
- return queue_.empty();
- }
-
- int Size() {
- std::lock_guard<std::mutex> lock(mutex_);
- return queue_.size();
- }
-
- private:
- std::queue<T> queue_;
- mutable std::mutex mutex_;
- std::condition_variable cond_var_;
-};
-
-} // namespace internal
-} // namespace rpc_port
-
-#endif // SHARED_QUEUE_INTERNAL_HH_