• 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 /**
17  * @addtogroup Ffrt
18  * @{
19  *
20  * @brief ffrt provides APIs.
21  *
22  *
23  * @syscap SystemCapability.Resourceschedule.Ffrt.Core
24  *
25  * @since 10
26  */
27 
28  /**
29  * @file task.h
30  *
31  * @brief Declares the task interfaces in C.
32  *
33  * @syscap SystemCapability.Resourceschedule.Ffrt.Core
34  * @since 10
35  * @version 1.0
36  */
37 #ifndef FFRT_API_C_TASK_H
38 #define FFRT_API_C_TASK_H
39 #include "type_def.h"
40 
41 /**
42  * @brief Initializes a task attribute.
43  *
44  * @param attr Indicates a pointer to the task attribute.
45  * @return Returns <b>0</b> if the task attribute is initialized;
46            returns <b>-1</b> otherwise.
47  * @since 10
48  * @version 1.0
49  */
50 FFRT_C_API int ffrt_task_attr_init(ffrt_task_attr_t* attr);
51 
52 /**
53  * @brief Sets a task name.
54  *
55  * @param attr Indicates a pointer to the task attribute.
56  * @param name Indicates a pointer to the task name.
57  * @since 10
58  * @version 1.0
59  */
60 FFRT_C_API void ffrt_task_attr_set_name(ffrt_task_attr_t* attr, const char* name);
61 
62 /**
63  * @brief Obtains a task name.
64  *
65  * @param attr Indicates a pointer to the task attribute.
66  * @return Returns a non-null pointer to the task name if the name is obtained;
67            returns a null pointer otherwise.
68  * @since 10
69  * @version 1.0
70  */
71 FFRT_C_API const char* ffrt_task_attr_get_name(const ffrt_task_attr_t* attr);
72 
73 /**
74  * @brief Destroys a task attribute.
75  *
76  * @param attr Indicates a pointer to the task attribute.
77  * @since 10
78  * @version 1.0
79  */
80 FFRT_C_API void ffrt_task_attr_destroy(ffrt_task_attr_t* attr);
81 
82 /**
83  * @brief Sets the QoS for a task attribute.
84  *
85  * @param attr Indicates a pointer to the task attribute.
86  * @param qos Indicates the QoS.
87  * @since 10
88  * @version 1.0
89  */
90 FFRT_C_API void ffrt_task_attr_set_qos(ffrt_task_attr_t* attr, ffrt_qos_t qos);
91 
92 /**
93  * @brief Obtains the QoS of a task attribute.
94  *
95  * @param attr Indicates a pointer to the task attribute.
96  * @return Returns the QoS, which is <b>ffrt_qos_default</b> by default.
97  * @since 10
98  * @version 1.0
99  */
100 FFRT_C_API ffrt_qos_t ffrt_task_attr_get_qos(const ffrt_task_attr_t* attr);
101 
102 /**
103  * @brief Sets the task delay time.
104  *
105  * @param attr Indicates a pointer to the task attribute.
106  * @param delay_us Indicates the delay time, in microseconds.
107  * @since 10
108  * @version 1.0
109  */
110 FFRT_C_API void ffrt_task_attr_set_delay(ffrt_task_attr_t* attr, uint64_t delay_us);
111 
112 /**
113  * @brief Obtains the task delay time.
114  *
115  * @param attr Indicates a pointer to the task attribute.
116  * @return Returns the delay time.
117  * @since 10
118  * @version 1.0
119  */
120 FFRT_C_API uint64_t ffrt_task_attr_get_delay(const ffrt_task_attr_t* attr);
121 
122 /**
123  * @brief Updates the QoS of this task.
124  *
125  * @param qos Indicates the new QoS.
126  * @return Returns <b>0</b> if the QoS is updated;
127            returns <b>-1</b> otherwise.
128  * @since 10
129  * @version 1.0
130  */
131 FFRT_C_API int ffrt_this_task_update_qos(ffrt_qos_t qos);
132 
133 /**
134  * @brief Obtains the ID of this task.
135  *
136  * @return Returns the task ID.
137  * @since 10
138  * @version 1.0
139  */
140 FFRT_C_API uint64_t ffrt_this_task_get_id(void);
141 
142 /**
143  * @brief Applies for memory for the function execution structure.
144  *
145  * @param kind Indicates the type of the function execution structure, which can be common or queue.
146  * @return Returns a non-null pointer if the memory is allocated;
147            returns a null pointer otherwise.
148  * @since 10
149  * @version 1.0
150  */
151 FFRT_C_API void *ffrt_alloc_auto_managed_function_storage_base(ffrt_function_kind_t kind);
152 
153 /**
154  * @brief Submits a task.
155  *
156  * @param f Indicates a pointer to the task executor.
157  * @param in_deps Indicates a pointer to the input dependencies.
158  * @param out_deps Indicates a pointer to the output dependencies.
159  * @param attr Indicates a pointer to the task attribute.
160  * @since 10
161  * @version 1.0
162  */
163 FFRT_C_API void ffrt_submit_base(ffrt_function_header_t* f, const ffrt_deps_t* in_deps, const ffrt_deps_t* out_deps,
164     const ffrt_task_attr_t* attr);
165 
166 /**
167  * @brief Submits a task, and obtains a task handle.
168  *
169  * @param f Indicates a pointer to the task executor.
170  * @param in_deps Indicates a pointer to the input dependencies.
171  * @param out_deps Indicates a pointer to the output dependencies.
172  * @param attr Indicates a pointer to the task attribute.
173  * @return Returns a non-null task handle if the task is submitted;
174            returns a null pointer otherwise.
175  * @since 10
176  * @version 1.0
177  */
178 FFRT_C_API ffrt_task_handle_t ffrt_submit_h_base(ffrt_function_header_t* f, const ffrt_deps_t* in_deps,
179     const ffrt_deps_t* out_deps, const ffrt_task_attr_t* attr);
180 
181 /**
182  * @brief Destroys a task handle.
183  *
184  * @param handle Indicates a task handle.
185  * @since 10
186  * @version 1.0
187  */
188 FFRT_C_API void ffrt_task_handle_destroy(ffrt_task_handle_t handle);
189 
190 /**
191  * @brief Waits until the dependent tasks are complete.
192  *
193  * @param deps Indicates a pointer to the dependent tasks.
194  * @since 10
195  * @version 1.0
196  */
197 FFRT_C_API void ffrt_wait_deps(const ffrt_deps_t* deps);
198 
199 /**
200  * @brief Waits until all submitted tasks are complete.
201  *
202  * @since 10
203  * @version 1.0
204  */
205 FFRT_C_API void ffrt_wait(void);
206 #endif
207