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