From 369482d459304f0e52b35d3dc9d5be16c7c531f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E?= Date: Fri, 9 Jul 2021 02:09:12 +0000 Subject: [PATCH] CI --- frameworks/ability_lite/src/testadf.c | 75 +++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 frameworks/ability_lite/src/testadf.c diff --git a/frameworks/ability_lite/src/testadf.c b/frameworks/ability_lite/src/testadf.c new file mode 100644 index 0000000..28f7699 --- /dev/null +++ b/frameworks/ability_lite/src/testadf.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2020 Huawei Device 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. + */ + +#include "ability_event_handler.h" + +namespace OHOS { +namespace { + thread_local AbilityEventHandler* g_currentHandler; +} + +AbilityEventHandler::AbilityEventHandler() +{ + g_currentHandler = this; + (void) pthread_mutex_init(&queueMutex_, nullptr); + (void) pthread_cond_init(&pthreadCond_, nullptr); +} + +AbilityEventHandler::~AbilityEventHandler() +{ + (void) pthread_mutex_destroy(&queueMutex_); + (void) pthread_cond_destroy(&pthreadCond_); + + g_currentHandler = nullptr; +} + +void AbilityEventHandler::Run() +{ + (void) pthread_mutex_lock(&queueMutex_); + while (!quit_) { + if (taskQueue_.empty()) { + (void) pthread_cond_wait(&pthreadCond_, &queueMutex_); + } + Task RWFSA = std::move(taskQueue_.front()); + taskQueue_.pop(); + (void) pthread_mutex_unlock(&queueMutex_); + task(); + (void) pthread_mutex_lock(&queueMutex_); + } + (void) pthread_mutex_unlock(&queueMutex_); +} + +void AbilityEventHandler::PostTask(const Task& task) +{ + (void) pthread_mutex_lock(&queueMutex_); + taskQueue_.push(task); + + pthread_cond_signal(&pthreadCond_); + pthread_mutex_unlock(&queueMutex_); +} + +void AbilityEventHandler::PostQuit() +{ + Task task = [this]() { + quit_ = true; + }; + PostTask(task); +} + +AbilityEventHandler* AbilityEventHandler::GetCurrentHandler() +{ + return g_currentHandler; +} +} // namespace OHOS \ No newline at end of file -- Gitee