1 /*
2  * Copyright (c) 2023 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 #ifndef OHOS_STANDARD_SYSTEM
16 #include "cpu_boost_adapter.h"
17 #else
18 #include "cpu_boost_ohos.h"
19 #endif
20 #include "cpp/task.h"
21 #include "dfx/log/ffrt_log_api.h"
22 #include "internal_inc/osal.h"
23 #include "sched/execute_ctx.h"
24 #include "tm/cpu_task.h"
25 #include "c/ffrt_cpu_boost.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 API_ATTRIBUTE((visibility("default")))
ffrt_cpu_boost_start(int ctx_id)32 int ffrt_cpu_boost_start(int ctx_id)
33 {
34     int ret = ffrt::CpuBoostStart(ctx_id);
35     if (ret == 0) {
36         ffrt::CPUEUTask* curTask = ffrt::ExecuteCtx::Cur()->task;
37         if (curTask != nullptr && curTask->cpuBoostCtxId < 0) {
38             curTask->cpuBoostCtxId = ctx_id;
39         }
40     }
41     return ret;
42 }
43 
44 API_ATTRIBUTE((visibility("default")))
ffrt_cpu_boost_end(int ctx_id)45 int ffrt_cpu_boost_end(int ctx_id)
46 {
47     int ret = ffrt::CpuBoostEnd(ctx_id);
48     if (ret == 0) {
49         ffrt::CPUEUTask* curTask = ffrt::ExecuteCtx::Cur()->task;
50         if (curTask != nullptr && curTask->cpuBoostCtxId == ctx_id) {
51             curTask->cpuBoostCtxId = -1;
52         }
53     }
54     return ret;
55 }
56 #ifdef __cplusplus
57 }
58 #endif