mirror of
https://gitee.com/openharmony/resourceschedule_ffrt
synced 2024-12-03 11:01:02 +00:00
commit
d609c95cbd
@ -46,7 +46,6 @@
|
||||
"header_base": "//foundation/resourceschedule/ffrt/interfaces/",
|
||||
"header_files": [
|
||||
"kits/ffrt.h",
|
||||
"inner_api/deadline.h",
|
||||
"inner_api/ffrt_inner.h"
|
||||
]
|
||||
},
|
||||
|
38
interfaces/inner_api/c/executor_task.h
Normal file
38
interfaces/inner_api/c/executor_task.h
Normal file
@ -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
|
@ -15,7 +15,7 @@
|
||||
#ifndef FFRT_WATCHDOG_H
|
||||
#define FFRT_WATCHDOG_H
|
||||
#include <stdint.h>
|
||||
#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);
|
33
interfaces/inner_api/c/task.h
Normal file
33
interfaces/inner_api/c/task.h
Normal file
@ -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 <b>0</b> if the task is skipped;
|
||||
returns <b>-1</b> 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
|
100
interfaces/inner_api/c/type_def.h
Normal file
100
interfaces/inner_api/c/type_def.h
Normal file
@ -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 <stdint.h>
|
||||
#include <errno.h>
|
||||
#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
|
@ -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
|
@ -18,8 +18,8 @@
|
||||
#include <optional>
|
||||
#include <chrono>
|
||||
#include <cassert>
|
||||
#include "condition_variable.h"
|
||||
#include "thread.h"
|
||||
#include "cpp/condition_variable.h"
|
||||
#include "cpp/thread.h"
|
||||
|
||||
namespace ffrt {
|
||||
struct non_copyable {
|
@ -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;
|
47
interfaces/inner_api/cpp/task.h
Normal file
47
interfaces/inner_api/cpp/task.h
Normal file
@ -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 <vector>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include "../c/task.h"
|
||||
|
||||
namespace ffrt {
|
||||
/**
|
||||
* @brief Skips a task.
|
||||
*
|
||||
* @param handle Indicates a task handle.
|
||||
* @return Returns <b>0</b> if the task is skipped;
|
||||
returns <b>-1</b> otherwise.
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
static inline int skip(task_handle &handle)
|
||||
{
|
||||
return ffrt_skip(handle);
|
||||
}
|
||||
} // namespace ffrt
|
||||
#endif
|
@ -16,7 +16,7 @@
|
||||
#define FFRT_API_CPP_THREAD_H
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include "task.h"
|
||||
#include "cpp/task.h"
|
||||
|
||||
namespace ffrt {
|
||||
class thread {
|
@ -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
|
||||
|
@ -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 <time.h>
|
||||
#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 <b>ffrt_thrd_success</b> if the condition variable is initialized;
|
||||
returns <b>ffrt_thrd_error</b> 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 <b>ffrt_thrd_success</b> if the thread is unblocked;
|
||||
returns <b>ffrt_thrd_error</b> 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 <b>ffrt_thrd_success</b> if the threads are unblocked;
|
||||
returns <b>ffrt_thrd_error</b> 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 <b>ffrt_thrd_success</b> if the thread is unblocked after being blocked;
|
||||
returns <b>ffrt_thrd_error</b> 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 <b>ffrt_cond_signal</b> or <b>ffrt_cond_broadcast</b> is not called to unblock the thread
|
||||
* when the maximum duration reaches, the thread is automatically unblocked.
|
||||
* @return Returns <b>ffrt_thrd_success</b> if the thread is unblocked after being blocked;
|
||||
returns <b>ffrt_thrd_timedout</b> if the maximum duration reaches;
|
||||
returns <b>ffrt_thrd_error</b> 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 <b>ffrt_thrd_success</b> if the condition variable is destroyed;
|
||||
returns <b>ffrt_thrd_error</b> otherwise.
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
FFRT_C_API int ffrt_cond_destroy(ffrt_cond_t* cond);
|
||||
#endif
|
||||
|
@ -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 <b>ffrt_thrd_success</b> if the mutex is initialized;
|
||||
returns <b>ffrt_thrd_error</b> 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 <b>ffrt_thrd_success</b> if the mutex is locked;
|
||||
returns <b>ffrt_thrd_error</b> 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 <b>ffrt_thrd_success</b> if the mutex is unlocked;
|
||||
returns <b>ffrt_thrd_error</b> 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 <b>ffrt_thrd_success</b> if the mutex is locked;
|
||||
returns <b>ffrt_thrd_error</b> or <b>ffrt_thrd_busy</b> 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 <b>ffrt_thrd_success</b> if the mutex is destroyed;
|
||||
returns <b>ffrt_thrd_error</b> otherwise.
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
FFRT_C_API int ffrt_mutex_destroy(ffrt_mutex_t* mutex);
|
||||
#endif
|
||||
|
@ -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 <b>0</b> if the queue attribute is initialized;
|
||||
returns <b>-1</b> 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 <b>0</b> if the task is canceled;
|
||||
returns <b>-1</b> otherwise.
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
FFRT_C_API int ffrt_queue_cancel(ffrt_task_handle_t handle);
|
||||
|
||||
#endif // FFRT_API_C_QUEUE_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 <time.h>
|
||||
#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 <b>ffrt_thrd_success</b> if the thread is suspended;
|
||||
returns <b>ffrt_thrd_error</b> 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
|
||||
|
@ -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 <b>0</b> if the task attribute is initialized;
|
||||
returns <b>-1</b> 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 <b>ffrt_qos_default</b> 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 <b>0</b> if the QoS is updated;
|
||||
returns <b>-1</b> 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
|
||||
|
@ -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 <stdint.h>
|
||||
@ -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
|
||||
|
@ -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 <chrono>
|
||||
|
@ -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"
|
||||
|
@ -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<void()>& 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<void()>& 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<void()>&& 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<void()>&& 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<void()>& 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<void()>& 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<void()>&& 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<void()>&& 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 <b>0</b> if the task is canceled;
|
||||
returns <b>-1</b> 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);
|
||||
|
@ -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 <ctime>
|
||||
|
@ -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 <vector>
|
||||
@ -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<void()>&& 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<void()>&& func, std::initializer_list<dependence> in_deps)
|
||||
{
|
||||
ffrt_deps_t in {static_cast<uint32_t>(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<void()>&& func, std::initializer_list<dependence> in_deps,
|
||||
std::initializer_list<dependence> out_deps)
|
||||
{
|
||||
@ -220,6 +257,16 @@ static inline void submit(std::function<void()>&& func, std::initializer_list<de
|
||||
return ffrt_submit_base(create_function_wrapper(std::move(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(std::function<void()>&& func, std::initializer_list<dependence> in_deps,
|
||||
std::initializer_list<dependence> out_deps, const task_attr& attr)
|
||||
{
|
||||
@ -228,12 +275,29 @@ static inline void submit(std::function<void()>&& func, std::initializer_list<de
|
||||
return ffrt_submit_base(create_function_wrapper(std::move(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(std::function<void()>&& func, const std::vector<dependence>& in_deps)
|
||||
{
|
||||
ffrt_deps_t in {static_cast<uint32_t>(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<void()>&& func, const std::vector<dependence>& in_deps,
|
||||
const std::vector<dependence>& out_deps)
|
||||
{
|
||||
@ -242,6 +306,16 @@ static inline void submit(std::function<void()>&& func, const std::vector<depend
|
||||
return ffrt_submit_base(create_function_wrapper(std::move(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(std::function<void()>&& func, const std::vector<dependence>& in_deps,
|
||||
const std::vector<dependence>& out_deps, const task_attr& attr)
|
||||
{
|
||||
@ -250,17 +324,41 @@ static inline void submit(std::function<void()>&& func, const std::vector<depend
|
||||
return ffrt_submit_base(create_function_wrapper(std::move(func)), &in, &out, &attr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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(const std::function<void()>& 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<void()>& func, std::initializer_list<dependence> in_deps)
|
||||
{
|
||||
ffrt_deps_t in {static_cast<uint32_t>(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<void()>& func, std::initializer_list<dependence> in_deps,
|
||||
std::initializer_list<dependence> out_deps)
|
||||
{
|
||||
@ -269,6 +367,16 @@ static inline void submit(const std::function<void()>& 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<void()>& func, std::initializer_list<dependence> in_deps,
|
||||
std::initializer_list<dependence> out_deps, const task_attr& attr)
|
||||
{
|
||||
@ -277,12 +385,29 @@ static inline void submit(const std::function<void()>& 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<void()>& func, const std::vector<dependence>& in_deps)
|
||||
{
|
||||
ffrt_deps_t in {static_cast<uint32_t>(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<void()>& func, const std::vector<dependence>& in_deps,
|
||||
const std::vector<dependence>& out_deps)
|
||||
{
|
||||
@ -291,6 +416,16 @@ static inline void submit(const std::function<void()>& func, const std::vector<d
|
||||
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<void()>& func, const std::vector<dependence>& in_deps,
|
||||
const std::vector<dependence>& out_deps, const task_attr& attr)
|
||||
{
|
||||
@ -300,19 +435,46 @@ static inline void submit(const std::function<void()>& func, const std::vector<d
|
||||
}
|
||||
|
||||
/**
|
||||
@brief submit and return task handle
|
||||
*/
|
||||
* @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(std::function<void()>&& 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<void()>&& func, std::initializer_list<dependence> in_deps)
|
||||
{
|
||||
ffrt_deps_t in {static_cast<uint32_t>(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<void()>&& func, std::initializer_list<dependence> in_deps,
|
||||
std::initializer_list<dependence> out_deps)
|
||||
{
|
||||
@ -321,6 +483,18 @@ static inline task_handle submit_h(std::function<void()>&& 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<void()>&& func, std::initializer_list<dependence> in_deps,
|
||||
std::initializer_list<dependence> out_deps, const task_attr& attr)
|
||||
{
|
||||
@ -329,12 +503,33 @@ static inline task_handle submit_h(std::function<void()>&& 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<void()>&& func, const std::vector<dependence>& in_deps)
|
||||
{
|
||||
ffrt_deps_t in {static_cast<uint32_t>(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<void()>&& func, const std::vector<dependence>& in_deps,
|
||||
const std::vector<dependence>& out_deps)
|
||||
{
|
||||
@ -343,6 +538,18 @@ static inline task_handle submit_h(std::function<void()>&& 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<void()>&& func, const std::vector<dependence>& in_deps,
|
||||
const std::vector<dependence>& out_deps, const task_attr& attr)
|
||||
{
|
||||
@ -351,17 +558,47 @@ static inline task_handle submit_h(std::function<void()>&& 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<void()>& 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<void()>& func, std::initializer_list<dependence> in_deps)
|
||||
{
|
||||
ffrt_deps_t in {static_cast<uint32_t>(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<void()>& func, std::initializer_list<dependence> in_deps,
|
||||
std::initializer_list<dependence> out_deps)
|
||||
{
|
||||
@ -370,6 +607,18 @@ static inline task_handle submit_h(const std::function<void()>& 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<void()>& func, std::initializer_list<dependence> in_deps,
|
||||
std::initializer_list<dependence> out_deps, const task_attr& attr)
|
||||
{
|
||||
@ -378,12 +627,33 @@ static inline task_handle submit_h(const std::function<void()>& 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<void()>& func, const std::vector<dependence>& in_deps)
|
||||
{
|
||||
ffrt_deps_t in {static_cast<uint32_t>(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<void()>& func, const std::vector<dependence>& in_deps,
|
||||
const std::vector<dependence>& out_deps)
|
||||
{
|
||||
@ -392,6 +662,18 @@ static inline task_handle submit_h(const std::function<void()>& 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<void()>& func, const std::vector<dependence>& in_deps,
|
||||
const std::vector<dependence>& out_deps, const task_attr& attr)
|
||||
{
|
||||
@ -400,42 +682,43 @@ static inline task_handle submit_h(const std::function<void()>& 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<dependence> deps)
|
||||
{
|
||||
ffrt_deps_t d {static_cast<uint32_t>(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<dependence>& deps)
|
||||
{
|
||||
ffrt_deps_t d {static_cast<uint32_t>(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();
|
||||
|
@ -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
|
||||
|
@ -17,7 +17,7 @@
|
||||
#include <vector>
|
||||
#include <cstdarg>
|
||||
|
||||
#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<ffrt::task_attr_private *>(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<ffrt::TaskCtx*>(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)
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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<TaskCtx*> in_handles;
|
||||
CoRoutine* coRoutine = nullptr;
|
||||
std::vector<std::string> 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
|
||||
|
@ -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"
|
||||
|
||||
|
@ -14,7 +14,6 @@
|
||||
*/
|
||||
|
||||
#include "co_routine.h"
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
@ -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<void*>(&(task->wake_callable_on_finish)));
|
||||
}
|
||||
if (task->wakeFlag&&task->wake_callable_on_finish.destroy) {
|
||||
ffrt_destroy_callable_wrapper(static_cast<void*>(&(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_lock<decltype(task->lock)>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
|
@ -101,8 +101,4 @@ void CoYield(void);
|
||||
void CoWait(const std::function<bool(ffrt::TaskCtx*)>& pred);
|
||||
void CoWake(ffrt::TaskCtx* task, bool timeOut);
|
||||
|
||||
#ifdef USE_STACKLESS_COROUTINE
|
||||
void StacklessCouroutineStart(ffrt::TaskCtx* task);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -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<ffrt_function_header_t*>(task->func_storage);
|
||||
auto exp = ffrt::SkipStatus::SUBMITTED;
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include "eu/worker_thread.h"
|
||||
#include "eu/cpu_manager_interface.h"
|
||||
#include "c/executor_task.h"
|
||||
|
||||
|
||||
namespace ffrt {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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"
|
||||
|
@ -16,7 +16,7 @@
|
||||
#ifndef FFRT_QOS_H
|
||||
#define FFRT_QOS_H
|
||||
|
||||
#include "ffrt.h"
|
||||
#include "ffrt_inner.h"
|
||||
|
||||
namespace ffrt {
|
||||
class QoS {
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
|
||||
#include "core/task_ctx.h"
|
||||
#include "c/executor_task.h"
|
||||
|
||||
namespace ffrt {
|
||||
template <typename Derived>
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <atomic>
|
||||
#include "ffrt.h"
|
||||
#include "ffrt_inner.h"
|
||||
#include "internal_inc/non_copyable.h"
|
||||
|
||||
namespace ffrt {
|
||||
|
@ -378,8 +378,5 @@ group("ffrt_unittest_ffrt") {
|
||||
":task_ctx_test",
|
||||
":worker_thread_test",
|
||||
]
|
||||
if (use_stackless_coroutine) {
|
||||
deps += [ ":ut_coroutine_test" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <thread>
|
||||
#include "deadline.h"
|
||||
#include "cpp/deadline.h"
|
||||
#include "internal_inc/osal.h"
|
||||
#include "sched/interval.h"
|
||||
#include "core/dependence_manager.h"
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <unistd.h>
|
||||
#include "qos_convert.h"
|
||||
#include "cpp/qos_convert.h"
|
||||
#include "eu/qos_interface.h"
|
||||
|
||||
using namespace testing;
|
||||
|
Loading…
Reference in New Issue
Block a user