• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025-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 #ifndef MOCK_FFRT_API_C_TYPE_DEF_H
16 #define MOCK_FFRT_API_C_TYPE_DEF_H
17 
18 #include <stdint.h>
19 #include <errno.h>
20 
21 #ifdef __cplusplus
22 #define FFRT_C_API
23 #else
24 #define FFRT_C_API
25 #endif
26 
27 typedef enum {
28 
29     ffrt_queue_priority_immediate = 0,
30 
31     ffrt_queue_priority_high,
32 
33     ffrt_queue_priority_low,
34 
35     ffrt_queue_priority_idle,
36 } ffrt_queue_priority_t;
37 
38 typedef enum {
39 
40     ffrt_qos_inherit = -1,
41 
42     ffrt_qos_background,
43 
44     ffrt_qos_utility,
45 
46     ffrt_qos_default,
47 
48     ffrt_qos_user_initiated,
49 } ffrt_qos_default_t;
50 
51 typedef int ffrt_qos_t;
52 
53 typedef void (*ffrt_function_t)(void *);
54 
55 typedef struct {
56 
57     ffrt_function_t exec;
58 
59     ffrt_function_t destroy;
60 
61     uint64_t reserve[2];
62 } ffrt_function_header_t;
63 
64 typedef enum {
65 
66     ffrt_task_attr_storage_size = 128,
67 
68     ffrt_auto_managed_function_storage_size = 64 + sizeof(ffrt_function_header_t),
69 
70     ffrt_mutex_storage_size = 64,
71 
72     ffrt_cond_storage_size = 64,
73 
74     ffrt_queue_attr_storage_size = 128,
75 
76     ffrt_rwlock_storage_size = 64,
77 
78 #if defined(__aarch64__)
79     ffrt_fiber_storage_size = 22,
80 #elif defined(__arm__)
81     ffrt_fiber_storage_size = 64,
82 #elif defined(__x86_64__)
83     ffrt_fiber_storage_size = 8,
84 #else
85 #error "unsupported architecture"
86 #endif
87 } ffrt_storage_size_t;
88 
89 typedef enum {
90 
91     ffrt_function_kind_general,
92 
93     ffrt_function_kind_queue,
94 } ffrt_function_kind_t;
95 
96 typedef enum {
97 
98     ffrt_dependence_data,
99 
100     ffrt_dependence_task,
101 } ffrt_dependence_type_t;
102 
103 typedef struct {
104 
105     ffrt_dependence_type_t type;
106 
107     const void *ptr;
108 } ffrt_dependence_t;
109 
110 typedef struct {
111 
112     uint32_t len;
113 
114     const ffrt_dependence_t *items;
115 } ffrt_deps_t;
116 
117 typedef struct {
118 
119     uint32_t storage[(ffrt_task_attr_storage_size + sizeof(uint32_t) - 1) / sizeof(uint32_t)];
120 } ffrt_task_attr_t;
121 
122 typedef struct {
123 
124     uint32_t storage[(ffrt_queue_attr_storage_size + sizeof(uint32_t) - 1) / sizeof(uint32_t)];
125 } ffrt_queue_attr_t;
126 
127 typedef void *ffrt_task_handle_t;
128 
129 typedef enum {
130 
131     ffrt_error = -1,
132 
133     ffrt_success = 0,
134 
135     ffrt_error_nomem = ENOMEM,
136 
137     ffrt_error_timedout = ETIMEDOUT,
138 
139     ffrt_error_busy = EBUSY,
140 
141     ffrt_error_inval = EINVAL
142 } ffrt_error_t;
143 
144 typedef struct {
145 
146     long storage;
147 } ffrt_condattr_t;
148 
149 typedef struct {
150 
151     long storage;
152 } ffrt_mutexattr_t;
153 
154 typedef struct {
155 
156     long storage;
157 } ffrt_rwlockattr_t;
158 
159 typedef enum {
160 
161     ffrt_mutex_normal = 0,
162 
163     ffrt_mutex_recursive = 2,
164 
165     ffrt_mutex_default = ffrt_mutex_normal
166 } ffrt_mutex_type;
167 
168 typedef struct {
169 
170     uint32_t storage[(ffrt_mutex_storage_size + sizeof(uint32_t) - 1) / sizeof(uint32_t)];
171 } ffrt_mutex_t;
172 
173 typedef struct {
174 
175     uint32_t storage[(ffrt_rwlock_storage_size + sizeof(uint32_t) - 1) / sizeof(uint32_t)];
176 } ffrt_rwlock_t;
177 
178 typedef struct {
179 
180     uint32_t storage[(ffrt_cond_storage_size + sizeof(uint32_t) - 1) / sizeof(uint32_t)];
181 } ffrt_cond_t;
182 
183 typedef struct {
184 
185     uintptr_t storage[ffrt_fiber_storage_size];
186 } ffrt_fiber_t;
187 
188 typedef void (*ffrt_poller_cb)(void *data, uint32_t event);
189 
190 typedef void (*ffrt_timer_cb)(void *data);
191 
192 typedef int ffrt_timer_t;
193 
194 #ifdef __cplusplus
195 namespace ffrt {
196 
197 enum qos_default {
198 
199     qos_inherit = ffrt_qos_inherit,
200 
201     qos_background = ffrt_qos_background,
202 
203     qos_utility = ffrt_qos_utility,
204 
205     qos_default = ffrt_qos_default,
206 
207     qos_user_initiated = ffrt_qos_user_initiated,
208 };
209 
210 using qos = int;
211 
212 }  // namespace ffrt
213 
214 #endif
215 #endif