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 * @file task.h
18 *
19 * @brief Declares the task interfaces in C++.
20 *
21 * @since 10
22 * @version 1.0
23 */
24 #ifndef FFRT_API_CPP_TASK_H
25 #define FFRT_API_CPP_TASK_H
26 #include <string>
27 #include <vector>
28 #include <functional>
29 #include "c/task.h"
30
31 namespace ffrt {
32 class task_attr : public ffrt_task_attr_t {
33 public:
34 #if __has_builtin(__builtin_FUNCTION)
35 task_attr(const char* func = __builtin_FUNCTION())
36 {
37 ffrt_task_attr_init(this);
38 ffrt_task_attr_set_name(this, func);
39 }
40 #else
41 task_attr()
42 {
43 ffrt_task_attr_init(this);
44 }
45 #endif
46
~task_attr()47 ~task_attr()
48 {
49 ffrt_task_attr_destroy(this);
50 }
51
52 task_attr(const task_attr&) = delete;
53 task_attr& operator=(const task_attr&) = delete;
54
55 /**
56 * @brief Sets a task name.
57 *
58 * @param name Indicates a pointer to the task name.
59 * @since 10
60 * @version 1.0
61 */
name(const char * name)62 inline task_attr& name(const char* name)
63 {
64 ffrt_task_attr_set_name(this, name);
65 return *this;
66 }
67
68 /**
69 * @brief Obtains the task name.
70 *
71 * @return Returns a pointer to the task name.
72 * @since 10
73 * @version 1.0
74 */
name()75 inline const char* name() const
76 {
77 return ffrt_task_attr_get_name(this);
78 }
79
80 /**
81 * @brief Sets the QoS for this task.
82 *
83 * @param qos Indicates the QoS.
84 * @since 10
85 * @version 1.0
86 */
qos(qos qos_)87 inline task_attr& qos(qos qos_)
88 {
89 ffrt_task_attr_set_qos(this, qos_);
90 return *this;
91 }
92
93 /**
94 * @brief Obtains the QoS of this task.
95 *
96 * @return Returns the QoS.
97 * @since 10
98 * @version 1.0
99 */
qos()100 inline int qos() const
101 {
102 return ffrt_task_attr_get_qos(this);
103 }
104
105 /**
106 * @brief Sets the delay time for this task.
107 *
108 * @param delay_us Indicates the delay time, in microseconds.
109 * @since 10
110 * @version 1.0
111 */
delay(uint64_t delay_us)112 inline task_attr& delay(uint64_t delay_us)
113 {
114 ffrt_task_attr_set_delay(this, delay_us);
115 return *this;
116 }
117
118 /**
119 * @brief Obtains the delay time of this task.
120 *
121 * @return Returns the delay time.
122 * @since 10
123 * @version 1.0
124 */
delay()125 inline uint64_t delay() const
126 {
127 return ffrt_task_attr_get_delay(this);
128 }
129
130 /**
131 * @brief Sets the priority for this task.
132 *
133 * @param priority Indicates the execute priority of concurrent queue task.
134 * @since 12
135 * @version 1.0
136 */
priority(ffrt_queue_priority_t prio)137 inline task_attr& priority(ffrt_queue_priority_t prio)
138 {
139 ffrt_task_attr_set_queue_priority(this, prio);
140 return *this;
141 }
142
143 /**
144 * @brief Obtains the priority of this task.
145 *
146 * @return Returns the priority of concurrent queue task.
147 * @since 12
148 * @version 1.0
149 */
priority()150 inline ffrt_queue_priority_t priority() const
151 {
152 return ffrt_task_attr_get_queue_priority(this);
153 }
154
155 /**
156 * @brief Sets the stack size for this task.
157 *
158 * @param size Indicates the task stack size, unit is byte.
159 * @since 12
160 * @version 1.0
161 */
stack_size(uint64_t size)162 inline task_attr& stack_size(uint64_t size)
163 {
164 ffrt_task_attr_set_stack_size(this, size);
165 return *this;
166 }
167
168 /**
169 * @brief Obtains the stack size of this task.
170 *
171 * @return Returns task stack size, unit is byte.
172 * @since 12
173 * @version 1.0
174 */
stack_size()175 inline uint64_t stack_size() const
176 {
177 return ffrt_task_attr_get_stack_size(this);
178 }
179
180 /**
181 * @brief Sets the task schedule timeout.
182 *
183 * @param timeout_us task scheduler timeout.
184 * @since 12
185 * @version 1.0
186 */
timeout(uint64_t timeout_us)187 inline task_attr& timeout(uint64_t timeout_us)
188 {
189 ffrt_task_attr_set_timeout(this, timeout_us);
190 return *this;
191 }
192
193 /**
194 * @brief Obtains the task schedule timeout.
195 *
196 * @return Returns task scheduler timeout.
197 * @since 12
198 * @version 1.0
199 */
timeout()200 inline uint64_t timeout() const
201 {
202 return ffrt_task_attr_get_timeout(this);
203 }
204 };
205
206 class task_handle {
207 public:
task_handle()208 task_handle() : p(nullptr)
209 {
210 }
task_handle(ffrt_task_handle_t p)211 task_handle(ffrt_task_handle_t p) : p(p)
212 {
213 }
214
~task_handle()215 ~task_handle()
216 {
217 if (p) {
218 ffrt_task_handle_destroy(p);
219 }
220 }
221
222 task_handle(task_handle const&) = delete;
223 task_handle& operator=(task_handle const&) = delete;
224
task_handle(task_handle && h)225 inline task_handle(task_handle&& h)
226 {
227 *this = std::move(h);
228 }
229
230 /**
231 * @brief get gid from task handle.
232 *
233 * @return Return gid.
234 * @since 10
235 * @version 1.0
236 */
get_id()237 inline uint64_t get_id() const
238 {
239 return ffrt_task_handle_get_id(p);
240 }
241
242 inline task_handle& operator=(task_handle&& h)
243 {
244 if (this != &h) {
245 if (p) {
246 ffrt_task_handle_destroy(p);
247 }
248 p = h.p;
249 h.p = nullptr;
250 }
251 return *this;
252 }
253
254 inline operator void* () const
255 {
256 return p;
257 }
258
259 private:
260 ffrt_task_handle_t p = nullptr;
261 };
262
263 struct dependence : ffrt_dependence_t {
dependencedependence264 dependence(const void* d)
265 {
266 type = ffrt_dependence_data;
267 ptr = d;
268 }
dependencedependence269 dependence(const task_handle& h)
270 {
271 type = ffrt_dependence_task;
272 ptr = h;
273 ffrt_task_handle_inc_ref(const_cast<ffrt_task_handle_t>(ptr));
274 }
275
dependencedependence276 dependence(const dependence& other)
277 {
278 (*this) = other;
279 }
280
dependencedependence281 dependence(dependence&& other)
282 {
283 (*this) = std::move(other);
284 }
285
286 dependence& operator=(const dependence& other)
287 {
288 if (this != &other) {
289 type = other.type;
290 ptr = other.ptr;
291 if (type == ffrt_dependence_task) {
292 ffrt_task_handle_inc_ref(const_cast<ffrt_task_handle_t>(ptr));
293 }
294 }
295 return *this;
296 }
297
298 dependence& operator=(dependence&& other)
299 {
300 if (this != &other) {
301 type = other.type;
302 ptr = other.ptr;
303 other.ptr = nullptr;
304 }
305 return *this;
306 }
307
~dependencedependence308 ~dependence()
309 {
310 if (type == ffrt_dependence_task && ptr) {
311 ffrt_task_handle_dec_ref(const_cast<ffrt_task_handle_t>(ptr));
312 }
313 }
314 };
315
316 template<class T>
317 struct function {
318 ffrt_function_header_t header;
319 T closure;
320 };
321
322 template<class T>
exec_function_wrapper(void * t)323 void exec_function_wrapper(void* t)
324 {
325 auto f = reinterpret_cast<function<std::decay_t<T>>*>(t);
326 f->closure();
327 }
328
329 template<class T>
destroy_function_wrapper(void * t)330 void destroy_function_wrapper(void* t)
331 {
332 auto f = reinterpret_cast<function<std::decay_t<T>>*>(t);
333 f->closure = nullptr;
334 }
335
336 template<class T>
337 inline ffrt_function_header_t* create_function_wrapper(T&& func,
338 ffrt_function_kind_t kind = ffrt_function_kind_general)
339 {
340 using function_type = function<std::decay_t<T>>;
341 static_assert(sizeof(function_type) <= ffrt_auto_managed_function_storage_size,
342 "size of function must be less than ffrt_auto_managed_function_storage_size");
343
344 auto p = ffrt_alloc_auto_managed_function_storage_base(kind);
345 auto f = new (p)function_type;
346 f->header.exec = exec_function_wrapper<T>;
347 f->header.destroy = destroy_function_wrapper<T>;
348 f->closure = std::forward<T>(func);
349 return reinterpret_cast<ffrt_function_header_t*>(f);
350 }
351
352 /**
353 * @brief Submits a task without input and output dependencies.
354 *
355 * @param func Indicates a task executor function closure.
356 * @param attr Indicates a task attribute.
357 * @since 10
358 * @version 1.0
359 */
360 static inline void submit(std::function<void()>&& func, const task_attr& attr = {})
361 {
362 return ffrt_submit_base(create_function_wrapper(std::move(func)), nullptr, nullptr, &attr);
363 }
364
365 /**
366 * @brief Submits a task with input dependencies only.
367 *
368 * @param func Indicates a task executor function closure.
369 * @param in_deps Indicates a pointer to the input dependencies.
370 * @param attr Indicates a task attribute.
371 * @since 10
372 * @version 1.0
373 */
374 static inline void submit(std::function<void()>&& func, std::initializer_list<dependence> in_deps,
375 const task_attr& attr = {})
376 {
377 ffrt_deps_t in{static_cast<uint32_t>(in_deps.size()), in_deps.begin()};
378 return ffrt_submit_base(create_function_wrapper(std::move(func)), &in, nullptr, &attr);
379 }
380
381 /**
382 * @brief Submits a task with input and output dependencies.
383 *
384 * @param func Indicates a task executor function closure.
385 * @param in_deps Indicates a pointer to the input dependencies.
386 * @param out_deps Indicates a pointer to the output dependencies.
387 * @param attr Indicates a task attribute.
388 * @since 10
389 * @version 1.0
390 */
391 static inline void submit(std::function<void()>&& func, std::initializer_list<dependence> in_deps,
392 std::initializer_list<dependence> out_deps, const task_attr& attr = {})
393 {
394 ffrt_deps_t in{static_cast<uint32_t>(in_deps.size()), in_deps.begin()};
395 ffrt_deps_t out{static_cast<uint32_t>(out_deps.size()), out_deps.begin()};
396 return ffrt_submit_base(create_function_wrapper(std::move(func)), &in, &out, &attr);
397 }
398
399 /**
400 * @brief Submits a task with input dependencies only.
401 *
402 * @param func Indicates a task executor function closure.
403 * @param in_deps Indicates a pointer to the input dependencies.
404 * @param attr Indicates a task attribute.
405 * @since 10
406 * @version 1.0
407 */
408 static inline void submit(std::function<void()>&& func, const std::vector<dependence>& in_deps,
409 const task_attr& attr = {})
410 {
411 ffrt_deps_t in{static_cast<uint32_t>(in_deps.size()), in_deps.data()};
412 return ffrt_submit_base(create_function_wrapper(std::move(func)), &in, nullptr, &attr);
413 }
414
415 /**
416 * @brief Submits a task with input and output dependencies.
417 *
418 * @param func Indicates a task executor function closure.
419 * @param in_deps Indicates a pointer to the input dependencies.
420 * @param out_deps Indicates a pointer to the output dependencies.
421 * @param attr Indicates a task attribute.
422 * @since 10
423 * @version 1.0
424 */
425 static inline void submit(std::function<void()>&& func, const std::vector<dependence>& in_deps,
426 const std::vector<dependence>& out_deps, const task_attr& attr = {})
427 {
428 ffrt_deps_t in{static_cast<uint32_t>(in_deps.size()), in_deps.data()};
429 ffrt_deps_t out{static_cast<uint32_t>(out_deps.size()), out_deps.data()};
430 return ffrt_submit_base(create_function_wrapper(std::move(func)), &in, &out, &attr);
431 }
432
433 /**
434 * @brief Submits a task without input and output dependencies.
435 *
436 * @param func Indicates a task executor function closure.
437 * @param attr Indicates a task attribute.
438 * @since 10
439 * @version 1.0
440 */
441 static inline void submit(const std::function<void()>& func, const task_attr& attr = {})
442 {
443 return ffrt_submit_base(create_function_wrapper(func), nullptr, nullptr, &attr);
444 }
445
446 /**
447 * @brief Submits a task with input dependencies only.
448 *
449 * @param func Indicates a task executor function closure.
450 * @param in_deps Indicates a pointer to the input dependencies.
451 * @param attr Indicates a task attribute.
452 * @since 10
453 * @version 1.0
454 */
455 static inline void submit(const std::function<void()>& func, std::initializer_list<dependence> in_deps,
456 const task_attr& attr = {})
457 {
458 ffrt_deps_t in{static_cast<uint32_t>(in_deps.size()), in_deps.begin()};
459 return ffrt_submit_base(create_function_wrapper(func), &in, nullptr, &attr);
460 }
461
462 /**
463 * @brief Submits a task with input and output dependencies.
464 *
465 * @param func Indicates a task executor function closure.
466 * @param in_deps Indicates a pointer to the input dependencies.
467 * @param out_deps Indicates a pointer to the output dependencies.
468 * @param attr Indicates a task attribute.
469 * @since 10
470 * @version 1.0
471 */
472 static inline void submit(const std::function<void()>& func, std::initializer_list<dependence> in_deps,
473 std::initializer_list<dependence> out_deps, const task_attr& attr = {})
474 {
475 ffrt_deps_t in{static_cast<uint32_t>(in_deps.size()), in_deps.begin()};
476 ffrt_deps_t out{static_cast<uint32_t>(out_deps.size()), out_deps.begin()};
477 return ffrt_submit_base(create_function_wrapper(func), &in, &out, &attr);
478 }
479
480 /**
481 * @brief Submits a task with input dependencies only.
482 *
483 * @param func Indicates a task executor function closure.
484 * @param in_deps Indicates a pointer to the input dependencies.
485 * @param attr Indicates a task attribute.
486 * @since 10
487 * @version 1.0
488 */
489 static inline void submit(const std::function<void()>& func, const std::vector<dependence>& in_deps,
490 const task_attr& attr = {})
491 {
492 ffrt_deps_t in{static_cast<uint32_t>(in_deps.size()), in_deps.data()};
493 return ffrt_submit_base(create_function_wrapper(func), &in, nullptr, &attr);
494 }
495
496 /**
497 * @brief Submits a task with input and output dependencies.
498 *
499 * @param func Indicates a task executor function closure.
500 * @param in_deps Indicates a pointer to the input dependencies.
501 * @param out_deps Indicates a pointer to the output dependencies.
502 * @param attr Indicates a task attribute.
503 * @since 10
504 * @version 1.0
505 */
506 static inline void submit(const std::function<void()>& func, const std::vector<dependence>& in_deps,
507 const std::vector<dependence>& out_deps, const task_attr& attr = {})
508 {
509 ffrt_deps_t in{static_cast<uint32_t>(in_deps.size()), in_deps.data()};
510 ffrt_deps_t out{static_cast<uint32_t>(out_deps.size()), out_deps.data()};
511 return ffrt_submit_base(create_function_wrapper(func), &in, &out, &attr);
512 }
513
514 /**
515 * @brief Submits a task without input and output dependencies, and obtains a task handle.
516 *
517 * @param func Indicates a task executor function closure.
518 * @param attr Indicates a task attribute.
519 * @return Returns a non-null task handle if the task is submitted;
520 returns a null pointer otherwise.
521 * @since 10
522 * @version 1.0
523 */
524 static inline task_handle submit_h(std::function<void()>&& func, const task_attr& attr = {})
525 {
526 return ffrt_submit_h_base(create_function_wrapper(std::move(func)), nullptr, nullptr, &attr);
527 }
528
529 /**
530 * @brief Submits a task with input dependencies only, and obtains a task handle.
531 *
532 * @param func Indicates a task executor function closure.
533 * @param in_deps Indicates a pointer to the input dependencies.
534 * @param attr Indicates a task attribute.
535 * @return Returns a non-null task handle if the task is submitted;
536 returns a null pointer otherwise.
537 * @since 10
538 * @version 1.0
539 */
540 static inline task_handle submit_h(std::function<void()>&& func, std::initializer_list<dependence> in_deps,
541 const task_attr& attr = {})
542 {
543 ffrt_deps_t in{static_cast<uint32_t>(in_deps.size()), in_deps.begin()};
544 return ffrt_submit_h_base(create_function_wrapper(std::move(func)), &in, nullptr, &attr);
545 }
546
547 /**
548 * @brief Submits a task with input and output dependencies, and obtains a task handle.
549 *
550 * @param func Indicates a task executor function closure.
551 * @param in_deps Indicates a pointer to the input dependencies.
552 * @param out_deps Indicates a pointer to the output dependencies.
553 * @param attr Indicates a task attribute.
554 * @return Returns a non-null task handle if the task is submitted;
555 returns a null pointer otherwise.
556 * @since 10
557 * @version 1.0
558 */
559 static inline task_handle submit_h(std::function<void()>&& func, std::initializer_list<dependence> in_deps,
560 std::initializer_list<dependence> out_deps, const task_attr& attr = {})
561 {
562 ffrt_deps_t in{static_cast<uint32_t>(in_deps.size()), in_deps.begin()};
563 ffrt_deps_t out{static_cast<uint32_t>(out_deps.size()), out_deps.begin()};
564 return ffrt_submit_h_base(create_function_wrapper(std::move(func)), &in, &out, &attr);
565 }
566
567 /**
568 * @brief Submits a task with input dependencies only, and obtains a task handle.
569 *
570 * @param func Indicates a task executor function closure.
571 * @param in_deps Indicates a pointer to the input dependencies.
572 * @param attr Indicates a task attribute.
573 * @return Returns a non-null task handle if the task is submitted;
574 returns a null pointer otherwise.
575 * @since 10
576 * @version 1.0
577 */
578 static inline task_handle submit_h(std::function<void()>&& func, const std::vector<dependence>& in_deps,
579 const task_attr& attr = {})
580 {
581 ffrt_deps_t in{static_cast<uint32_t>(in_deps.size()), in_deps.data()};
582 return ffrt_submit_h_base(create_function_wrapper(std::move(func)), &in, nullptr, &attr);
583 }
584
585 /**
586 * @brief Submits a task with input and output dependencies, and obtains a task handle.
587 *
588 * @param func Indicates a task executor function closure.
589 * @param in_deps Indicates a pointer to the input dependencies.
590 * @param out_deps Indicates a pointer to the output dependencies.
591 * @param attr Indicates a task attribute.
592 * @return Returns a non-null task handle if the task is submitted;
593 returns a null pointer otherwise.
594 * @since 10
595 * @version 1.0
596 */
597 static inline task_handle submit_h(std::function<void()>&& func, const std::vector<dependence>& in_deps,
598 const std::vector<dependence>& out_deps, const task_attr& attr = {})
599 {
600 ffrt_deps_t in{static_cast<uint32_t>(in_deps.size()), in_deps.data()};
601 ffrt_deps_t out{static_cast<uint32_t>(out_deps.size()), out_deps.data()};
602 return ffrt_submit_h_base(create_function_wrapper(std::move(func)), &in, &out, &attr);
603 }
604
605 /**
606 * @brief Submits a task without input and output dependencies, and obtains a task handle.
607 *
608 * @param func Indicates a task executor function closure.
609 * @param attr Indicates a task attribute.
610 * @return Returns a non-null task handle if the task is submitted;
611 returns a null pointer otherwise.
612 * @since 10
613 * @version 1.0
614 */
615 static inline task_handle submit_h(const std::function<void()>& func, const task_attr& attr = {})
616 {
617 return ffrt_submit_h_base(create_function_wrapper(func), nullptr, nullptr, &attr);
618 }
619
620 /**
621 * @brief Submits a task with input dependencies only, and obtains a task handle.
622 *
623 * @param func Indicates a task executor function closure.
624 * @param in_deps Indicates a pointer to the input dependencies.
625 * @param attr Indicates a task attribute.
626 * @return Returns a non-null task handle if the task is submitted;
627 returns a null pointer otherwise.
628 * @since 10
629 * @version 1.0
630 */
631 static inline task_handle submit_h(const std::function<void()>& func, std::initializer_list<dependence> in_deps,
632 const task_attr& attr = {})
633 {
634 ffrt_deps_t in{static_cast<uint32_t>(in_deps.size()), in_deps.begin()};
635 return ffrt_submit_h_base(create_function_wrapper(func), &in, nullptr, &attr);
636 }
637
638 /**
639 * @brief Submits a task with input and output dependencies, and obtains a task handle.
640 *
641 * @param func Indicates a task executor function closure.
642 * @param in_deps Indicates a pointer to the input dependencies.
643 * @param out_deps Indicates a pointer to the output dependencies.
644 * @param attr Indicates a task attribute.
645 * @return Returns a non-null task handle if the task is submitted;
646 returns a null pointer otherwise.
647 * @since 10
648 * @version 1.0
649 */
650 static inline task_handle submit_h(const std::function<void()>& func, std::initializer_list<dependence> in_deps,
651 std::initializer_list<dependence> out_deps, const task_attr& attr = {})
652 {
653 ffrt_deps_t in{static_cast<uint32_t>(in_deps.size()), in_deps.begin()};
654 ffrt_deps_t out{static_cast<uint32_t>(out_deps.size()), out_deps.begin()};
655 return ffrt_submit_h_base(create_function_wrapper(func), &in, &out, &attr);
656 }
657
658 /**
659 * @brief Submits a task with input dependencies only, and obtains a task handle.
660 *
661 * @param func Indicates a task executor function closure.
662 * @param in_deps Indicates a pointer to the input dependencies.
663 * @param attr Indicates a task attribute.
664 * @return Returns a non-null task handle if the task is submitted;
665 returns a null pointer otherwise.
666 * @since 10
667 * @version 1.0
668 */
669 static inline task_handle submit_h(const std::function<void()>& func, const std::vector<dependence>& in_deps,
670 const task_attr& attr = {})
671 {
672 ffrt_deps_t in{static_cast<uint32_t>(in_deps.size()), in_deps.data()};
673 return ffrt_submit_h_base(create_function_wrapper(func), &in, nullptr, &attr);
674 }
675
676 /**
677 * @brief Submits a task with input and output dependencies, and obtains a task handle.
678 *
679 * @param func Indicates a task executor function closure.
680 * @param in_deps Indicates a pointer to the input dependencies.
681 * @param out_deps Indicates a pointer to the output dependencies.
682 * @param attr Indicates a task attribute.
683 * @return Returns a non-null task handle if the task is submitted;
684 returns a null pointer otherwise.
685 * @since 10
686 * @version 1.0
687 */
688 static inline task_handle submit_h(const std::function<void()>& func, const std::vector<dependence>& in_deps,
689 const std::vector<dependence>& out_deps, const task_attr& attr = {})
690 {
691 ffrt_deps_t in{static_cast<uint32_t>(in_deps.size()), in_deps.data()};
692 ffrt_deps_t out{static_cast<uint32_t>(out_deps.size()), out_deps.data()};
693 return ffrt_submit_h_base(create_function_wrapper(func), &in, &out, &attr);
694 }
695
696 /**
697 * @brief Waits until all submitted tasks are complete.
698 *
699 * @since 10
700 * @version 1.0
701 */
wait()702 static inline void wait()
703 {
704 ffrt_wait();
705 }
706
707 /**
708 * @brief Waits until dependent tasks are complete.
709 *
710 * @param deps Indicates a pointer to the dependent tasks.
711 * @since 10
712 * @version 1.0
713 */
wait(std::initializer_list<dependence> deps)714 static inline void wait(std::initializer_list<dependence> deps)
715 {
716 ffrt_deps_t d{static_cast<uint32_t>(deps.size()), deps.begin()};
717 ffrt_wait_deps(&d);
718 }
719
720 /**
721 * @brief Waits until dependent tasks are complete.
722 *
723 * @param deps Indicates a pointer to the dependent tasks.
724 * @since 10
725 * @version 1.0
726 */
wait(const std::vector<dependence> & deps)727 static inline void wait(const std::vector<dependence>& deps)
728 {
729 ffrt_deps_t d{static_cast<uint32_t>(deps.size()), deps.data()};
730 ffrt_wait_deps(&d);
731 }
732
733 /**
734 * @brief Sets the thread stack size of a specified QoS level.
735 *
736 * @param qos_ Indicates the QoS.
737 * @param stack_size Indicates the thread stack size.
738 * @return Returns ffrt_success if the stack size set success;
739 returns ffrt_error_inval if qos_ or stack_size invalid;
740 returns ffrt_error otherwise.
741 * @since 10
742 * @version 1.0
743 */
set_worker_stack_size(qos qos_,size_t stack_size)744 static inline ffrt_error_t set_worker_stack_size(qos qos_, size_t stack_size)
745 {
746 return ffrt_set_worker_stack_size(qos_, stack_size);
747 }
748
749 namespace this_task {
update_qos(qos qos_)750 static inline int update_qos(qos qos_)
751 {
752 return ffrt_this_task_update_qos(qos_);
753 }
754
755 /**
756 * @brief Obtains the ID of this task.
757 *
758 * @return Returns the task ID.
759 * @since 10
760 * @version 1.0
761 */
get_id()762 static inline uint64_t get_id()
763 {
764 return ffrt_this_task_get_id();
765 }
766 } // namespace this_task
767 } // namespace ffrt
768 #endif
769