diff --git a/bundle.json b/bundle.json index d5c263b..d4402fe 100644 --- a/bundle.json +++ b/bundle.json @@ -46,7 +46,6 @@ "header_base": "//foundation/resourceschedule/ffrt/interfaces/", "header_files": [ "kits/ffrt.h", - "inner_api/deadline.h", "inner_api/ffrt_inner.h" ] }, diff --git a/interfaces/kits/c/deadline.h b/interfaces/inner_api/c/deadline.h similarity index 100% rename from interfaces/kits/c/deadline.h rename to interfaces/inner_api/c/deadline.h diff --git a/interfaces/inner_api/c/executor_task.h b/interfaces/inner_api/c/executor_task.h new file mode 100644 index 0000000..8d4c698 --- /dev/null +++ b/interfaces/inner_api/c/executor_task.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef FFRT_API_C_EXECUTOR_TASK_H +#define FFRT_API_C_EXECUTOR_TASK_H + +#include "type_def.h" + +typedef enum { + ffrt_normal_task = 0, + ffrt_rust_task = 1, + ffrt_uv_task // only used to register func for libuv +} ffrt_executor_task_type_t; + +typedef struct ffrt_executor_task { + uintptr_t reserved[2]; + uintptr_t type; // 0: TaskCtx, 1: rust task, User Space Address: libuv work + void* wq[2]; +} ffrt_executor_task_t; + +typedef void (*ffrt_executor_task_func)(ffrt_executor_task_t* data); + +FFRT_C_API void ffrt_executor_task_register_func(ffrt_executor_task_func func, const char* name); +FFRT_C_API void ffrt_executor_task_submit(ffrt_executor_task_t *task, const ffrt_task_attr_t *attr); +FFRT_C_API int ffrt_executor_task_cancel(ffrt_executor_task_t *task, const ffrt_qos_t qos); + +#endif \ No newline at end of file diff --git a/interfaces/inner_api/ffrt_watchdog.h b/interfaces/inner_api/c/ffrt_watchdog.h similarity index 95% rename from interfaces/inner_api/ffrt_watchdog.h rename to interfaces/inner_api/c/ffrt_watchdog.h index 107e392..89bf73d 100644 --- a/interfaces/inner_api/ffrt_watchdog.h +++ b/interfaces/inner_api/c/ffrt_watchdog.h @@ -15,7 +15,7 @@ #ifndef FFRT_WATCHDOG_H #define FFRT_WATCHDOG_H #include -#include "c/type_def.h" +#include "type_def.h" typedef void(*ffrt_watchdog_cb)(uint64_t, const char *, uint32_t); FFRT_C_API void ffrt_watchdog_dumpinfo(char *buf, uint32_t len); diff --git a/interfaces/inner_api/c/task.h b/interfaces/inner_api/c/task.h new file mode 100644 index 0000000..336b741 --- /dev/null +++ b/interfaces/inner_api/c/task.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FFRT_INNER_API_C_TASK_H +#define FFRT_INNER_API_C_TASK_H +#include "type_def.h" + +/** + * @brief Skips a task. + * + * @param handle Indicates a task handle. + * @return Returns 0 if the task is skipped; + returns -1 otherwise. + * @since 10 + * @version 1.0 + */ +FFRT_C_API int ffrt_skip(ffrt_task_handle_t handle); + +// config +FFRT_C_API int ffrt_set_cgroup_attr(ffrt_qos_t qos, ffrt_os_sched_attr* attr); +#endif diff --git a/interfaces/kits/c/thread.h b/interfaces/inner_api/c/thread.h similarity index 100% rename from interfaces/kits/c/thread.h rename to interfaces/inner_api/c/thread.h diff --git a/interfaces/inner_api/c/type_def.h b/interfaces/inner_api/c/type_def.h new file mode 100644 index 0000000..dc2a08d --- /dev/null +++ b/interfaces/inner_api/c/type_def.h @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + /** + * @file type_def.h + * + * @brief Declares common types. + * + * @since 10 + * @version 1.0 + */ +#ifndef FFRT_INNER_API_C_TYPE_DEF_H +#define FFRT_INNER_API_C_TYPE_DEF_H +#include +#include +#include "../../kits/c/type_def.h" + +#ifdef __cplusplus +#define FFRT_C_API extern "C" +#else +#define FFRT_C_API +#endif + +/** + * @brief Enumerates the task QoS types. + * + */ +typedef enum { + ffrt_qos_deadline_request = 4, + ffrt_qos_user_interactive, + ffrt_qos_max = ffrt_qos_user_interactive, +} ffrt_inner_qos_default_t; + +typedef enum { + ffrt_stack_protect_weak, + ffrt_stack_protect_strong +} ffrt_stack_protect_t; + +typedef enum { + ffrt_thread_attr_storage_size = 64, +} ffrt_inner_storage_size_t; + +typedef struct { + uint32_t storage[(ffrt_thread_attr_storage_size + sizeof(uint32_t) - 1) / sizeof(uint32_t)]; +} ffrt_thread_attr_t; + +#define MAX_CPUMAP_LENGTH 100 // this is in c and code style +typedef struct { + int shares; + int latency_nice; + int uclamp_min; + int uclamp_max; + int vip_prio; + char cpumap[MAX_CPUMAP_LENGTH]; +} ffrt_os_sched_attr; + +typedef void* ffrt_thread_t; + +typedef void* ffrt_interval_t; + +typedef enum { + ffrt_sys_event_type_read, +} ffrt_sys_event_type_t; + +typedef enum { + ffrt_sys_event_status_no_timeout, + ffrt_sys_event_status_timeout +} ffrt_sys_event_status_t; + +typedef void* ffrt_sys_event_handle_t; + +typedef void* ffrt_config_t; + +#ifdef __cplusplus +namespace ffrt { +enum qos_inner_default { + qos_deadline_request = ffrt_qos_deadline_request, + qos_user_interactive = ffrt_qos_user_interactive, + qos_max = ffrt_qos_max, +}; + +enum class stack_protect { + weak = ffrt_stack_protect_weak, + strong = ffrt_stack_protect_strong, +}; +} +#endif +#endif diff --git a/interfaces/inner_api/deadline.h b/interfaces/inner_api/cpp/deadline.h similarity index 98% rename from interfaces/inner_api/deadline.h rename to interfaces/inner_api/cpp/deadline.h index 48640b2..d9ea4b1 100644 --- a/interfaces/inner_api/deadline.h +++ b/interfaces/inner_api/cpp/deadline.h @@ -14,7 +14,7 @@ */ #ifndef FFRT_API_CPP_DEADLINE_H #define FFRT_API_CPP_DEADLINE_H -#include "c/deadline.h" +#include "../c/deadline.h" namespace ffrt { using interval = ffrt_interval_t; @@ -74,7 +74,6 @@ static inline int qos_interval_leave(interval it) { return ffrt_interval_leave(it); } - }; // namespace ffrt #endif diff --git a/interfaces/kits/cpp/future.h b/interfaces/inner_api/cpp/future.h similarity index 99% rename from interfaces/kits/cpp/future.h rename to interfaces/inner_api/cpp/future.h index d508b44..4bc464c 100644 --- a/interfaces/kits/cpp/future.h +++ b/interfaces/inner_api/cpp/future.h @@ -18,8 +18,8 @@ #include #include #include -#include "condition_variable.h" -#include "thread.h" +#include "cpp/condition_variable.h" +#include "cpp/thread.h" namespace ffrt { struct non_copyable { diff --git a/interfaces/inner_api/qos_convert.h b/interfaces/inner_api/cpp/qos_convert.h similarity index 93% rename from interfaces/inner_api/qos_convert.h rename to interfaces/inner_api/cpp/qos_convert.h index 824137c..f753dac 100644 --- a/interfaces/inner_api/qos_convert.h +++ b/interfaces/inner_api/cpp/qos_convert.h @@ -14,7 +14,7 @@ */ #ifndef FFRT_API_CPP_QOS_CONVERT_H #define FFRT_API_CPP_QOS_CONVERT_H -#include "c/type_def.h" +#include "../c/type_def.h" namespace ffrt { constexpr int ERROR_NUM = -1; diff --git a/interfaces/inner_api/cpp/task.h b/interfaces/inner_api/cpp/task.h new file mode 100644 index 0000000..eeee8e4 --- /dev/null +++ b/interfaces/inner_api/cpp/task.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + /** + * @file task.h + * + * @brief Declares the task inner interfaces in C++. + * + * @since 10 + * @version 1.0 + */ +#ifndef FFRT_INNER_API_CPP_TASK_H +#define FFRT_INNER_API_CPP_TASK_H +#include +#include +#include +#include +#include "../c/task.h" + +namespace ffrt { +/** + * @brief Skips a task. + * + * @param handle Indicates a task handle. + * @return Returns 0 if the task is skipped; + returns -1 otherwise. + * @since 10 + * @version 1.0 + */ +static inline int skip(task_handle &handle) +{ + return ffrt_skip(handle); +} +} // namespace ffrt +#endif diff --git a/interfaces/kits/cpp/thread.h b/interfaces/inner_api/cpp/thread.h similarity index 99% rename from interfaces/kits/cpp/thread.h rename to interfaces/inner_api/cpp/thread.h index 1fd8ce0..ce41ca9 100644 --- a/interfaces/kits/cpp/thread.h +++ b/interfaces/inner_api/cpp/thread.h @@ -16,7 +16,7 @@ #define FFRT_API_CPP_THREAD_H #include #include -#include "task.h" +#include "cpp/task.h" namespace ffrt { class thread { diff --git a/interfaces/inner_api/ffrt_inner.h b/interfaces/inner_api/ffrt_inner.h index 8959479..0695a1e 100644 --- a/interfaces/inner_api/ffrt_inner.h +++ b/interfaces/inner_api/ffrt_inner.h @@ -15,5 +15,16 @@ #ifndef FFRT_API_FFRT_INNER_H #define FFRT_API_FFRT_INNER_H #include "../kits/ffrt.h" -#include "ffrt_watchdog.h" +#ifdef __cplusplus +#include "cpp/thread.h" +#include "cpp/future.h" +#include "cpp/task.h" +#include "cpp/deadline.h" +#include "cpp/qos_convert.h" +#else +#include "c/task.h" +#include "c/thread.h" +#include "c/ffrt_watchdog.h" +#include "c/executor_task.h" +#endif #endif diff --git a/interfaces/kits/c/condition_variable.h b/interfaces/kits/c/condition_variable.h index 80f8b6c..bf36f14 100644 --- a/interfaces/kits/c/condition_variable.h +++ b/interfaces/kits/c/condition_variable.h @@ -12,25 +12,90 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + + /** + * @file condition_variable.h + * + * @brief Declares the condition variable interfaces in C. + * + * @since 10 + * @version 1.0 + */ #ifndef FFRT_API_C_CONDITION_VARIABLE_H #define FFRT_API_C_CONDITION_VARIABLE_H #include #include "type_def.h" -typedef enum { - ffrt_clock_realtime = CLOCK_REALTIME, - ffrt_clock_monotonic = CLOCK_MONOTONIC -} ffrt_clockid_t; - -FFRT_C_API int ffrt_condattr_init(ffrt_condattr_t* attr); -FFRT_C_API int ffrt_condattr_destroy(ffrt_condattr_t* attr); -FFRT_C_API int ffrt_condattr_setclock(ffrt_condattr_t* attr, ffrt_clockid_t clock); -FFRT_C_API int ffrt_condattr_getclock(const ffrt_condattr_t* attr, ffrt_clockid_t* clock); - +/** + * @brief Initializes a condition variable. + * + * @param cond Indicates a pointer to the condition variable. + * @param attr Indicates a pointer to the condition variable attribute. + * @return Returns ffrt_thrd_success if the condition variable is initialized; + returns ffrt_thrd_error otherwise. + * @since 10 + * @version 1.0 + */ FFRT_C_API int ffrt_cond_init(ffrt_cond_t* cond, const ffrt_condattr_t* attr); + +/** + * @brief Unblocks at least one of the threads that are blocked on a condition variable. + * + * @param cond Indicates a pointer to the condition variable. + * @return Returns ffrt_thrd_success if the thread is unblocked; + returns ffrt_thrd_error otherwise. + * @since 10 + * @version 1.0 + */ FFRT_C_API int ffrt_cond_signal(ffrt_cond_t* cond); + +/** + * @brief Unblocks all threads currently blocked on a condition variable. + * + * @param cond Indicates a pointer to the condition variable. + * @return Returns ffrt_thrd_success if the threads are unblocked; + returns ffrt_thrd_error otherwise. + * @since 10 + * @version 1.0 + */ FFRT_C_API int ffrt_cond_broadcast(ffrt_cond_t* cond); + +/** + * @brief Blocks the calling thread. + * + * @param cond Indicates a pointer to the condition variable. + * @param mutex Indicates a pointer to the mutex. + * @return Returns ffrt_thrd_success if the thread is unblocked after being blocked; + returns ffrt_thrd_error otherwise. + * @since 10 + * @version 1.0 + */ FFRT_C_API int ffrt_cond_wait(ffrt_cond_t* cond, ffrt_mutex_t* mutex); + +/** + * @brief Blocks the calling thread for a given duration. + * + * @param cond Indicates a pointer to the condition variable. + * @param mutex Indicates a pointer to the mutex. + * @param time_point Indicates the maximum duration that the thread is blocked. + * If ffrt_cond_signal or ffrt_cond_broadcast is not called to unblock the thread + * when the maximum duration reaches, the thread is automatically unblocked. + * @return Returns ffrt_thrd_success if the thread is unblocked after being blocked; + returns ffrt_thrd_timedout if the maximum duration reaches; + returns ffrt_thrd_error if the blocking fails. + * @since 10 + * @version 1.0 + */ FFRT_C_API int ffrt_cond_timedwait(ffrt_cond_t* cond, ffrt_mutex_t* mutex, const struct timespec* time_point); + +/** + * @brief Destroys a condition variable. + * + * @param cond Indicates a pointer to the condition variable. + * @return Returns ffrt_thrd_success if the condition variable is destroyed; + returns ffrt_thrd_error otherwise. + * @since 10 + * @version 1.0 + */ FFRT_C_API int ffrt_cond_destroy(ffrt_cond_t* cond); #endif diff --git a/interfaces/kits/c/mutex.h b/interfaces/kits/c/mutex.h index 4724235..bdd0e03 100644 --- a/interfaces/kits/c/mutex.h +++ b/interfaces/kits/c/mutex.h @@ -12,13 +12,72 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + + /** + * @file mutex.h + * + * @brief Declares the mutex interfaces in C. + * + * @since 10 + * @version 1.0 + */ #ifndef FFRT_API_C_MUTEX_H #define FFRT_API_C_MUTEX_H #include "type_def.h" +/** + * @brief Initializes a mutex. + * + * @param mutex Indicates a pointer to the mutex. + * @param attr Indicates a pointer to the mutex attribute. + * @return Returns ffrt_thrd_success if the mutex is initialized; + returns ffrt_thrd_error otherwise. + * @since 10 + * @version 1.0 + */ FFRT_C_API int ffrt_mutex_init(ffrt_mutex_t* mutex, const ffrt_mutexattr_t* attr); + +/** + * @brief Locks a mutex. + * + * @param mutex Indicates a pointer to the mutex. + * @return Returns ffrt_thrd_success if the mutex is locked; + returns ffrt_thrd_error or blocks the calling thread otherwise. + * @since 10 + * @version 1.0 + */ FFRT_C_API int ffrt_mutex_lock(ffrt_mutex_t* mutex); + +/** + * @brief Unlocks a mutex. + * + * @param mutex Indicates a pointer to the mutex. + * @return Returns ffrt_thrd_success if the mutex is unlocked; + returns ffrt_thrd_error otherwise. + * @since 10 + * @version 1.0 + */ FFRT_C_API int ffrt_mutex_unlock(ffrt_mutex_t* mutex); + +/** + * @brief Attempts to lock a mutex. + * + * @param mutex Indicates a pointer to the mutex. + * @return Returns ffrt_thrd_success if the mutex is locked; + returns ffrt_thrd_error or ffrt_thrd_busy otherwise. + * @since 10 + * @version 1.0 + */ FFRT_C_API int ffrt_mutex_trylock(ffrt_mutex_t* mutex); + +/** + * @brief Destroys a mutex. + * + * @param mutex Indicates a pointer to the mutex. + * @return Returns ffrt_thrd_success if the mutex is destroyed; + returns ffrt_thrd_error otherwise. + * @since 10 + * @version 1.0 + */ FFRT_C_API int ffrt_mutex_destroy(ffrt_mutex_t* mutex); #endif diff --git a/interfaces/kits/c/queue.h b/interfaces/kits/c/queue.h index fb1666a..b9a5ebd 100644 --- a/interfaces/kits/c/queue.h +++ b/interfaces/kits/c/queue.h @@ -12,6 +12,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +/** + * @file queue.h + * + * @brief Declares the queue interfaces in C. + * + * @since 10 + * @version 1.0 + */ #ifndef FFRT_API_C_QUEUE_H #define FFRT_API_C_QUEUE_H @@ -20,31 +29,151 @@ typedef enum { ffrt_queue_serial, ffrt_queue_max } ffrt_queue_type_t; typedef void* ffrt_queue_t; -// attr +/** + * @brief Initializes the queue attribute. + * + * @param attr Indicates a pointer to the queue attribute. + * @return Returns 0 if the queue attribute is initialized; + returns -1 otherwise. + * @since 10 + * @version 1.0 + */ FFRT_C_API int ffrt_queue_attr_init(ffrt_queue_attr_t* attr); + +/** + * @brief Destroys a queue attribute. + * + * @param attr Indicates a pointer to the queue attribute. + * @since 10 + * @version 1.0 + */ FFRT_C_API void ffrt_queue_attr_destroy(ffrt_queue_attr_t* attr); + +/** + * @brief Sets the QoS for a queue attribute. + * + * @param attr Indicates a pointer to the queue attribute. + * @param attr Indicates the QoS. + * @since 10 + * @version 1.0 + */ FFRT_C_API void ffrt_queue_attr_set_qos(ffrt_queue_attr_t* attr, ffrt_qos_t qos); + +/** + * @brief Obtains the QoS of a queue attribute. + * + * @param attr Indicates a pointer to the queue attribute. + * @return Returns the QoS. + * @since 10 + * @version 1.0 + */ FFRT_C_API ffrt_qos_t ffrt_queue_attr_get_qos(const ffrt_queue_attr_t* attr); + +/** + * @brief Set the serial queue task execution timeout. + * + * @param attr Serial Queue Property Pointer. + * @param timeout_us Serial queue task execution timeout. + * @since 10 + * @version 1.0 + */ FFRT_C_API void ffrt_queue_attr_set_timeout(ffrt_queue_attr_t* attr, uint64_t timeout_us); + +/** + * @brief Get the serial queue task execution timeout. + * + * @param attr Serial Queue Property Pointer. + * @return Returns the serial queue task execution timeout. + * @since 10 + * @version 1.0 + */ FFRT_C_API uint64_t ffrt_queue_attr_get_timeout(const ffrt_queue_attr_t* attr); + +/** + * @brief Set the serial queue timeout callback function. + * + * @param attr Serial Queue Property Pointer. + * @param f Serial queue timeout callback function. + * @since 10 + * @version 1.0 + */ FFRT_C_API void ffrt_queue_attr_set_callback(ffrt_queue_attr_t* attr, ffrt_function_header_t* f); + +/** + * @brief Get the serial queue task timeout callback function. + * + * @param attr Serial Queue Property Pointer. + * @return Returns the serial queue task timeout callback function. + * @since 10 + * @version 1.0 + */ FFRT_C_API ffrt_function_header_t* ffrt_queue_attr_get_callback(const ffrt_queue_attr_t* attr); -// create serial queue +/** + * @brief Creates a queue. + * + * @param type Indicates the queue type. + * @param name Indicates a pointer to the queue name. + * @param attr Indicates a pointer to the queue attribute. + * @return Returns a non-null queue handle if the queue is created; + returns a null pointer otherwise. + * @since 10 + * @version 1.0 + */ FFRT_C_API ffrt_queue_t ffrt_queue_create(ffrt_queue_type_t type, const char* name, const ffrt_queue_attr_t* attr); -// destroy serial queue +/** + * @brief Destroys a queue. + * + * @param queue Indicates a queue handle. + * @since 10 + * @version 1.0 + */ FFRT_C_API void ffrt_queue_destroy(ffrt_queue_t queue); -// submit to serial queue +/** + * @brief Submits a task to a queue. + * + * @param queue Indicates a queue handle. + * @param f Indicates a pointer to the task executor. + * @param attr Indicates a pointer to the task attribute. + * @since 10 + * @version 1.0 + */ FFRT_C_API void ffrt_queue_submit(ffrt_queue_t queue, ffrt_function_header_t* f, const ffrt_task_attr_t* attr); + +/** + * @brief Submits a task to the queue, and obtains a task handle. + * + * @param queue Indicates a queue handle. + * @param f Indicates a pointer to the task executor. + * @param attr Indicates a pointer to the task attribute. + * @return Returns a non-null task handle if the task is submitted; + returns a null pointer otherwise. + * @since 10 + * @version 1.0 + */ FFRT_C_API ffrt_task_handle_t ffrt_queue_submit_h( ffrt_queue_t queue, ffrt_function_header_t* f, const ffrt_task_attr_t* attr); -// wait serial task +/** + * @brief Waits until a task in the queue is complete. + * + * @param handle Indicates a task handle. + * @since 10 + * @version 1.0 + */ FFRT_C_API void ffrt_queue_wait(ffrt_task_handle_t handle); -// cancel serial task +/** + * @brief Cancels a task in the queue. + * + * @param handle Indicates a task handle. + * @return Returns 0 if the task is canceled; + returns -1 otherwise. + * @since 10 + * @version 1.0 + */ FFRT_C_API int ffrt_queue_cancel(ffrt_task_handle_t handle); #endif // FFRT_API_C_QUEUE_H \ No newline at end of file diff --git a/interfaces/kits/c/sleep.h b/interfaces/kits/c/sleep.h index e7db223..8486172 100644 --- a/interfaces/kits/c/sleep.h +++ b/interfaces/kits/c/sleep.h @@ -12,11 +12,35 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +/** + * @file sleep.h + * + * @brief Declares the sleep and yield interfaces in C. + * + * @since 10 + * @version 1.0 + */ #ifndef FFRT_API_C_SLEEP_H #define FFRT_API_C_SLEEP_H -#include #include "type_def.h" +/** + * @brief Suspends the calling thread for a given duration. + * + * @param usec Indicates the duration that the calling thread is suspended, in microseconds. + * @return Returns ffrt_thrd_success if the thread is suspended; + returns ffrt_thrd_error otherwise. + * @since 10 + * @version 1.0 + */ FFRT_C_API int ffrt_usleep(uint64_t usec); + +/** + * @brief Passes control to other tasks so that they can be executed. + * + * @since 10 + * @version 1.0 + */ FFRT_C_API void ffrt_yield(void); #endif diff --git a/interfaces/kits/c/task.h b/interfaces/kits/c/task.h index e383f06..d933f29 100644 --- a/interfaces/kits/c/task.h +++ b/interfaces/kits/c/task.h @@ -12,65 +12,180 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + + /** + * @file task.h + * + * @brief Declares the task interfaces in C. + * + * @since 10 + * @version 1.0 + */ #ifndef FFRT_API_C_TASK_H #define FFRT_API_C_TASK_H #include "type_def.h" -// attr +/** + * @brief Initializes a task attribute. + * + * @param attr Indicates a pointer to the task attribute. + * @return Returns 0 if the task attribute is initialized; + returns -1 otherwise. + * @since 10 + * @version 1.0 + */ FFRT_C_API int ffrt_task_attr_init(ffrt_task_attr_t* attr); + +/** + * @brief Sets a task name. + * + * @param attr Indicates a pointer to the task attribute. + * @param name Indicates a pointer to the task name. + * @since 10 + * @version 1.0 + */ FFRT_C_API void ffrt_task_attr_set_name(ffrt_task_attr_t* attr, const char* name); + +/** + * @brief Obtains a task name. + * + * @param attr Indicates a pointer to the task attribute. + * @return Returns a non-null pointer to the task name if the name is obtained; + returns a null pointer otherwise. + * @since 10 + * @version 1.0 + */ FFRT_C_API const char* ffrt_task_attr_get_name(const ffrt_task_attr_t* attr); + +/** + * @brief Destroys a task attribute. + * + * @param attr Indicates a pointer to the task attribute. + * @since 10 + * @version 1.0 + */ FFRT_C_API void ffrt_task_attr_destroy(ffrt_task_attr_t* attr); + +/** + * @brief Sets the QoS for a task attribute. + * + * @param attr Indicates a pointer to the task attribute. + * @param qos Indicates the QoS. + * @since 10 + * @version 1.0 + */ FFRT_C_API void ffrt_task_attr_set_qos(ffrt_task_attr_t* attr, ffrt_qos_t qos); + +/** + * @brief Obtains the QoS of a task attribute. + * + * @param attr Indicates a pointer to the task attribute. + * @return Returns the QoS, which is ffrt_qos_default by default. + * @since 10 + * @version 1.0 + */ FFRT_C_API ffrt_qos_t ffrt_task_attr_get_qos(const ffrt_task_attr_t* attr); + +/** + * @brief Sets the task delay time. + * + * @param attr Indicates a pointer to the task attribute. + * @param delay_us Indicates the delay time, in microseconds. + * @since 10 + * @version 1.0 + */ FFRT_C_API void ffrt_task_attr_set_delay(ffrt_task_attr_t* attr, uint64_t delay_us); + +/** + * @brief Obtains the task delay time. + * + * @param attr Indicates a pointer to the task attribute. + * @return Returns the delay time. + * @since 10 + * @version 1.0 + */ FFRT_C_API uint64_t ffrt_task_attr_get_delay(const ffrt_task_attr_t* attr); +/** + * @brief Updates the QoS of this task. + * + * @param qos Indicates the new QoS. + * @return Returns 0 if the QoS is updated; + returns -1 otherwise. + * @since 10 + * @version 1.0 + */ FFRT_C_API int ffrt_this_task_update_qos(ffrt_qos_t task_qos); +/** + * @brief Obtains the ID of this task. + * + * @return Returns the task ID. + * @since 10 + * @version 1.0 + */ FFRT_C_API uint64_t ffrt_this_task_get_id(void); -FFRT_C_API void ffrt_task_attr_set_coroutine_type(ffrt_task_attr_t* attr, ffrt_coroutine_t coroutine_type); -FFRT_C_API ffrt_coroutine_t ffrt_task_attr_get_coroutine_type(const ffrt_task_attr_t* attr); - -// deps -#define ffrt_deps_define(name, dep1, ...) const ffrt_dependence_t __v_##name[] = {dep1, ##__VA_ARGS__}; \ - ffrt_deps_t name = {sizeof(__v_##name) / sizeof(ffrt_dependence_t), __v_##name} - -// submit +/** + * @brief Applies for memory for the function execution structure. + * + * @param kind Indicates the type of the function execution structure, which can be common or queue. + * @return Returns a non-null pointer if the memory is allocated; + returns a null pointer otherwise. + * @since 10 + * @version 1.0 + */ FFRT_C_API void *ffrt_alloc_auto_managed_function_storage_base(ffrt_function_kind_t kind); + +/** + * @brief Submits a task. + * + * @param f Indicates a pointer to the task executor. + * @param in_deps Indicates a pointer to the input dependencies. + * @param out_deps Indicates a pointer to the output dependencies. + * @param attr Indicates a pointer to the task attribute. + * @since 10 + * @version 1.0 + */ FFRT_C_API void ffrt_submit_base(ffrt_function_header_t* f, const ffrt_deps_t* in_deps, const ffrt_deps_t* out_deps, const ffrt_task_attr_t* attr); + +/** + * @brief Submits a task, and obtains a task handle. + * + * @param f Indicates a pointer to the task executor. + * @param in_deps Indicates a pointer to the input dependencies. + * @param out_deps Indicates a pointer to the output dependencies. + * @param attr Indicates a pointer to the task attribute. + * @return Returns a non-null task handle if the task is submitted; + returns a null pointer otherwise. + * @since 10 + * @version 1.0 + */ FFRT_C_API ffrt_task_handle_t ffrt_submit_h_base(ffrt_function_header_t* f, const ffrt_deps_t* in_deps, const ffrt_deps_t* out_deps, const ffrt_task_attr_t* attr); -#ifdef USE_STACKLESS_COROUTINE -FFRT_C_API void ffrt_submit_coroutine(void* co, ffrt_coroutine_ptr_t exec, - ffrt_function_ptr_t destroy, const ffrt_deps_t* in_deps, const ffrt_deps_t* out_deps, const ffrt_task_attr_t* attr); -FFRT_C_API ffrt_task_handle_t ffrt_submit_h_coroutine(void* co, ffrt_coroutine_ptr_t exec, - ffrt_function_ptr_t destroy, const ffrt_deps_t* in_deps, const ffrt_deps_t* out_deps, const ffrt_task_attr_t* attr); - -// get -FFRT_C_API void *ffrt_task_get(); - -// waker -FFRT_C_API void ffrt_wake_by_handle(void* waker, ffrt_function_ptr_t exec, - ffrt_function_ptr_t destroy, ffrt_task_handle_t handle); -FFRT_C_API void ffrt_set_wake_flag(bool flag); -FFRT_C_API void ffrt_wake_coroutine(void *task); -#endif - +/** + * @brief Destroys a task handle. + * + * @param handle Indicates a task handle. + * @since 10 + * @version 1.0 + */ FFRT_C_API void ffrt_task_handle_destroy(ffrt_task_handle_t handle); -FFRT_C_API void ffrt_executor_task_register_func(ffrt_executor_task_func func, const char* name); -FFRT_C_API void ffrt_executor_task_submit(ffrt_executor_task_t *task, const ffrt_task_attr_t *attr); -FFRT_C_API int ffrt_executor_task_cancel(ffrt_executor_task_t *task, const ffrt_qos_t qos); - -// skip task -FFRT_C_API int ffrt_skip(ffrt_task_handle_t handle); - -// wait +/** + * @brief Waits until the dependent tasks are complete. + * + * @param deps Indicates a pointer to the dependent tasks. + * @since 10 + * @version 1.0 + */ FFRT_C_API void ffrt_wait_deps(const ffrt_deps_t* deps); -FFRT_C_API void ffrt_wait(void); -// config -FFRT_C_API int ffrt_set_cgroup_attr(ffrt_qos_t qos, ffrt_os_sched_attr* attr); +/** + * @brief Waits until all submitted tasks are complete. + * + * @since 10 + * @version 1.0 + */ +FFRT_C_API void ffrt_wait(void); #endif diff --git a/interfaces/kits/c/type_def.h b/interfaces/kits/c/type_def.h index f2d3b09..b4661d4 100644 --- a/interfaces/kits/c/type_def.h +++ b/interfaces/kits/c/type_def.h @@ -12,6 +12,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + + /** + * @file type_def.h + * + * @brief Declares common types. + * + * @since 10 + * @version 1.0 + */ #ifndef FFRT_API_C_TYPE_DEF_H #define FFRT_API_C_TYPE_DEF_H #include @@ -23,62 +32,62 @@ #define FFRT_C_API #endif -typedef enum { - ffrt_coroutine_stackless, - ffrt_coroutine_stackfull, -} ffrt_coroutine_t; - -typedef enum { - ffrt_ready = 1, - ffrt_blocked = 3, - ffrt_exited = 4, -} ffrt_task_status_t; - -typedef enum { - ffrt_coroutine_pending = 0, - ffrt_coroutine_ready = 1, -} ffrt_coroutine_ret_t; - - -typedef void(*ffrt_function_ptr_t)(void*); -typedef ffrt_coroutine_ret_t(*ffrt_coroutine_ptr_t)(void*); - +/** + * @brief Enumerates the task QoS types. + * + */ typedef enum { ffrt_qos_inherit = -1, + /** Background task. */ ffrt_qos_background, + /** Real-time tool. */ ffrt_qos_utility, + /** Default type. */ ffrt_qos_default, + /** User initiated. */ ffrt_qos_user_initiated, - ffrt_qos_deadline_request, - ffrt_qos_user_interactive, - ffrt_qos_max = ffrt_qos_user_interactive, } ffrt_qos_default_t; typedef int ffrt_qos_t; -typedef enum { - ffrt_stack_protect_weak, - ffrt_stack_protect_strong -} ffrt_stack_protect_t; - typedef void(*ffrt_function_t)(void*); +/** + * @brief Defines a task executor. + * + */ typedef struct { + /** Function used to execute a task. */ ffrt_function_t exec; + /** Function used to destroy a task. */ ffrt_function_t destroy; uint64_t reserve[2]; } ffrt_function_header_t; +/** + * @brief Defines the storage size of multiple types of structs. + * + */ typedef enum { + /** Task attribute storage size. */ ffrt_task_attr_storage_size = 128, + /** Task executor storage size. */ ffrt_auto_managed_function_storage_size = 64 + sizeof(ffrt_function_header_t), + /* Mutex storage size. */ ffrt_mutex_storage_size = 64, + /** Condition variable storage size. */ ffrt_cond_storage_size = 64, - ffrt_thread_attr_storage_size = 64, + /** Queue storage size. */ ffrt_queue_attr_storage_size = 128, } ffrt_storage_size_t; +/** + * @brief Enumerates the task types. + * + */ typedef enum { + /** General task. */ ffrt_function_kind_general, + /** Queue task. */ ffrt_function_kind_queue } ffrt_function_kind_t; @@ -92,8 +101,14 @@ typedef struct { const void* ptr; } ffrt_dependence_t; +/** + * @brief Defines the dependency struct. + * + */ typedef struct { + /** Number of dependencies. */ uint32_t len; + /** Dependent data. */ const ffrt_dependence_t* items; } ffrt_deps_t; @@ -124,10 +139,6 @@ typedef struct { long storage; } ffrt_mutexattr_t; -typedef struct { - uint32_t storage[(ffrt_thread_attr_storage_size + sizeof(uint32_t) - 1) / sizeof(uint32_t)]; -} ffrt_thread_attr_t; - typedef struct { uint32_t storage[(ffrt_mutex_storage_size + sizeof(uint32_t) - 1) / sizeof(uint32_t)]; } ffrt_mutex_t; @@ -136,42 +147,6 @@ typedef struct { uint32_t storage[(ffrt_cond_storage_size + sizeof(uint32_t) - 1) / sizeof(uint32_t)]; } ffrt_cond_t; -#define MAX_CPUMAP_LENGTH 100 // this is in c and code style -typedef struct { - int shares; - int latency_nice; - int uclamp_min; - int uclamp_max; - int vip_prio; - char cpumap[MAX_CPUMAP_LENGTH]; -} ffrt_os_sched_attr; - -typedef void* ffrt_thread_t; - -typedef void* ffrt_interval_t; - -typedef enum { - ffrt_sys_event_type_read, -} ffrt_sys_event_type_t; - -typedef enum { - ffrt_sys_event_status_no_timeout, - ffrt_sys_event_status_timeout -} ffrt_sys_event_status_t; - -typedef void* ffrt_sys_event_handle_t; - -typedef void* ffrt_config_t; - -// 该任务仅在libuv中提交 -typedef struct ffrt_executor_task { - uintptr_t reserved[2]; - uintptr_t type; // 0: TaskCtx, 1: rust task, User Space Address: libuv work - void* wq[2]; -} ffrt_executor_task_t; - -typedef void (*ffrt_executor_task_func)(ffrt_executor_task_t* data); - #ifdef __cplusplus namespace ffrt { enum qos_default { @@ -180,16 +155,8 @@ enum qos_default { qos_utility = ffrt_qos_utility, qos_default = ffrt_qos_default, qos_user_initiated = ffrt_qos_user_initiated, - qos_deadline_request = ffrt_qos_deadline_request, - qos_user_interactive = ffrt_qos_user_interactive, - qos_max = ffrt_qos_max, }; using qos = int; - -enum class stack_protect { - weak = ffrt_stack_protect_weak, - strong = ffrt_stack_protect_strong, -}; } #endif #endif diff --git a/interfaces/kits/cpp/condition_variable.h b/interfaces/kits/cpp/condition_variable.h index 8bd912b..d7e6877 100644 --- a/interfaces/kits/cpp/condition_variable.h +++ b/interfaces/kits/cpp/condition_variable.h @@ -12,6 +12,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +/** + * @file condition_variable.h + * + * @brief Declares the condition variable interfaces in C++. + * + * @since 10 + * @version 1.0 + */ #ifndef FFRT_API_CPP_CONDITION_VARIABLE_H #define FFRT_API_CPP_CONDITION_VARIABLE_H #include diff --git a/interfaces/kits/cpp/mutex.h b/interfaces/kits/cpp/mutex.h index 2adddcf..d0df3c7 100644 --- a/interfaces/kits/cpp/mutex.h +++ b/interfaces/kits/cpp/mutex.h @@ -12,6 +12,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + + /** + * @file mutex.h + * + * @brief Declares the mutex interfaces in C++. + * + * @since 10 + * @version 1.0 + */ #ifndef FFRT_API_CPP_MUTEX_H #define FFRT_API_CPP_MUTEX_H #include "c/mutex.h" diff --git a/interfaces/kits/cpp/queue.h b/interfaces/kits/cpp/queue.h index 156fce9..c6c7973 100644 --- a/interfaces/kits/cpp/queue.h +++ b/interfaces/kits/cpp/queue.h @@ -12,6 +12,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +/** + * @file queue.h + * + * @brief Declares the queue interfaces in C++. + * + * @since 10 + * @version 1.0 + */ #ifndef FFRT_API_CPP_QUEUE_H #define FFRT_API_CPP_QUEUE_H @@ -34,7 +43,13 @@ public: queue_attr(const queue_attr&) = delete; queue_attr& operator=(const queue_attr&) = delete; - // set qos + /** + * @brief Sets the QoS for this queue attribute. + * + * @param attr Indicates the QoS. + * @since 10 + * @version 1.0 + */ inline queue_attr& qos(qos qos_) { ffrt_queue_attr_set_qos(this, qos_); @@ -89,57 +104,137 @@ public: queue(queue const&) = delete; void operator=(queue const&) = delete; - // submit + /** + * @brief Submits a task to this queue. + * + * @param func Indicates a task executor function closure. + * @since 10 + * @version 1.0 + */ inline void submit(std::function& func) { ffrt_queue_submit(queue_handle, create_function_wrapper(func, ffrt_function_kind_queue), nullptr); } + /** + * @brief Submits a task with a specified attribute to this queue. + * + * @param func Indicates a task executor function closure. + * @param attr Indicates a task attribute. + * @since 10 + * @version 1.0 + */ inline void submit(std::function& func, const task_attr& attr) { ffrt_queue_submit(queue_handle, create_function_wrapper(func, ffrt_function_kind_queue), &attr); } + /** + * @brief Submits a task to this queue. + * + * @param func Indicates a task executor function closure. + * @since 10 + * @version 1.0 + */ inline void submit(std::function&& func) { ffrt_queue_submit(queue_handle, create_function_wrapper(std::move(func), ffrt_function_kind_queue), nullptr); } + /** + * @brief Submits a task with a specified attribute to this queue. + * + * @param func Indicates a task executor function closure. + * @param attr Indicates a task attribute. + * @since 10 + * @version 1.0 + */ inline void submit(std::function&& func, const task_attr& attr) { ffrt_queue_submit(queue_handle, create_function_wrapper(std::move(func), ffrt_function_kind_queue), &attr); } - // submit_h + /** + * @brief Submits a task to this queue, and obtains a task handle. + * + * @param func Indicates a task executor function closure. + * @return Returns a non-null task handle if the task is submitted; + returns a null pointer otherwise. + * @since 10 + * @version 1.0 + */ inline task_handle submit_h(std::function& func) { return ffrt_queue_submit_h(queue_handle, create_function_wrapper(func, ffrt_function_kind_queue), nullptr); } + /** + * @brief Submits a task with a specified attribute to this queue, and obtains a task handle. + * + * @param func Indicates a task executor function closure. + * @param attr Indicates a task attribute. + * @return Returns a non-null task handle if the task is submitted; + returns a null pointer otherwise. + * @since 10 + * @version 1.0 + */ inline task_handle submit_h(std::function& func, const task_attr& attr) { return ffrt_queue_submit_h(queue_handle, create_function_wrapper(func, ffrt_function_kind_queue), &attr); } + /** + * @brief Submits a task to this queue, and obtains a task handle. + * + * @param func Indicates a task executor function closure. + * @return Returns a non-null task handle if the task is submitted; + returns a null pointer otherwise. + * @since 10 + * @version 1.0 + */ inline task_handle submit_h(std::function&& func) { return ffrt_queue_submit_h( queue_handle, create_function_wrapper(std::move(func), ffrt_function_kind_queue), nullptr); } + /** + * @brief Submits a task with a specified attribute to this queue, and obtains a task handle. + * + * @param func Indicates a task executor function closure. + * @param attr Indicates a task attribute. + * @return Returns a non-null task handle if the task is submitted; + returns a null pointer otherwise. + * @since 10 + * @version 1.0 + */ inline task_handle submit_h(std::function&& func, const task_attr& attr) { return ffrt_queue_submit_h( queue_handle, create_function_wrapper(std::move(func), ffrt_function_kind_queue), &attr); } - // cancel + /** + * @brief Cancels a task. + * + * @param handle Indicates a task handle. + * @return Returns 0 if the task is canceled; + returns -1 otherwise. + * @since 10 + * @version 1.0 + */ inline int cancel(task_handle& handle) { return ffrt_queue_cancel(handle); } - // wait + /** + * @brief Waits until a task is complete. + * + * @param handle Indicates a task handle. + * @since 10 + * @version 1.0 + */ inline void wait(task_handle& handle) { return ffrt_queue_wait(handle); diff --git a/interfaces/kits/cpp/sleep.h b/interfaces/kits/cpp/sleep.h index a725b50..a082e24 100644 --- a/interfaces/kits/cpp/sleep.h +++ b/interfaces/kits/cpp/sleep.h @@ -12,6 +12,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +/** + * @file sleep.h + * + * @brief Declares the sleep and yield interfaces in C++. + * + * @since 10 + * @version 1.0 + */ #ifndef FFRT_API_CPP_SLEEP_H #define FFRT_API_CPP_SLEEP_H #include diff --git a/interfaces/kits/cpp/task.h b/interfaces/kits/cpp/task.h index 1a1872b..f90f117 100644 --- a/interfaces/kits/cpp/task.h +++ b/interfaces/kits/cpp/task.h @@ -12,6 +12,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + + /** + * @file task.h + * + * @brief Declares the task interfaces in C++. + * + * @since 10 + * @version 1.0 + */ #ifndef FFRT_API_CPP_TASK_H #define FFRT_API_CPP_TASK_H #include @@ -37,8 +46,12 @@ public: task_attr& operator=(const task_attr&) = delete; /** - @brief set task name - */ + * @brief Sets a task name. + * + * @param name Indicates a pointer to the task name. + * @since 10 + * @version 1.0 + */ inline task_attr& name(const char* name) { ffrt_task_attr_set_name(this, name); @@ -46,16 +59,24 @@ public: } /** - @brief get task name - */ + * @brief Obtains the task name. + * + * @return Returns a pointer to the task name. + * @since 10 + * @version 1.0 + */ inline const char* name() const { return ffrt_task_attr_get_name(this); } /** - @brief set qos - */ + * @brief Sets the QoS for this task. + * + * @param qos Indicates the QoS. + * @since 10 + * @version 1.0 + */ inline task_attr& qos(qos qos_) { ffrt_task_attr_set_qos(this, qos_); @@ -63,16 +84,24 @@ public: } /** - @brief get qos - */ + * @brief Obtains the QoS of this task. + * + * @return Returns the QoS. + * @since 10 + * @version 1.0 + */ inline int qos() const { return ffrt_task_attr_get_qos(this); } /** - @brief set task delay - */ + * @brief Sets the delay time for this task. + * + * @param delay_us Indicates the delay time, in microseconds. + * @since 10 + * @version 1.0 + */ inline task_attr& delay(uint64_t delay_us) { ffrt_task_attr_set_delay(this, delay_us); @@ -80,29 +109,16 @@ public: } /** - @brief get task name - */ + * @brief Obtains the delay time of this task. + * + * @return Returns the delay time. + * @since 10 + * @version 1.0 + */ inline uint64_t delay() const { return ffrt_task_attr_get_delay(this); } - - /** - @brief set task coroutine type - */ - inline task_attr& coroutine_type(ffrt_coroutine_t coroutine_type) - { - ffrt_task_attr_set_coroutine_type(this, coroutine_type); - return *this; - } - - /** - @brief get task coroutine type - */ - inline ffrt_coroutine_t coroutine_type() const - { - return ffrt_task_attr_get_coroutine_type(this); - } }; @@ -199,19 +215,40 @@ inline ffrt_function_header_t* create_function_wrapper(T&& func, } /** -@brief submit a task with the given func and its dependency -*/ + * @brief Submits a task without input and output dependencies. + * + * @param func Indicates a task executor function closure. + * @since 10 + * @version 1.0 + */ static inline void submit(std::function&& func) { return ffrt_submit_base(create_function_wrapper(std::move(func)), nullptr, nullptr, nullptr); } +/** + * @brief Submits a task with input dependencies only. + * + * @param func Indicates a task executor function closure. + * @param in_deps Indicates a pointer to the input dependencies. + * @since 10 + * @version 1.0 + */ static inline void submit(std::function&& func, std::initializer_list in_deps) { ffrt_deps_t in {static_cast(in_deps.size()), in_deps.begin()}; return ffrt_submit_base(create_function_wrapper(std::move(func)), &in, nullptr, nullptr); } +/** + * @brief Submits a task with input and output dependencies. + * + * @param func Indicates a task executor function closure. + * @param in_deps Indicates a pointer to the input dependencies. + * @param out_deps Indicates a pointer to the output dependencies. + * @since 10 + * @version 1.0 + */ static inline void submit(std::function&& func, std::initializer_list in_deps, std::initializer_list out_deps) { @@ -220,6 +257,16 @@ static inline void submit(std::function&& func, std::initializer_list&& func, std::initializer_list in_deps, std::initializer_list out_deps, const task_attr& attr) { @@ -228,12 +275,29 @@ static inline void submit(std::function&& func, std::initializer_list&& func, const std::vector& in_deps) { ffrt_deps_t in {static_cast(in_deps.size()), in_deps.data()}; return ffrt_submit_base(create_function_wrapper(std::move(func)), &in, nullptr, nullptr); } +/** + * @brief Submits a task with input and output dependencies. + * + * @param func Indicates a task executor function closure. + * @param in_deps Indicates a pointer to the input dependencies. + * @param out_deps Indicates a pointer to the output dependencies. + * @since 10 + * @version 1.0 + */ static inline void submit(std::function&& func, const std::vector& in_deps, const std::vector& out_deps) { @@ -242,6 +306,16 @@ static inline void submit(std::function&& func, const std::vector&& func, const std::vector& in_deps, const std::vector& out_deps, const task_attr& attr) { @@ -250,17 +324,41 @@ static inline void submit(std::function&& func, const std::vector& func) { return ffrt_submit_base(create_function_wrapper(func), nullptr, nullptr, nullptr); } +/** + * @brief Submits a task with input dependencies only. + * + * @param func Indicates a task executor function closure. + * @param in_deps Indicates a pointer to the input dependencies. + * @since 10 + * @version 1.0 + */ static inline void submit(const std::function& func, std::initializer_list in_deps) { ffrt_deps_t in {static_cast(in_deps.size()), in_deps.begin()}; return ffrt_submit_base(create_function_wrapper(func), &in, nullptr, nullptr); } +/** + * @brief Submits a task with input and output dependencies. + * + * @param func Indicates a task executor function closure. + * @param in_deps Indicates a pointer to the input dependencies. + * @param out_deps Indicates a pointer to the output dependencies. + * @since 10 + * @version 1.0 + */ static inline void submit(const std::function& func, std::initializer_list in_deps, std::initializer_list out_deps) { @@ -269,6 +367,16 @@ static inline void submit(const std::function& func, std::initializer_li return ffrt_submit_base(create_function_wrapper(func), &in, &out, nullptr); } +/** + * @brief Submits a task with a specified attribute and input and output dependencies. + * + * @param func Indicates a task executor function closure. + * @param in_deps Indicates a pointer to the input dependencies. + * @param out_deps Indicates a pointer to the output dependencies. + * @param attr Indicates a task attribute. + * @since 10 + * @version 1.0 + */ static inline void submit(const std::function& func, std::initializer_list in_deps, std::initializer_list out_deps, const task_attr& attr) { @@ -277,12 +385,29 @@ static inline void submit(const std::function& func, std::initializer_li return ffrt_submit_base(create_function_wrapper(func), &in, &out, &attr); } +/** + * @brief Submits a task with input dependencies only. + * + * @param func Indicates a task executor function closure. + * @param in_deps Indicates a pointer to the input dependencies. + * @since 10 + * @version 1.0 + */ static inline void submit(const std::function& func, const std::vector& in_deps) { ffrt_deps_t in {static_cast(in_deps.size()), in_deps.data()}; return ffrt_submit_base(create_function_wrapper(func), &in, nullptr, nullptr); } +/** + * @brief Submits a task with input and output dependencies. + * + * @param func Indicates a task executor function closure. + * @param in_deps Indicates a pointer to the input dependencies. + * @param out_deps Indicates a pointer to the output dependencies. + * @since 10 + * @version 1.0 + */ static inline void submit(const std::function& func, const std::vector& in_deps, const std::vector& out_deps) { @@ -291,6 +416,16 @@ static inline void submit(const std::function& func, const std::vector& func, const std::vector& in_deps, const std::vector& out_deps, const task_attr& attr) { @@ -300,19 +435,46 @@ static inline void submit(const std::function& func, const std::vector&& func) { return ffrt_submit_h_base(create_function_wrapper(std::move(func)), nullptr, nullptr, nullptr); } +/** + * @brief Submits a task with input dependencies only, and obtains a task handle. + * + * @param func Indicates a task executor function closure. + * @param in_deps Indicates a pointer to the input dependencies. + * @return Returns a non-null task handle if the task is submitted; + returns a null pointer otherwise. + * @since 10 + * @version 1.0 + */ static inline task_handle submit_h(std::function&& func, std::initializer_list in_deps) { ffrt_deps_t in {static_cast(in_deps.size()), in_deps.begin()}; return ffrt_submit_h_base(create_function_wrapper(std::move(func)), &in, nullptr, nullptr); } +/** + * @brief Submits a task with input and output dependencies, and obtains a task handle. + * + * @param func Indicates a task executor function closure. + * @param in_deps Indicates a pointer to the input dependencies. + * @param out_deps Indicates a pointer to the output dependencies. + * @return Returns a non-null task handle if the task is submitted; + returns a null pointer otherwise. + * @since 10 + * @version 1.0 + */ static inline task_handle submit_h(std::function&& func, std::initializer_list in_deps, std::initializer_list out_deps) { @@ -321,6 +483,18 @@ static inline task_handle submit_h(std::function&& func, std::initialize return ffrt_submit_h_base(create_function_wrapper(std::move(func)), &in, &out, nullptr); } +/** + * @brief Submits a task with a specified attribute and input and output dependencies, and obtains a task handle. + * + * @param func Indicates a task executor function closure. + * @param in_deps Indicates a pointer to the input dependencies. + * @param out_deps Indicates a pointer to the output dependencies. + * @param attr Indicates a task attribute. + * @return Returns a non-null task handle if the task is submitted; + returns a null pointer otherwise. + * @since 10 + * @version 1.0 + */ static inline task_handle submit_h(std::function&& func, std::initializer_list in_deps, std::initializer_list out_deps, const task_attr& attr) { @@ -329,12 +503,33 @@ static inline task_handle submit_h(std::function&& func, std::initialize return ffrt_submit_h_base(create_function_wrapper(std::move(func)), &in, &out, &attr); } +/** + * @brief Submits a task with input dependencies only, and obtains a task handle. + * + * @param func Indicates a task executor function closure. + * @param in_deps Indicates a pointer to the input dependencies. + * @return Returns a non-null task handle if the task is submitted; + returns a null pointer otherwise. + * @since 10 + * @version 1.0 + */ static inline task_handle submit_h(std::function&& func, const std::vector& in_deps) { ffrt_deps_t in {static_cast(in_deps.size()), in_deps.data()}; return ffrt_submit_h_base(create_function_wrapper(std::move(func)), &in, nullptr, nullptr); } +/** + * @brief Submits a task with input and output dependencies, and obtains a task handle. + * + * @param func Indicates a task executor function closure. + * @param in_deps Indicates a pointer to the input dependencies. + * @param out_deps Indicates a pointer to the output dependencies. + * @return Returns a non-null task handle if the task is submitted; + returns a null pointer otherwise. + * @since 10 + * @version 1.0 + */ static inline task_handle submit_h(std::function&& func, const std::vector& in_deps, const std::vector& out_deps) { @@ -343,6 +538,18 @@ static inline task_handle submit_h(std::function&& func, const std::vect return ffrt_submit_h_base(create_function_wrapper(std::move(func)), &in, &out, nullptr); } +/** + * @brief Submits a task with a specified attribute and input and output dependencies, and obtains a task handle. + * + * @param func Indicates a task executor function closure. + * @param in_deps Indicates a pointer to the input dependencies. + * @param out_deps Indicates a pointer to the output dependencies. + * @param attr Indicates a task attribute. + * @return Returns a non-null task handle if the task is submitted; + returns a null pointer otherwise. + * @since 10 + * @version 1.0 + */ static inline task_handle submit_h(std::function&& func, const std::vector& in_deps, const std::vector& out_deps, const task_attr& attr) { @@ -351,17 +558,47 @@ static inline task_handle submit_h(std::function&& func, const std::vect return ffrt_submit_h_base(create_function_wrapper(std::move(func)), &in, &out, &attr); } +/** + * @brief Submits a task without input and output dependencies, and obtains a task handle. + * + * @param func Indicates a task executor function closure. + * @return Returns a non-null task handle if the task is submitted; + returns a null pointer otherwise. + * @since 10 + * @version 1.0 + */ static inline task_handle submit_h(const std::function& func) { return ffrt_submit_h_base(create_function_wrapper(func), nullptr, nullptr, nullptr); } +/** + * @brief Submits a task with input dependencies only, and obtains a task handle. + * + * @param func Indicates a task executor function closure. + * @param in_deps Indicates a pointer to the input dependencies. + * @return Returns a non-null task handle if the task is submitted; + returns a null pointer otherwise. + * @since 10 + * @version 1.0 + */ static inline task_handle submit_h(const std::function& func, std::initializer_list in_deps) { ffrt_deps_t in {static_cast(in_deps.size()), in_deps.begin()}; return ffrt_submit_h_base(create_function_wrapper(func), &in, nullptr, nullptr); } +/** + * @brief Submits a task with input and output dependencies, and obtains a task handle. + * + * @param func Indicates a task executor function closure. + * @param in_deps Indicates a pointer to the input dependencies. + * @param out_deps Indicates a pointer to the output dependencies. + * @return Returns a non-null task handle if the task is submitted; + returns a null pointer otherwise. + * @since 10 + * @version 1.0 + */ static inline task_handle submit_h(const std::function& func, std::initializer_list in_deps, std::initializer_list out_deps) { @@ -370,6 +607,18 @@ static inline task_handle submit_h(const std::function& func, std::initi return ffrt_submit_h_base(create_function_wrapper(func), &in, &out, nullptr); } +/** + * @brief Submits a task with a specified attribute and input and output dependencies, and obtains a task handle. + * + * @param func Indicates a task executor function closure. + * @param in_deps Indicates a pointer to the input dependencies. + * @param out_deps Indicates a pointer to the output dependencies. + * @param attr Indicates a task attribute. + * @return Returns a non-null task handle if the task is submitted; + returns a null pointer otherwise. + * @since 10 + * @version 1.0 + */ static inline task_handle submit_h(const std::function& func, std::initializer_list in_deps, std::initializer_list out_deps, const task_attr& attr) { @@ -378,12 +627,33 @@ static inline task_handle submit_h(const std::function& func, std::initi return ffrt_submit_h_base(create_function_wrapper(func), &in, &out, &attr); } +/** + * @brief Submits a task with input dependencies only, and obtains a task handle. + * + * @param func Indicates a task executor function closure. + * @param in_deps Indicates a pointer to the input dependencies. + * @return Returns a non-null task handle if the task is submitted; + returns a null pointer otherwise. + * @since 10 + * @version 1.0 + */ static inline task_handle submit_h(const std::function& func, const std::vector& in_deps) { ffrt_deps_t in {static_cast(in_deps.size()), in_deps.data()}; return ffrt_submit_h_base(create_function_wrapper(func), &in, nullptr, nullptr); } +/** + * @brief Submits a task with input and output dependencies, and obtains a task handle. + * + * @param func Indicates a task executor function closure. + * @param in_deps Indicates a pointer to the input dependencies. + * @param out_deps Indicates a pointer to the output dependencies. + * @return Returns a non-null task handle if the task is submitted; + returns a null pointer otherwise. + * @since 10 + * @version 1.0 + */ static inline task_handle submit_h(const std::function& func, const std::vector& in_deps, const std::vector& out_deps) { @@ -392,6 +662,18 @@ static inline task_handle submit_h(const std::function& func, const std: return ffrt_submit_h_base(create_function_wrapper(func), &in, &out, nullptr); } +/** + * @brief Submits a task with a specified attribute and input and output dependencies, and obtains a task handle. + * + * @param func Indicates a task executor function closure. + * @param in_deps Indicates a pointer to the input dependencies. + * @param out_deps Indicates a pointer to the output dependencies. + * @param attr Indicates a task attribute. + * @return Returns a non-null task handle if the task is submitted; + returns a null pointer otherwise. + * @since 10 + * @version 1.0 + */ static inline task_handle submit_h(const std::function& func, const std::vector& in_deps, const std::vector& out_deps, const task_attr& attr) { @@ -400,42 +682,43 @@ static inline task_handle submit_h(const std::function& func, const std: return ffrt_submit_h_base(create_function_wrapper(func), &in, &out, &attr); } -static inline int skip(task_handle &handle) -{ - return ffrt_skip(handle); -} - /** -@brief wait until all child tasks of current task to be done -*/ + * @brief Waits until all submitted tasks are complete. + * + * @since 10 + * @version 1.0 + */ static inline void wait() { ffrt_wait(); } /** -@brief wait until specified data be produced -*/ + * @brief Waits until dependent tasks are complete. + * + * @param deps Indicates a pointer to the dependent tasks. + * @since 10 + * @version 1.0 + */ static inline void wait(std::initializer_list deps) { ffrt_deps_t d {static_cast(deps.size()), deps.begin()}; ffrt_wait_deps(&d); } +/** + * @brief Waits until dependent tasks are complete. + * + * @param deps Indicates a pointer to the dependent tasks. + * @since 10 + * @version 1.0 + */ static inline void wait(const std::vector& deps) { ffrt_deps_t d {static_cast(deps.size()), deps.data()}; ffrt_wait_deps(&d); } -/** -@brief config -*/ -static inline int set_cgroup_attr(qos qos_, ffrt_os_sched_attr *attr) -{ - return ffrt_set_cgroup_attr(qos_, attr); -} - void sync_io(int fd); void set_trace_tag(const std::string& name); @@ -448,6 +731,13 @@ static inline int update_qos(qos qos_) return ffrt_this_task_update_qos(qos_); } +/** + * @brief Obtains the ID of this task. + * + * @return Returns the task ID. + * @since 10 + * @version 1.0 + */ static inline uint64_t get_id() { return ffrt_this_task_get_id(); diff --git a/interfaces/kits/ffrt.h b/interfaces/kits/ffrt.h index e20832e..15dba43 100644 --- a/interfaces/kits/ffrt.h +++ b/interfaces/kits/ffrt.h @@ -19,15 +19,12 @@ #include "cpp/mutex.h" #include "cpp/condition_variable.h" #include "cpp/sleep.h" -#include "cpp/thread.h" -#include "cpp/future.h" #include "cpp/queue.h" #else #include "c/task.h" #include "c/mutex.h" #include "c/condition_variable.h" #include "c/sleep.h" -#include "c/thread.h" #include "c/queue.h" #endif #endif diff --git a/src/core/task.cpp b/src/core/task.cpp index 3b04dca..9a83f84 100644 --- a/src/core/task.cpp +++ b/src/core/task.cpp @@ -17,7 +17,7 @@ #include #include -#include "ffrt.h" +#include "ffrt_inner.h" #include "cpp/task.h" #include "internal_inc/osal.h" @@ -174,117 +174,6 @@ uint64_t ffrt_task_attr_get_delay(const ffrt_task_attr_t *attr) return (reinterpret_cast(p))->delay_; } -API_ATTRIBUTE((visibility("default"))) -void ffrt_task_attr_set_coroutine_type(ffrt_task_attr_t* attr, ffrt_coroutine_t coroutine_type) -{ - if (!attr) { - FFRT_LOGE("attr should be a valid address"); - return; - } - ((ffrt::task_attr_private*)attr)->coroutine_type_ = coroutine_type; -} - -API_ATTRIBUTE((visibility("default"))) -ffrt_coroutine_t ffrt_task_attr_get_coroutine_type(const ffrt_task_attr_t* attr) -{ - if (!attr) { - FFRT_LOGE("attr should be a valid address"); - return ffrt_coroutine_stackfull; - } - return ((ffrt::task_attr_private*)attr)->coroutine_type_; -} - -#ifdef USE_STACKLESS_COROUTINE -typedef struct { - ffrt_function_header_t header; - ffrt_coroutine_ptr_t func; - ffrt_function_ptr_t destroy; - void* arg; -} ffrt_function_coroutine_t; - -static ffrt_coroutine_ret_t ffrt_exec_function_coroutine_wrapper(void* t) -{ - ffrt_function_coroutine_t* f = (ffrt_function_coroutine_t*)t; - return f->func(f->arg); -} - -static void ffrt_destory_function_coroutine_wrapper(void* t) -{ - ffrt_function_coroutine_t* f = (ffrt_function_coroutine_t*)t; - f->destroy(f->arg); -} - -static inline ffrt_function_header_t* ffrt_create_function_coroutine_wrapper(void* co, - ffrt_coroutine_ptr_t exec, ffrt_function_ptr_t destroy) -{ - static_assert(sizeof(ffrt_function_coroutine_t) <= ffrt_auto_managed_function_storage_size, - "size_of_ffrt_function_coroutine_t_must_be_less_than_ffrt_auto_managed_function_storage_size"); - FFRT_COND_DO_ERR((co == nullptr), return nullptr, "input valid,co == nullptr"); - FFRT_COND_DO_ERR((exec == nullptr), return nullptr, "input valid,exec == nullptr"); - FFRT_COND_DO_ERR((destroy == nullptr), return nullptr, "input valid,destroy == nullptr"); - ffrt_function_coroutine_t* f = (ffrt_function_coroutine_t*)ffrt_alloc_auto_managed_function_storage_base( - ffrt_function_kind_general); - f->header.exec = (ffrt_function_ptr_t)ffrt_exec_function_coroutine_wrapper; - f->header.destroy = ffrt_destory_function_coroutine_wrapper; - f->func = exec; - f->destroy = destroy; - f->arg = co; - return (ffrt_function_header_t*) f; -} - -API_ATTRIBUTE((visibility("default"))) -void ffrt_submit_coroutine(void* co, ffrt_coroutine_ptr_t exec, ffrt_function_ptr_t destroy, - const ffrt_deps_t* in_deps, const ffrt_deps_t* out_deps, const ffrt_task_attr_t* attr) -{ - FFRT_COND_DO_ERR((((ffrt::task_attr_private*)attr)->coroutine_type_ != ffrt_coroutine_stackless), - return, "input invalid,coroutine_type != coroutine_stackless"); - ffrt_submit_base(ffrt_create_function_coroutine_wrapper(co, exec, destroy), in_deps, out_deps, attr); -} - -API_ATTRIBUTE((visibility("default"))) -ffrt_task_handle_t ffrt_submit_h_coroutine(void* co, ffrt_coroutine_ptr_t exec, - ffrt_function_ptr_t destroy, const ffrt_deps_t* in_deps, const ffrt_deps_t* out_deps, const ffrt_task_attr_t* attr) -{ - FFRT_COND_DO_ERR((((ffrt::task_attr_private*)attr)->coroutine_type_ != ffrt_coroutine_stackless), - return nullptr, "input invalid,coroutine_type != coroutine_stackless"); - return ffrt_submit_h_base(ffrt_create_function_coroutine_wrapper(co, exec, destroy), in_deps, out_deps, attr); -} - -// waker -API_ATTRIBUTE((visibility("default"))) -void ffrt_wake_by_handle(void* callable, ffrt_function_ptr_t exec, ffrt_function_ptr_t destroy, - ffrt_task_handle_t handle) -{ - FFRT_COND_DO_ERR((callable == nullptr), return, "input valid,co == nullptr"); - FFRT_COND_DO_ERR((exec == nullptr), return, "input valid,exec == nullptr"); - FFRT_COND_DO_ERR((destroy == nullptr), return, "input valid,destroy == nullptr"); - FFRT_COND_DO_ERR((handle == nullptr), return, "input valid,handle == nullptr"); - ffrt::TaskCtx *task = static_cast(handle); - - task->lock.lock(); - FFRT_LOGW("tid:%ld ffrt_wake_by_handle and CurState = %d", syscall(SYS_gettid), task->state.CurState()); - if (task->state.CurState() != ffrt::TaskState::State::EXITED) { - task->wake_callable_on_finish.callable = callable; - task->wake_callable_on_finish.exec = exec; - task->wake_callable_on_finish.destroy = destroy; - } - task->lock.unlock(); -} - -API_ATTRIBUTE((visibility("default"))) -void ffrt_set_wake_flag(bool flag) -{ - ffrt::TaskCtx * task = (ffrt::TaskCtx *)ffrt_task_get(); - task->SetWakeFlag(flag); -} - -API_ATTRIBUTE((visibility("default"))) -void * ffrt_task_get() -{ - return (void*)ffrt::ExecuteCtx::Cur()->task; -} -#endif - // submit API_ATTRIBUTE((visibility("default"))) void *ffrt_alloc_auto_managed_function_storage_base(ffrt_function_kind_t kind) diff --git a/src/core/task_attr_private.h b/src/core/task_attr_private.h index a3bd871..55724ea 100644 --- a/src/core/task_attr_private.h +++ b/src/core/task_attr_private.h @@ -29,8 +29,7 @@ public: explicit task_attr_private(const task_attr attr) : qos_(attr.qos()), name_(attr.name()), - delay_(attr.delay()), - coroutine_type_(attr.coroutine_type()) + delay_(attr.delay()) { } @@ -39,7 +38,6 @@ public: uint64_t delay_ = 0; uint64_t timeout_ = 0; ffrt_function_header_t* timeoutCb_ = nullptr; - ffrt_coroutine_t coroutine_type_ = ffrt_coroutine_stackfull; }; } #endif diff --git a/src/core/task_ctx.cpp b/src/core/task_ctx.cpp index 4b64939..bbed16b 100644 --- a/src/core/task_ctx.cpp +++ b/src/core/task_ctx.cpp @@ -51,9 +51,6 @@ TaskCtx::TaskCtx(const task_attr_private *attr, TaskCtx *parent, const uint64_t } else { label = parent->label + "." + std::to_string(rank); } - if (attr) { - coroutine_type = attr->coroutine_type_; - } if (!IsRoot()) { FFRT_SUBMIT_MARKER(label, gid); } diff --git a/src/core/task_ctx.h b/src/core/task_ctx.h index ae0c587..d85a2e8 100644 --- a/src/core/task_ctx.h +++ b/src/core/task_ctx.h @@ -39,13 +39,6 @@ namespace ffrt { struct TaskCtx; struct VersionCtx; -typedef struct { - ffrt_function_ptr_t exec; - ffrt_function_ptr_t destroy; - void* callable; -} ffrt_callable_t; - - /* TaskCtx 必须是数据结构ffrt_executor_task_t的子类 */ @@ -65,8 +58,6 @@ struct TaskCtx : public TaskDeleter { std::vector in_handles; CoRoutine* coRoutine = nullptr; std::vector traceTag; - bool wakeFlag = true; - ffrt_callable_t wake_callable_on_finish {nullptr, nullptr, nullptr}; #ifdef MUTEX_PERF // Mutex Lock&Unlock Cycles Statistic xx::mutex lock {"TaskCtx::lock"}; @@ -108,9 +99,6 @@ struct TaskCtx : public TaskDeleter { QoS qos; void SetQos(QoS& qos); - ffrt_coroutine_t coroutine_type = ffrt_coroutine_stackfull; - uint32_t stackless_coroutine_wake_count = 1; - inline void freeMem() override { BboxCheckAndFreeze(); @@ -173,11 +161,6 @@ struct TaskCtx : public TaskDeleter { } } - void SetWakeFlag(bool wakeFlagIn) - { - wakeFlag = wakeFlagIn; - } - #ifdef FFRT_CO_BACKTRACE_OH_ENABLE static void DumpTask(TaskCtx* task, std::string& stackInfo, uint8_t flag = 0); /* 0:hilog others:hiview */ #endif diff --git a/src/dfx/watchdog/watchdog.cpp b/src/dfx/watchdog/watchdog.cpp index aeeb7c9..b041e10 100644 --- a/src/dfx/watchdog/watchdog.cpp +++ b/src/dfx/watchdog/watchdog.cpp @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "ffrt_watchdog.h" +#include "c/ffrt_watchdog.h" #include "internal_inc/osal.h" #include "dfx/bbox/bbox.h" diff --git a/src/eu/co_routine.cpp b/src/eu/co_routine.cpp index 8ec313e..92cf7f5 100644 --- a/src/eu/co_routine.cpp +++ b/src/eu/co_routine.cpp @@ -14,7 +14,6 @@ */ #include "co_routine.h" -#include #include #include #include @@ -296,82 +295,3 @@ void CoWake(ffrt::TaskCtx* task, bool timeOut) FFRT_WAKE_TRACER(task->gid); task->UpdateState(ffrt::TaskState::READY); } - -#ifdef USE_STACKLESS_COROUTINE -static inline void ffrt_exec_callable_wrapper(void* t) -{ - ffrt::ffrt_callable_t* f = (ffrt::ffrt_callable_t*)t; - f->exec(f->callable); -} - -static inline void ffrt_destroy_callable_wrapper(void* t) -{ - ffrt::ffrt_callable_t* f = (ffrt::ffrt_callable_t*)t; - f->destroy(f->callable); -} - -static void OnStacklessCoroutineReady(ffrt::TaskCtx* task) -{ - task->lock.lock(); - task->state.SetCurState(ffrt::TaskState::State::EXITED); - if (task->stackless_coroutine_wake_count > 0) { - // log - } - task->lock.unlock(); - if (task->wakeFlag&&task->wake_callable_on_finish.exec) { - ffrt_exec_callable_wrapper(static_cast(&(task->wake_callable_on_finish))); - } - if (task->wakeFlag&&task->wake_callable_on_finish.destroy) { - ffrt_destroy_callable_wrapper(static_cast(&(task->wake_callable_on_finish))); - } - auto f = (ffrt_function_header_t*)task->func_storage; - f->destroy(f); - - ffrt::DependenceManager::Instance()->onTaskDone(task); -} - -void StacklessCouroutineStart(ffrt::TaskCtx* task) -{ - assert(task->coroutine_type == ffrt_coroutine_stackless); - auto f = (ffrt_function_header_t*)task->func_storage; - ffrt_coroutine_ptr_t coroutine = (ffrt_coroutine_ptr_t)f->exec; - ffrt_coroutine_ret_t ret = coroutine(f); - if (ret == ffrt_coroutine_ready) { - OnStacklessCoroutineReady(task); - } else { - task->lock.lock(); - task->stackless_coroutine_wake_count-=1; - if (task->stackless_coroutine_wake_count > 0) { - task->state.SetCurState(ffrt::TaskState::State::READY); - task->lock.unlock(); - ffrt::FFRTScheduler::Instance()->PushTask(task); - } else { - task->state.SetCurState(ffrt::TaskState::State::BLOCKED); - task->lock.unlock(); - } - } -} - -#ifdef __cplusplus -extern "C" { -#endif - -API_ATTRIBUTE((visibility("default"))) -void ffrt_wake_coroutine(void *taskin) -{ - ffrt::TaskCtx *task = (ffrt::TaskCtx *)taskin; - std::unique_locklock)>lck(task->lock); - if (task->state.CurState() >= ffrt::TaskState::State::EXITED) { - return; - } - task->stackless_coroutine_wake_count+=1; - if (task->stackless_coroutine_wake_count == 1) { - task->state.SetCurState(ffrt::TaskState::State::READY); - task->lock.unlock(); - ffrt::FFRTScheduler::Instance()->WakeupTask(task); - } -} -#ifdef __cplusplus -} -#endif -#endif \ No newline at end of file diff --git a/src/eu/co_routine.h b/src/eu/co_routine.h index 57594fc..5804510 100644 --- a/src/eu/co_routine.h +++ b/src/eu/co_routine.h @@ -101,8 +101,4 @@ void CoYield(void); void CoWait(const std::function& pred); void CoWake(ffrt::TaskCtx* task, bool timeOut); -#ifdef USE_STACKLESS_COROUTINE -void StacklessCouroutineStart(ffrt::TaskCtx* task); -#endif - #endif diff --git a/src/eu/cpu_worker.cpp b/src/eu/cpu_worker.cpp index ab424e8..1105603 100644 --- a/src/eu/cpu_worker.cpp +++ b/src/eu/cpu_worker.cpp @@ -27,13 +27,6 @@ void CPUWorker::Run(TaskCtx* task) FFRT_TRACE_SCOPE(TRACE_LEVEL2, Run); if constexpr(USE_COROUTINE) { CoStart(task); -#ifdef USE_STACKLESS_COROUTINE - if (task->coroutine_type == ffrt_coroutine_stackfull) { - CoStart(task); - } else { - StacklessCoroutineStart(task); - } -#endif } else { auto f = reinterpret_cast(task->func_storage); auto exp = ffrt::SkipStatus::SUBMITTED; diff --git a/src/eu/cpu_worker.h b/src/eu/cpu_worker.h index c5c046a..1711223 100644 --- a/src/eu/cpu_worker.h +++ b/src/eu/cpu_worker.h @@ -18,6 +18,7 @@ #include "eu/worker_thread.h" #include "eu/cpu_manager_interface.h" +#include "c/executor_task.h" namespace ffrt { diff --git a/src/eu/func_manager.h b/src/eu/func_manager.h index bc6442f..3780047 100644 --- a/src/eu/func_manager.h +++ b/src/eu/func_manager.h @@ -16,7 +16,7 @@ #ifndef FFRT_FUNC_MANAGER_HPP #define FFRT_FUNC_MANAGER_HPP -#include "ffrt.h" +#include "ffrt_inner.h" namespace ffrt { class FuncManager { diff --git a/src/eu/osattr_manager.h b/src/eu/osattr_manager.h index 8952f4a..99a5869 100644 --- a/src/eu/osattr_manager.h +++ b/src/eu/osattr_manager.h @@ -15,7 +15,7 @@ #ifndef OS_ATTR_MANAGER_H #define OS_ATTR_MANAGER_H -#include "ffrt.h" +#include "ffrt_inner.h" #include "sched/qos.h" namespace ffrt { diff --git a/src/eu/qos_convert.cpp b/src/eu/qos_convert.cpp index 4811ada..448687a 100644 --- a/src/eu/qos_convert.cpp +++ b/src/eu/qos_convert.cpp @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "qos_convert.h" +#include "cpp/qos_convert.h" #include "dfx/log/ffrt_log_api.h" #include "eu/qos_interface.h" diff --git a/src/queue/queue_monitor.cpp b/src/queue/queue_monitor.cpp index 7f9ecf5..a1bdae8 100644 --- a/src/queue/queue_monitor.cpp +++ b/src/queue/queue_monitor.cpp @@ -19,7 +19,7 @@ #include "dfx/log/ffrt_log_api.h" #include "internal_inc/osal.h" #include "sync/sync.h" -#include "ffrt_watchdog.h" +#include "c/ffrt_watchdog.h" namespace { constexpr uint32_t INVAILD_TASK_ID = 0; diff --git a/src/sched/deadline.cpp b/src/sched/deadline.cpp index d9ecd9c..3df4a3c 100644 --- a/src/sched/deadline.cpp +++ b/src/sched/deadline.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "deadline.h" +#include "cpp/deadline.h" #include "c/deadline.h" #include "internal_inc/osal.h" #include "sched/interval.h" diff --git a/src/sched/qos.h b/src/sched/qos.h index a638a0c..f466c46 100644 --- a/src/sched/qos.h +++ b/src/sched/qos.h @@ -16,7 +16,7 @@ #ifndef FFRT_QOS_H #define FFRT_QOS_H -#include "ffrt.h" +#include "ffrt_inner.h" namespace ffrt { class QoS { diff --git a/src/sched/task_runqueue.h b/src/sched/task_runqueue.h index 421cd7f..61d3855 100644 --- a/src/sched/task_runqueue.h +++ b/src/sched/task_runqueue.h @@ -18,6 +18,7 @@ #include "core/task_ctx.h" +#include "c/executor_task.h" namespace ffrt { template diff --git a/src/sync/io_poller.h b/src/sync/io_poller.h index d71b2b9..f106efd 100644 --- a/src/sync/io_poller.h +++ b/src/sync/io_poller.h @@ -23,7 +23,7 @@ #include #include #include -#include "ffrt.h" +#include "ffrt_inner.h" #include "internal_inc/non_copyable.h" namespace ffrt { diff --git a/test/ut/BUILD.gn b/test/ut/BUILD.gn index dee802a..dcdb59f 100644 --- a/test/ut/BUILD.gn +++ b/test/ut/BUILD.gn @@ -378,8 +378,5 @@ group("ffrt_unittest_ffrt") { ":task_ctx_test", ":worker_thread_test", ] - if (use_stackless_coroutine) { - deps += [ ":ut_coroutine_test" ] - } } } diff --git a/test/ut/deadline_test.cpp b/test/ut/deadline_test.cpp index 5f00b08..a0737af 100644 --- a/test/ut/deadline_test.cpp +++ b/test/ut/deadline_test.cpp @@ -15,7 +15,7 @@ #include #include -#include "deadline.h" +#include "cpp/deadline.h" #include "internal_inc/osal.h" #include "sched/interval.h" #include "core/dependence_manager.h" diff --git a/test/ut/qos_convert_test.cpp b/test/ut/qos_convert_test.cpp index 72087fa..bfd5d5c 100644 --- a/test/ut/qos_convert_test.cpp +++ b/test/ut/qos_convert_test.cpp @@ -18,7 +18,7 @@ #include #include #include -#include "qos_convert.h" +#include "cpp/qos_convert.h" #include "eu/qos_interface.h" using namespace testing;