• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 12
23  */
24 
25 /**
26  * @file loop.h
27  *
28  * @brief Declares the loop interfaces in C.
29  *
30  * @library libffrt.z.so
31  * @kit FunctionFlowRuntimeKit
32  * @syscap SystemCapability.Resourceschedule.Ffrt.Core
33  * @since 12
34  */
35 
36 #ifndef FFRT_API_C_LOOP_H
37 #define FFRT_API_C_LOOP_H
38 
39 #include "queue.h"
40 #include "type_def.h"
41 
42 /**
43  * @brief Defines the loop handle, which identifies different loops.
44  *
45  * @since 12
46  */
47 typedef void* ffrt_loop_t;
48 
49 /**
50  * @brief Creates a loop.
51  *
52  * @param queue Indicates a queue.
53  * @return Returns a non-null loop handle if the loop is created;
54            returns a null pointer otherwise.
55  * @since 12
56  */
57 FFRT_C_API ffrt_loop_t ffrt_loop_create(ffrt_queue_t queue);
58 
59 /**
60  * @brief Destroys a loop, the user needs to invoke this interface.
61  *
62  * @param loop Indicates a loop handle.
63  * @return Returns 0 if the loop is destroyed;
64            returns -1 otherwise.
65  * @since 12
66  */
67 FFRT_C_API int ffrt_loop_destroy(ffrt_loop_t loop);
68 
69 /**
70  * @brief Starts a loop run.
71  *
72  * @param loop Indicates a loop handle.
73  * @return Returns -1 if loop run fail;
74            returns 0 otherwise.
75  * @since 12
76  */
77 FFRT_C_API int ffrt_loop_run(ffrt_loop_t loop);
78 
79 /**
80  * @brief Stops a loop run.
81  *
82  * @param loop Indicates a loop handle.
83  * @since 12
84  */
85 FFRT_C_API void ffrt_loop_stop(ffrt_loop_t loop);
86 
87 /**
88  * @brief Controls an epoll file descriptor on ffrt loop.
89  *
90  * @param loop Indicates a loop handle.
91  * @param op Indicates operation on the target file descriptor.
92  * @param fd Indicates the target file descriptor on which to perform the operation.
93  * @param events Indicates the event type associated with the target file descriptor.
94  * @param data Indicates user data used in cb.
95  * @param cb Indicates user cb which will be executed when the target fd is polled.
96  * @return Returns 0 if success;
97            returns -1 otherwise.
98  * @since 12
99  */
100 FFRT_C_API int ffrt_loop_epoll_ctl(ffrt_loop_t loop, int op, int fd, uint32_t events, void *data, ffrt_poller_cb cb);
101 
102 /**
103  * @brief Starts a timer on ffrt loop.
104  *
105  * @param loop Indicates a loop handle.
106  * @param timeout Indicates the number of milliseconds that specifies timeout.
107  * @param data Indicates user data used in cb.
108  * @param cb Indicates user cb which will be executed when timeout.
109  * @param repeat Indicates whether to repeat this timer.
110  * @return Returns a timer handle.
111  * @since 12
112  */
113 FFRT_C_API ffrt_timer_t ffrt_loop_timer_start(
114     ffrt_loop_t loop, uint64_t timeout, void* data, ffrt_timer_cb cb, bool repeat);
115 
116 /**
117  * @brief Stops a timer on ffrt loop.
118  *
119  * @param loop Indicates a loop handle.
120  * @param handle Indicates the target timer handle.
121  * @return Returns 0 if success;
122            returns -1 otherwise.
123  * @since 12
124  */
125 FFRT_C_API int ffrt_loop_timer_stop(ffrt_loop_t loop, ffrt_timer_t handle);
126 
127 #endif // FFRT_API_C_LOOP_H
128 /** @} */