1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "common/rs_switching_thread.h" 17 #include "platform/common/rs_log.h" 18 19 #ifdef RES_BASE_SCHED_ENABLE 20 #include "qos.h" 21 #endif 22 23 namespace OHOS::Rosen { Instance()24RSSwitchingThread& RSSwitchingThread::Instance() 25 { 26 static RSSwitchingThread instance; 27 return instance; 28 } 29 RSSwitchingThread()30RSSwitchingThread::RSSwitchingThread() 31 { 32 runner_ = AppExecFwk::EventRunner::Create("RSSwitchingThread"); 33 handler_ = std::make_shared<AppExecFwk::EventHandler>(runner_); 34 #ifdef RES_BASE_SCHED_ENABLE 35 PostTask([this]() { 36 auto ret = OHOS::QOS::SetThreadQos(OHOS::QOS::QosLevel::QOS_USER_INTERACTIVE); 37 RS_LOGI("RSSwitchingThread: SetThreadQos retcode = %{public}d", ret); 38 }); 39 #endif 40 } 41 PostTask(const std::function<void ()> & task)42void RSSwitchingThread::PostTask(const std::function<void()>& task) 43 { 44 if (handler_) { 45 handler_->PostTask(task, AppExecFwk::EventQueue::Priority::IMMEDIATE); 46 } 47 } 48 PostSyncTask(const std::function<void ()> & task)49void RSSwitchingThread::PostSyncTask(const std::function<void()>& task) 50 { 51 if (handler_) { 52 handler_->PostSyncTask(task, AppExecFwk::EventQueue::Priority::IMMEDIATE); 53 } 54 } 55 } // namespace OHOS::Rosen 56