归档ffrt头文件

Signed-off-by: huangdongting <huangdongting3@huawei.com>
This commit is contained in:
huangdongting 2023-08-24 18:43:27 +08:00
parent a75067c61b
commit e7a14c92fc
9 changed files with 960 additions and 0 deletions

View File

@ -0,0 +1,41 @@
# 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.
import("//build/ohos.gni")
import("//build/ohos/ndk/ndk.gni")
ohos_ndk_headers("ffrt_header") {
dest_dir = "$ndk_headers_out_dir/ffrt"
sources = [
"c/condition_variable.h",
"c/mutex.h",
"c/queue.h",
"c/sleep.h",
"c/task.h",
"c/type_def.h",
]
}
ohos_ndk_library("libffrt_ndk") {
output_name = "ffrt"
ndk_description_file = "./ffrt.ndk.json"
system_capability = "SystemCapability.Resourceschedule.Ffrt.Core"
system_capability_headers = [
"ffrt/condition_variable.h",
"ffrt/mutex.h",
"ffrt/queue.h",
"ffrt/sleep.h",
"ffrt/task.h",
"ffrt/type_def.h",
]
}

View File

@ -0,0 +1,118 @@
/*
* 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.
*/
/**
* @addtogroup Ffrt
* @{
*
* @brief ffrt provides APIs.
*
*
* @syscap SystemCapability.Resourceschedule.Ffrt.Core
*
* @since 10
*/
/**
* @file condition_variable.h
*
* @brief Declares the condition variable interfaces in C.
*
* @syscap SystemCapability.Resourceschedule.Ffrt.Core
* @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"
/**
* @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.
* @syscap SystemCapability.Resourceschedule.Ffrt.Core
* @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.
* @syscap SystemCapability.Resourceschedule.Ffrt.Core
* @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.
* @syscap SystemCapability.Resourceschedule.Ffrt.Core
* @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.
* @syscap SystemCapability.Resourceschedule.Ffrt.Core
* @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

View File

@ -0,0 +1,96 @@
/*
* 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.
*/
/**
* @addtogroup Ffrt
* @{
*
* @brief ffrt provides APIs.
*
*
* @syscap SystemCapability.Resourceschedule.Ffrt.Core
*
* @since 10
*/
/**
* @file mutex.h
*
* @brief Declares the mutex interfaces in C.
*
* @syscap SystemCapability.Resourceschedule.Ffrt.Core
* @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

View File

@ -0,0 +1,192 @@
/*
* 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.
*/
/**
* @addtogroup Ffrt
* @{
*
* @brief ffrt provides APIs.
*
*
* @syscap SystemCapability.Resourceschedule.Ffrt.Core
*
* @since 10
*/
/**
* @file queue.h
*
* @brief Declares the queue interfaces in C.
*
* @syscap SystemCapability.Resourceschedule.Ffrt.Core
* @since 10
* @version 1.0
*/
#ifndef FFRT_API_C_QUEUE_H
#define FFRT_API_C_QUEUE_H
#include "type_def.h"
typedef enum { ffrt_queue_serial, ffrt_queue_max } ffrt_queue_type_t;
typedef void* ffrt_queue_t;
/**
* @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);
/**
* @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);
/**
* @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);
/**
* @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);
/**
* @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);
/**
* @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

View File

@ -0,0 +1,59 @@
/*
* 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.
*/
/**
* @addtogroup Ffrt
* @{
*
* @brief ffrt provides APIs.
*
*
* @syscap SystemCapability.Resourceschedule.Ffrt.Core
*
* @since 10
*/
/**
* @file sleep.h
*
* @brief Declares the sleep and yield interfaces in C.
*
* @syscap SystemCapability.Resourceschedule.Ffrt.Core
* @since 10
* @version 1.0
*/
#ifndef FFRT_API_C_SLEEP_H
#define FFRT_API_C_SLEEP_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

View File

@ -0,0 +1,204 @@
/*
* 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.
*/
/**
* @addtogroup Ffrt
* @{
*
* @brief ffrt provides APIs.
*
*
* @syscap SystemCapability.Resourceschedule.Ffrt.Core
*
* @since 10
*/
/**
* @file task.h
*
* @brief Declares the task interfaces in C.
*
* @syscap SystemCapability.Resourceschedule.Ffrt.Core
* @since 10
* @version 1.0
*/
#ifndef FFRT_API_C_TASK_H
#define FFRT_API_C_TASK_H
#include "type_def.h"
/**
* @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);
/**
* @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);
/**
* @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);
/**
* @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);
/**
* @brief Waits until all submitted tasks are complete.
*
* @since 10
* @version 1.0
*/
FFRT_C_API void ffrt_wait(void);
#endif

View File

@ -0,0 +1,175 @@
/*
* 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.
*/
/**
* @addtogroup Ffrt
* @{
*
* @brief ffrt provides APIs.
*
*
* @syscap SystemCapability.Resourceschedule.Ffrt.Core
*
* @since 10
*/
/**
* @file type_def.h
*
* @brief Declares common types.
*
* @syscap SystemCapability.Resourceschedule.Ffrt.Core
* @since 10
* @version 1.0
*/
#ifndef FFRT_API_C_TYPE_DEF_H
#define FFRT_API_C_TYPE_DEF_H
#include <stdint.h>
#include <errno.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_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_default_t;
typedef int ffrt_qos_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,
/** 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;
typedef enum {
ffrt_dependence_data,
ffrt_dependence_task,
} ffrt_dependence_type_t;
typedef struct {
ffrt_dependence_type_t type;
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;
typedef struct {
uint32_t storage[(ffrt_task_attr_storage_size + sizeof(uint32_t) - 1) / sizeof(uint32_t)];
} ffrt_task_attr_t;
typedef struct {
uint32_t storage[(ffrt_queue_attr_storage_size + sizeof(uint32_t) - 1) / sizeof(uint32_t)];
} ffrt_queue_attr_t;
typedef void* ffrt_task_handle_t;
typedef enum {
ffrt_error = -1,
ffrt_success = 0,
ffrt_error_nomem = ENOMEM,
ffrt_error_timedout = ETIMEDOUT,
ffrt_error_busy = EBUSY,
ffrt_error_inval = EINVAL
} ffrt_error_t;
typedef struct {
long storage;
} ffrt_condattr_t;
typedef struct {
long storage;
} ffrt_mutexattr_t;
typedef struct {
uint32_t storage[(ffrt_mutex_storage_size + sizeof(uint32_t) - 1) / sizeof(uint32_t)];
} ffrt_mutex_t;
typedef struct {
uint32_t storage[(ffrt_cond_storage_size + sizeof(uint32_t) - 1) / sizeof(uint32_t)];
} ffrt_cond_t;
#ifdef __cplusplus
namespace ffrt {
enum qos_default {
qos_inherit = ffrt_qos_inherit,
qos_background = ffrt_qos_background,
qos_utility = ffrt_qos_utility,
qos_default = ffrt_qos_default,
qos_user_initiated = ffrt_qos_user_initiated,
};
using qos = int;
}
#endif
#endif

View File

@ -0,0 +1,30 @@
/*
* 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_FFRT_H
#define FFRT_API_FFRT_H
#ifdef __cplusplus
#include "cpp/task.h"
#include "cpp/mutex.h"
#include "cpp/condition_variable.h"
#include "cpp/sleep.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/queue.h"
#endif
#endif

View File

@ -0,0 +1,45 @@
[
{ "name": "ffrt_cond_init" },
{ "name": "ffrt_cond_signal" },
{ "name": "ffrt_cond_broadcast" },
{ "name": "ffrt_cond_wait" },
{ "name": "ffrt_cond_timedwait" },
{ "name": "ffrt_cond_destroy" },
{ "name": "ffrt_mutex_init" },
{ "name": "ffrt_mutex_lock" },
{ "name": "ffrt_mutex_unlock" },
{ "name": "ffrt_mutex_trylock" },
{ "name": "ffrt_mutex_destroy" },
{ "name": "ffrt_queue_attr_init" },
{ "name": "ffrt_queue_attr_destroy" },
{ "name": "ffrt_queue_attr_set_qos" },
{ "name": "ffrt_queue_attr_get_qos" },
{ "name": "ffrt_queue_attr_set_timeout" },
{ "name": "ffrt_queue_attr_get_timeout" },
{ "name": "ffrt_queue_attr_set_callback" },
{ "name": "ffrt_queue_attr_get_callback" },
{ "name": "ffrt_queue_create" },
{ "name": "ffrt_queue_destroy" },
{ "name": "ffrt_queue_submit" },
{ "name": "ffrt_queue_submit_h" },
{ "name": "ffrt_queue_wait" },
{ "name": "ffrt_queue_cancel" },
{ "name": "ffrt_usleep" },
{ "name": "ffrt_yield" },
{ "name": "ffrt_task_attr_init" },
{ "name": "ffrt_task_attr_set_name" },
{ "name": "ffrt_task_attr_get_name" },
{ "name": "ffrt_task_attr_destroy" },
{ "name": "ffrt_task_attr_set_qos" },
{ "name": "ffrt_task_attr_get_qos" },
{ "name": "ffrt_task_attr_set_delay" },
{ "name": "ffrt_task_attr_get_delay" },
{ "name": "ffrt_this_task_update_qos" },
{ "name": "ffrt_this_task_get_id" },
{ "name": "ffrt_alloc_auto_managed_function_storage_base" },
{ "name": "ffrt_submit_base" },
{ "name": "ffrt_submit_h_base" },
{ "name": "ffrt_task_handle_destroy" },
{ "name": "ffrt_wait_deps" },
{ "name": "ffrt_wait" }
]