17777dab0Sopenharmony_ci/*
27777dab0Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
37777dab0Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
47777dab0Sopenharmony_ci * you may not use this file except in compliance with the License.
57777dab0Sopenharmony_ci * You may obtain a copy of the License at
67777dab0Sopenharmony_ci *
77777dab0Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
87777dab0Sopenharmony_ci *
97777dab0Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
107777dab0Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
117777dab0Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
127777dab0Sopenharmony_ci * See the License for the specific language governing permissions and
137777dab0Sopenharmony_ci * limitations under the License.
147777dab0Sopenharmony_ci */
157777dab0Sopenharmony_ci
167777dab0Sopenharmony_ci/**
177777dab0Sopenharmony_ci * @addtogroup Ffrt
187777dab0Sopenharmony_ci * @{
197777dab0Sopenharmony_ci *
207777dab0Sopenharmony_ci * @brief ffrt provides APIs.
217777dab0Sopenharmony_ci *
227777dab0Sopenharmony_ci *
237777dab0Sopenharmony_ci * @syscap SystemCapability.Resourceschedule.Ffrt.Core
247777dab0Sopenharmony_ci *
257777dab0Sopenharmony_ci * @since 10
267777dab0Sopenharmony_ci */
277777dab0Sopenharmony_ci
287777dab0Sopenharmony_ci /**
297777dab0Sopenharmony_ci * @file task.h
307777dab0Sopenharmony_ci * @kit FunctionFlowRuntimeKit
317777dab0Sopenharmony_ci *
327777dab0Sopenharmony_ci * @brief Declares the task interfaces in C.
337777dab0Sopenharmony_ci *
347777dab0Sopenharmony_ci * @syscap SystemCapability.Resourceschedule.Ffrt.Core
357777dab0Sopenharmony_ci * @since 10
367777dab0Sopenharmony_ci * @version 1.0
377777dab0Sopenharmony_ci */
387777dab0Sopenharmony_ci#ifndef FFRT_API_C_TASK_H
397777dab0Sopenharmony_ci#define FFRT_API_C_TASK_H
407777dab0Sopenharmony_ci#include <stdint.h>
417777dab0Sopenharmony_ci#include "type_def.h"
427777dab0Sopenharmony_ci
437777dab0Sopenharmony_ci/**
447777dab0Sopenharmony_ci * @brief Initializes a task attribute.
457777dab0Sopenharmony_ci *
467777dab0Sopenharmony_ci * @param attr Indicates a pointer to the task attribute.
477777dab0Sopenharmony_ci * @return Returns <b>0</b> if the task attribute is initialized;
487777dab0Sopenharmony_ci           returns <b>-1</b> otherwise.
497777dab0Sopenharmony_ci * @since 10
507777dab0Sopenharmony_ci * @version 1.0
517777dab0Sopenharmony_ci */
527777dab0Sopenharmony_ciFFRT_C_API int ffrt_task_attr_init(ffrt_task_attr_t* attr);
537777dab0Sopenharmony_ci
547777dab0Sopenharmony_ci/**
557777dab0Sopenharmony_ci * @brief Sets a task name.
567777dab0Sopenharmony_ci *
577777dab0Sopenharmony_ci * @param attr Indicates a pointer to the task attribute.
587777dab0Sopenharmony_ci * @param name Indicates a pointer to the task name.
597777dab0Sopenharmony_ci * @since 10
607777dab0Sopenharmony_ci * @version 1.0
617777dab0Sopenharmony_ci */
627777dab0Sopenharmony_ciFFRT_C_API void ffrt_task_attr_set_name(ffrt_task_attr_t* attr, const char* name);
637777dab0Sopenharmony_ci
647777dab0Sopenharmony_ci/**
657777dab0Sopenharmony_ci * @brief Obtains a task name.
667777dab0Sopenharmony_ci *
677777dab0Sopenharmony_ci * @param attr Indicates a pointer to the task attribute.
687777dab0Sopenharmony_ci * @return Returns a non-null pointer to the task name if the name is obtained;
697777dab0Sopenharmony_ci           returns a null pointer otherwise.
707777dab0Sopenharmony_ci * @since 10
717777dab0Sopenharmony_ci * @version 1.0
727777dab0Sopenharmony_ci */
737777dab0Sopenharmony_ciFFRT_C_API const char* ffrt_task_attr_get_name(const ffrt_task_attr_t* attr);
747777dab0Sopenharmony_ci
757777dab0Sopenharmony_ci/**
767777dab0Sopenharmony_ci * @brief Destroys a task attribute.
777777dab0Sopenharmony_ci *
787777dab0Sopenharmony_ci * @param attr Indicates a pointer to the task attribute.
797777dab0Sopenharmony_ci * @since 10
807777dab0Sopenharmony_ci * @version 1.0
817777dab0Sopenharmony_ci */
827777dab0Sopenharmony_ciFFRT_C_API void ffrt_task_attr_destroy(ffrt_task_attr_t* attr);
837777dab0Sopenharmony_ci
847777dab0Sopenharmony_ci/**
857777dab0Sopenharmony_ci * @brief Sets the QoS for a task attribute.
867777dab0Sopenharmony_ci *
877777dab0Sopenharmony_ci * @param attr Indicates a pointer to the task attribute.
887777dab0Sopenharmony_ci * @param qos Indicates the QoS.
897777dab0Sopenharmony_ci * @since 10
907777dab0Sopenharmony_ci * @version 1.0
917777dab0Sopenharmony_ci */
927777dab0Sopenharmony_ciFFRT_C_API void ffrt_task_attr_set_qos(ffrt_task_attr_t* attr, ffrt_qos_t qos);
937777dab0Sopenharmony_ci
947777dab0Sopenharmony_ci/**
957777dab0Sopenharmony_ci * @brief Obtains the QoS of a task attribute.
967777dab0Sopenharmony_ci *
977777dab0Sopenharmony_ci * @param attr Indicates a pointer to the task attribute.
987777dab0Sopenharmony_ci * @return Returns the QoS, which is <b>ffrt_qos_default</b> by default.
997777dab0Sopenharmony_ci * @since 10
1007777dab0Sopenharmony_ci * @version 1.0
1017777dab0Sopenharmony_ci */
1027777dab0Sopenharmony_ciFFRT_C_API ffrt_qos_t ffrt_task_attr_get_qos(const ffrt_task_attr_t* attr);
1037777dab0Sopenharmony_ci
1047777dab0Sopenharmony_ci/**
1057777dab0Sopenharmony_ci * @brief Sets the task delay time.
1067777dab0Sopenharmony_ci *
1077777dab0Sopenharmony_ci * @param attr Indicates a pointer to the task attribute.
1087777dab0Sopenharmony_ci * @param delay_us Indicates the delay time, in microseconds.
1097777dab0Sopenharmony_ci * @since 10
1107777dab0Sopenharmony_ci * @version 1.0
1117777dab0Sopenharmony_ci */
1127777dab0Sopenharmony_ciFFRT_C_API void ffrt_task_attr_set_delay(ffrt_task_attr_t* attr, uint64_t delay_us);
1137777dab0Sopenharmony_ci
1147777dab0Sopenharmony_ci/**
1157777dab0Sopenharmony_ci * @brief Obtains the task delay time.
1167777dab0Sopenharmony_ci *
1177777dab0Sopenharmony_ci * @param attr Indicates a pointer to the task attribute.
1187777dab0Sopenharmony_ci * @return Returns the delay time.
1197777dab0Sopenharmony_ci * @since 10
1207777dab0Sopenharmony_ci * @version 1.0
1217777dab0Sopenharmony_ci */
1227777dab0Sopenharmony_ciFFRT_C_API uint64_t ffrt_task_attr_get_delay(const ffrt_task_attr_t* attr);
1237777dab0Sopenharmony_ci
1247777dab0Sopenharmony_ci/**
1257777dab0Sopenharmony_ci * @brief Sets the task priority.
1267777dab0Sopenharmony_ci *
1277777dab0Sopenharmony_ci * @param attr Indicates a pointer to the task attribute.
1287777dab0Sopenharmony_ci * @param priority Indicates the execute priority of concurrent queue task.
1297777dab0Sopenharmony_ci * @since 12
1307777dab0Sopenharmony_ci * @version 1.0
1317777dab0Sopenharmony_ci */
1327777dab0Sopenharmony_ciFFRT_C_API void ffrt_task_attr_set_queue_priority(ffrt_task_attr_t* attr, ffrt_queue_priority_t priority);
1337777dab0Sopenharmony_ci
1347777dab0Sopenharmony_ci/**
1357777dab0Sopenharmony_ci * @brief Obtains the task priority.
1367777dab0Sopenharmony_ci *
1377777dab0Sopenharmony_ci * @param attr Indicates a pointer to the task attribute.
1387777dab0Sopenharmony_ci * @return Returns the priority of concurrent queue task.
1397777dab0Sopenharmony_ci * @since 12
1407777dab0Sopenharmony_ci * @version 1.0
1417777dab0Sopenharmony_ci */
1427777dab0Sopenharmony_ciFFRT_C_API ffrt_queue_priority_t ffrt_task_attr_get_queue_priority(const ffrt_task_attr_t* attr);
1437777dab0Sopenharmony_ci
1447777dab0Sopenharmony_ci/**
1457777dab0Sopenharmony_ci * @brief Sets the task stack size.
1467777dab0Sopenharmony_ci *
1477777dab0Sopenharmony_ci * @param attr Indicates a pointer to the task attribute.
1487777dab0Sopenharmony_ci * @param size Indicates the task stack size, unit is byte.
1497777dab0Sopenharmony_ci * @since 12
1507777dab0Sopenharmony_ci * @version 1.0
1517777dab0Sopenharmony_ci */
1527777dab0Sopenharmony_ciFFRT_C_API void ffrt_task_attr_set_stack_size(ffrt_task_attr_t* attr, uint64_t size);
1537777dab0Sopenharmony_ci
1547777dab0Sopenharmony_ci/**
1557777dab0Sopenharmony_ci * @brief Obtains the task stack size.
1567777dab0Sopenharmony_ci *
1577777dab0Sopenharmony_ci * @param attr Indicates a pointer to the task attribute.
1587777dab0Sopenharmony_ci * @return Returns the task stack size, unit is byte.
1597777dab0Sopenharmony_ci * @since 12
1607777dab0Sopenharmony_ci * @version 1.0
1617777dab0Sopenharmony_ci */
1627777dab0Sopenharmony_ciFFRT_C_API uint64_t ffrt_task_attr_get_stack_size(const ffrt_task_attr_t* attr);
1637777dab0Sopenharmony_ci
1647777dab0Sopenharmony_ci/**
1657777dab0Sopenharmony_ci * @brief Updates the QoS of this task.
1667777dab0Sopenharmony_ci *
1677777dab0Sopenharmony_ci * @param qos Indicates the new QoS.
1687777dab0Sopenharmony_ci * @return Returns <b>0</b> if the QoS is updated;
1697777dab0Sopenharmony_ci           returns <b>-1</b> otherwise.
1707777dab0Sopenharmony_ci * @since 10
1717777dab0Sopenharmony_ci * @version 1.0
1727777dab0Sopenharmony_ci */
1737777dab0Sopenharmony_ciFFRT_C_API int ffrt_this_task_update_qos(ffrt_qos_t qos);
1747777dab0Sopenharmony_ci
1757777dab0Sopenharmony_ci/**
1767777dab0Sopenharmony_ci * @brief Obtains the qos of this task.
1777777dab0Sopenharmony_ci *
1787777dab0Sopenharmony_ci * @return Returns the task qos.
1797777dab0Sopenharmony_ci * @since 12
1807777dab0Sopenharmony_ci * @version 1.0
1817777dab0Sopenharmony_ci */
1827777dab0Sopenharmony_ciFFRT_C_API ffrt_qos_t ffrt_this_task_get_qos();
1837777dab0Sopenharmony_ci
1847777dab0Sopenharmony_ci/**
1857777dab0Sopenharmony_ci * @brief Obtains the ID of this task.
1867777dab0Sopenharmony_ci *
1877777dab0Sopenharmony_ci * @return Returns the task ID.
1887777dab0Sopenharmony_ci * @since 10
1897777dab0Sopenharmony_ci * @version 1.0
1907777dab0Sopenharmony_ci */
1917777dab0Sopenharmony_ciFFRT_C_API uint64_t ffrt_this_task_get_id(void);
1927777dab0Sopenharmony_ci
1937777dab0Sopenharmony_ci/**
1947777dab0Sopenharmony_ci * @brief Applies for memory for the function execution structure.
1957777dab0Sopenharmony_ci *
1967777dab0Sopenharmony_ci * @param kind Indicates the type of the function execution structure, which can be common or queue.
1977777dab0Sopenharmony_ci * @return Returns a non-null pointer if the memory is allocated;
1987777dab0Sopenharmony_ci           returns a null pointer otherwise.
1997777dab0Sopenharmony_ci * @since 10
2007777dab0Sopenharmony_ci * @version 1.0
2017777dab0Sopenharmony_ci */
2027777dab0Sopenharmony_ciFFRT_C_API void *ffrt_alloc_auto_managed_function_storage_base(ffrt_function_kind_t kind);
2037777dab0Sopenharmony_ci
2047777dab0Sopenharmony_ci/**
2057777dab0Sopenharmony_ci * @brief Submits a task.
2067777dab0Sopenharmony_ci *
2077777dab0Sopenharmony_ci * @param f Indicates a pointer to the task executor.
2087777dab0Sopenharmony_ci * @param in_deps Indicates a pointer to the input dependencies.
2097777dab0Sopenharmony_ci * @param out_deps Indicates a pointer to the output dependencies.
2107777dab0Sopenharmony_ci * @param attr Indicates a pointer to the task attribute.
2117777dab0Sopenharmony_ci * @since 10
2127777dab0Sopenharmony_ci * @version 1.0
2137777dab0Sopenharmony_ci */
2147777dab0Sopenharmony_ciFFRT_C_API void ffrt_submit_base(ffrt_function_header_t* f, const ffrt_deps_t* in_deps, const ffrt_deps_t* out_deps,
2157777dab0Sopenharmony_ci    const ffrt_task_attr_t* attr);
2167777dab0Sopenharmony_ci
2177777dab0Sopenharmony_ci/**
2187777dab0Sopenharmony_ci * @brief Submits a task, and obtains a task handle.
2197777dab0Sopenharmony_ci *
2207777dab0Sopenharmony_ci * @param f Indicates a pointer to the task executor.
2217777dab0Sopenharmony_ci * @param in_deps Indicates a pointer to the input dependencies.
2227777dab0Sopenharmony_ci * @param out_deps Indicates a pointer to the output dependencies.
2237777dab0Sopenharmony_ci * @param attr Indicates a pointer to the task attribute.
2247777dab0Sopenharmony_ci * @return Returns a non-null task handle if the task is submitted;
2257777dab0Sopenharmony_ci           returns a null pointer otherwise.
2267777dab0Sopenharmony_ci * @since 10
2277777dab0Sopenharmony_ci * @version 1.0
2287777dab0Sopenharmony_ci */
2297777dab0Sopenharmony_ciFFRT_C_API ffrt_task_handle_t ffrt_submit_h_base(ffrt_function_header_t* f, const ffrt_deps_t* in_deps,
2307777dab0Sopenharmony_ci    const ffrt_deps_t* out_deps, const ffrt_task_attr_t* attr);
2317777dab0Sopenharmony_ci
2327777dab0Sopenharmony_ci/**
2337777dab0Sopenharmony_ci * @brief increase reference count of task handle.
2347777dab0Sopenharmony_ci *
2357777dab0Sopenharmony_ci * @param handle Indicates a task handle.
2367777dab0Sopenharmony_ci * @return return the task handle original reference count.
2377777dab0Sopenharmony_ci * @since 12
2387777dab0Sopenharmony_ci * @version 1.0
2397777dab0Sopenharmony_ci */
2407777dab0Sopenharmony_ciFFRT_C_API uint32_t ffrt_task_handle_inc_ref(ffrt_task_handle_t handle);
2417777dab0Sopenharmony_ci
2427777dab0Sopenharmony_ci/**
2437777dab0Sopenharmony_ci * @brief decrease reference count of task handle.
2447777dab0Sopenharmony_ci *
2457777dab0Sopenharmony_ci * @param handle Indicates a task handle.
2467777dab0Sopenharmony_ci * @return return the task handle original reference count.
2477777dab0Sopenharmony_ci * @since 12
2487777dab0Sopenharmony_ci * @version 1.0
2497777dab0Sopenharmony_ci */
2507777dab0Sopenharmony_ciFFRT_C_API uint32_t ffrt_task_handle_dec_ref(ffrt_task_handle_t handle);
2517777dab0Sopenharmony_ci
2527777dab0Sopenharmony_ci/**
2537777dab0Sopenharmony_ci * @brief Destroys a task handle.
2547777dab0Sopenharmony_ci *
2557777dab0Sopenharmony_ci * @param handle Indicates a task handle.
2567777dab0Sopenharmony_ci * @since 10
2577777dab0Sopenharmony_ci * @version 1.0
2587777dab0Sopenharmony_ci */
2597777dab0Sopenharmony_ciFFRT_C_API void ffrt_task_handle_destroy(ffrt_task_handle_t handle);
2607777dab0Sopenharmony_ci
2617777dab0Sopenharmony_ci/**
2627777dab0Sopenharmony_ci * @brief Waits until the dependent tasks are complete.
2637777dab0Sopenharmony_ci *
2647777dab0Sopenharmony_ci * @param deps Indicates a pointer to the dependent tasks.
2657777dab0Sopenharmony_ci * @since 10
2667777dab0Sopenharmony_ci * @version 1.0
2677777dab0Sopenharmony_ci */
2687777dab0Sopenharmony_ciFFRT_C_API void ffrt_wait_deps(const ffrt_deps_t* deps);
2697777dab0Sopenharmony_ci
2707777dab0Sopenharmony_ci/**
2717777dab0Sopenharmony_ci * @brief Waits until all submitted tasks are complete.
2727777dab0Sopenharmony_ci *
2737777dab0Sopenharmony_ci * @since 10
2747777dab0Sopenharmony_ci * @version 1.0
2757777dab0Sopenharmony_ci */
2767777dab0Sopenharmony_ciFFRT_C_API void ffrt_wait(void);
2777777dab0Sopenharmony_ci
2787777dab0Sopenharmony_ci#endif
279