14d6c458bSopenharmony_ci/* 24d6c458bSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 34d6c458bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44d6c458bSopenharmony_ci * you may not use this file except in compliance with the License. 54d6c458bSopenharmony_ci * You may obtain a copy of the License at 64d6c458bSopenharmony_ci * 74d6c458bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84d6c458bSopenharmony_ci * 94d6c458bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104d6c458bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114d6c458bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124d6c458bSopenharmony_ci * See the License for the specific language governing permissions and 134d6c458bSopenharmony_ci * limitations under the License. 144d6c458bSopenharmony_ci */ 154d6c458bSopenharmony_ci 164d6c458bSopenharmony_ci#include "qos_helper.h" 174d6c458bSopenharmony_ci 184d6c458bSopenharmony_ci#include <map> 194d6c458bSopenharmony_ci 204d6c458bSopenharmony_ci#ifdef ENABLE_QOS 214d6c458bSopenharmony_ci#include "qos.h" 224d6c458bSopenharmony_ci#endif 234d6c458bSopenharmony_ci#include "tools/log.h" 244d6c458bSopenharmony_ci 254d6c458bSopenharmony_cinamespace Commonlibrary::Platform { 264d6c458bSopenharmony_ci 274d6c458bSopenharmony_ciusing OHOS::QOS::QosLevel; 284d6c458bSopenharmony_ci 294d6c458bSopenharmony_ci#ifdef ENABLE_QOS 304d6c458bSopenharmony_cistatic const std::map<Priority, QosLevel> WORKERPRIORITY_QOSLEVEL_MAP = { 314d6c458bSopenharmony_ci {Priority::IDLE, OHOS::QOS::QosLevel::QOS_BACKGROUND}, 324d6c458bSopenharmony_ci {Priority::LOW, OHOS::QOS::QosLevel::QOS_UTILITY}, 334d6c458bSopenharmony_ci {Priority::DEFAULT, OHOS::QOS::QosLevel::QOS_DEFAULT}, 344d6c458bSopenharmony_ci {Priority::HIGH, OHOS::QOS::QosLevel::QOS_USER_INITIATED} 354d6c458bSopenharmony_ci}; 364d6c458bSopenharmony_ci 374d6c458bSopenharmony_ciint SetWorkerPriority([[maybe_unused]] Priority priority) 384d6c458bSopenharmony_ci{ 394d6c458bSopenharmony_ci return SetThreadQos(WORKERPRIORITY_QOSLEVEL_MAP.at(priority)); 404d6c458bSopenharmony_ci} 414d6c458bSopenharmony_ci#else 424d6c458bSopenharmony_ciint SetWorkerPriority(Priority priority) 434d6c458bSopenharmony_ci{ 444d6c458bSopenharmony_ci HILOG_DEBUG("SetWorkerPriority:: not supported currently."); 454d6c458bSopenharmony_ci return 0; 464d6c458bSopenharmony_ci} 474d6c458bSopenharmony_ci#endif 484d6c458bSopenharmony_ci} // namespace Commonlibrary::Platform 49