• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @addtogroup FFRT
18  * @{
19  *
20  * @brief Provides FFRT C APIs.
21  *
22  * @since 20
23  */
24 
25 /**
26  * @file fiber.h
27  *
28  * @brief Declares the fiber interfaces in C.
29  *
30  * @library libffrt.z.so
31  * @kit FunctionFlowRuntimeKit
32  * @syscap SystemCapability.Resourceschedule.Ffrt.Core
33  * @since 20
34  */
35 
36 #ifndef FFRT_API_C_FIBER_H
37 #define FFRT_API_C_FIBER_H
38 
39 #include "type_def.h"
40 
41 /**
42  * @brief Initializes a fiber.
43  *
44  * This function initializes a fiber structure, preparing it for execution.
45  *
46  * @param fiber Indicates the pointer to the fiber structure to be initialized.
47  * @param func Indicates the entry point function that the fiber will execute.
48  * @param arg Indicates the argument to be passed to the entry point function.
49  * @param stack Indicates the pointer to the memory region to be used as the fiber's stack.
50  * @param stack_size Indicates the size of the stack in bytes.
51  * @return Returns <b>ffrt_success</b> if the fiber is initialized;
52            returns <b>ffrt_error</b> otherwise.
53  * @since 20
54  */
55 FFRT_C_API int ffrt_fiber_init(ffrt_fiber_t* fiber, void(*func)(void*), void* arg, void* stack, size_t stack_size);
56 
57 
58 /**
59  * @brief Switch execution context between two fibers.
60  *
61  * Switches the execution context by saving the current context into the fiber specified
62  * by @c from and restoring the context from the fiber specified by @c to.
63  *
64  * @param from Indicates the pointer to the fiber into which the current context will be saved.
65  * @param to Indicates the pointer to the fiber from which the context will be restored.
66  * @since 20
67  */
68 FFRT_C_API void ffrt_fiber_switch(ffrt_fiber_t* from, ffrt_fiber_t* to);
69 
70 #endif // FFRT_API_C_FIBER_H
71 /** @} */