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 FFRT_API_CPP_DEADLINE_H
16 #define FFRT_API_CPP_DEADLINE_H
17 #include <stdint.h>
18 #include "c/deadline.h"
19
20 namespace ffrt {
21 using interval = ffrt_interval_t;
22
23 /**
24 @brief app create an anonymous interval, the number is limited. should specify the deadline
25 */
26 static inline interval qos_interval_create(uint64_t deadline_us, qos qos_ = static_cast<int>(qos_deadline_request))
27 {
28 return ffrt_interval_create(deadline_us, qos_);
29 }
30
31 /**
32 @brief destroy a interval
33 */
qos_interval_destroy(interval it)34 static inline void qos_interval_destroy(interval it)
35 {
36 ffrt_interval_destroy(it);
37 }
38
39 /**
40 @brief start the interval
41 */
qos_interval_begin(interval it)42 static inline int qos_interval_begin(interval it)
43 {
44 return ffrt_interval_begin(it);
45 }
46
47 /**
48 @brief update interval
49 */
qos_interval_update(interval it,uint64_t new_deadline_us)50 static inline int qos_interval_update(interval it, uint64_t new_deadline_us)
51 {
52 return ffrt_interval_update(it, new_deadline_us);
53 }
54
55 /**
56 @brief interval become inactive until next begin
57 */
qos_interval_end(interval it)58 static inline int qos_interval_end(interval it)
59 {
60 return ffrt_interval_end(it);
61 }
62
63 /**
64 @brief current task or thread join an interval, only allow FIXED number of threads to join a interval
65 */
qos_interval_join(interval it)66 static inline int qos_interval_join(interval it)
67 {
68 return ffrt_interval_join(it);
69 }
70
71 /**
72 @brief current task or thread leave an interval
73 */
qos_interval_leave(interval it)74 static inline int qos_interval_leave(interval it)
75 {
76 return ffrt_interval_leave(it);
77 }
78 }; // namespace ffrt
79
80 #endif
81