• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #include "cpp/deadline.h"
17 #include "c/deadline.h"
18 #include "internal_inc/osal.h"
19 #include "sched/interval.h"
20 #include "core/dependence_manager.h"
21 #include "sched/frame_interval.h"
22 #include "dfx/log/ffrt_log_api.h"
23 
24 namespace ffrt {
25 class qos_interval_private_t {
26 public:
27     template <typename... Args>
qos_interval_private_t(uint64_t deadlineUs,const QoS & qos)28     qos_interval_private_t(uint64_t deadlineUs, const QoS& qos)
29     {
30         if (qos == qos_user_interactive) {
31             it = std::unique_ptr<Interval>(new (std::nothrow) FrameInterval(deadlineUs, qos));
32         } else {
33             it = std::unique_ptr<Interval>(new (std::nothrow) DefaultInterval(deadlineUs, qos));
34         }
35     }
36 
operator ->()37     Interval* operator->()
38     {
39         return it.get();
40     }
41 
42 private:
43     std::unique_ptr<Interval> it;
44 };
45 }; // namespace ffrt
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 API_ATTRIBUTE((visibility("default")))
ffrt_interval_create(uint64_t deadline_us,ffrt_qos_t qos)51 ffrt_interval_t ffrt_interval_create(uint64_t deadline_us, ffrt_qos_t qos)
52 {
53     if (qos < static_cast<int>(ffrt_qos_deadline_request) || qos > static_cast<int>(ffrt_qos_user_interactive)) {
54         FFRT_LOGE("Invalid QoS Interval!");
55         return nullptr;
56     }
57 
58     return new ffrt::qos_interval_private_t(deadline_us, qos);
59 }
60 
61 API_ATTRIBUTE((visibility("default")))
ffrt_interval_update(ffrt_interval_t it,uint64_t new_deadline_us)62 int ffrt_interval_update(ffrt_interval_t it, uint64_t new_deadline_us)
63 {
64     if (!it) {
65         FFRT_LOGE("QoS Interval Not Created Or Has Been Canceled!");
66         return ffrt_error;
67     }
68 
69     auto _it = static_cast<ffrt::qos_interval_private_t *>(it);
70 
71     (*_it)->Update(new_deadline_us);
72     return ffrt_success;
73 }
74 
75 API_ATTRIBUTE((visibility("default")))
ffrt_interval_begin(ffrt_interval_t it)76 int ffrt_interval_begin(ffrt_interval_t it)
77 {
78     if (!it) {
79         FFRT_LOGE("QoS Interval Not Created Or Has Been Canceled!");
80         return ffrt_error;
81     }
82 
83     auto _it = static_cast<ffrt::qos_interval_private_t *>(it);
84 
85     return (*_it)->Begin();
86 }
87 
88 API_ATTRIBUTE((visibility("default")))
ffrt_interval_end(ffrt_interval_t it)89 int ffrt_interval_end(ffrt_interval_t it)
90 {
91     if (!it) {
92         FFRT_LOGE("QoS Interval Not Created Or Has Been Canceled!");
93         return ffrt_error;
94     }
95 
96     auto _it = static_cast<ffrt::qos_interval_private_t *>(it);
97 
98     (*_it)->End();
99     return ffrt_success;
100 }
101 
102 API_ATTRIBUTE((visibility("default")))
ffrt_interval_destroy(ffrt_interval_t it)103 void ffrt_interval_destroy(ffrt_interval_t it)
104 {
105     if (!it) {
106         FFRT_LOGE("QoS Interval Not Created Or Has Been Canceled!");
107         return;
108     }
109 
110     delete static_cast<ffrt::qos_interval_private_t *>(it);
111 }
112 
113 API_ATTRIBUTE((visibility("default")))
ffrt_interval_join(ffrt_interval_t it)114 int ffrt_interval_join(ffrt_interval_t it)
115 {
116     if (!it) {
117         FFRT_LOGE("QoS Interval Not Created Or Has Been Canceled!");
118         return ffrt_error;
119     }
120 
121     auto _it = static_cast<ffrt::qos_interval_private_t *>(it);
122 
123     (*_it)->Join();
124     return ffrt_success;
125 }
126 
127 API_ATTRIBUTE((visibility("default")))
ffrt_interval_leave(ffrt_interval_t it)128 int ffrt_interval_leave(ffrt_interval_t it)
129 {
130     if (!it) {
131         FFRT_LOGE("QoS Interval Not Created Or Has Been Canceled!");
132         return ffrt_error;
133     }
134 
135     auto _it = static_cast<ffrt::qos_interval_private_t *>(it);
136 
137     (*_it)->Leave();
138     return ffrt_success;
139 }
140 #ifdef __cplusplus
141 }
142 #endif
143