This source file includes following definitions.
- opal_free_list_get_mt
- opal_free_list_get_st
- opal_free_list_get
- opal_free_list_wait_mt
- opal_free_list_wait_st
- opal_free_list_wait
- opal_free_list_return_mt
- opal_free_list_return_st
- opal_free_list_return
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 #ifndef OPAL_FREE_LIST_H
25 #define OPAL_FREE_LIST_H
26
27 #include "opal_config.h"
28 #include "opal/class/opal_lifo.h"
29 #include "opal/prefetch.h"
30 #include "opal/threads/condition.h"
31 #include "opal/constants.h"
32 #include "opal/runtime/opal.h"
33
34 BEGIN_C_DECLS
35
36 struct mca_mem_pool_t;
37 struct opal_free_list_item_t;
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 typedef int (*opal_free_list_item_init_fn_t) (
54 struct opal_free_list_item_t *item, void *ctx);
55
56 struct opal_free_list_t {
57
58 opal_lifo_t super;
59
60 size_t fl_max_to_alloc;
61
62 size_t fl_num_allocated;
63
64 size_t fl_num_per_alloc;
65
66 size_t fl_num_waiting;
67
68 size_t fl_frag_size;
69
70 size_t fl_frag_alignment;
71
72 size_t fl_payload_buffer_size;
73
74 size_t fl_payload_buffer_alignment;
75
76 opal_class_t *fl_frag_class;
77
78
79 struct mca_mpool_base_module_t *fl_mpool;
80
81 struct mca_rcache_base_module_t *fl_rcache;
82
83 opal_mutex_t fl_lock;
84
85
86 opal_condition_t fl_condition;
87
88 opal_list_t fl_allocations;
89
90 int fl_rcache_reg_flags;
91
92 opal_free_list_item_init_fn_t item_init;
93
94 void *ctx;
95 };
96 typedef struct opal_free_list_t opal_free_list_t;
97 OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_free_list_t);
98
99 struct mca_mpool_base_registration_t;
100 struct opal_free_list_item_t
101 {
102 opal_list_item_t super;
103 struct mca_rcache_base_registration_t *registration;
104 void *ptr;
105 };
106 typedef struct opal_free_list_item_t opal_free_list_item_t;
107 OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_free_list_item_t);
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129 OPAL_DECLSPEC int opal_free_list_init (opal_free_list_t *free_list,
130 size_t frag_size,
131 size_t frag_alignment,
132 opal_class_t* frag_class,
133 size_t payload_buffer_size,
134 size_t payload_buffer_alignment,
135 int num_elements_to_alloc,
136 int max_elements_to_alloc,
137 int num_elements_per_alloc,
138 struct mca_mpool_base_module_t *mpool,
139 int rcache_reg_flags,
140 struct mca_rcache_base_module_t *rcache,
141 opal_free_list_item_init_fn_t item_init,
142 void *ctx);
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166 OPAL_DECLSPEC int opal_free_list_grow_st (opal_free_list_t *flist, size_t num_elements, opal_free_list_item_t **item_out);
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182 OPAL_DECLSPEC int opal_free_list_resize_mt (opal_free_list_t *flist, size_t size);
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198 static inline opal_free_list_item_t *opal_free_list_get_mt (opal_free_list_t *flist)
199 {
200 opal_free_list_item_t *item =
201 (opal_free_list_item_t*) opal_lifo_pop_atomic (&flist->super);
202
203 if (OPAL_UNLIKELY(NULL == item)) {
204 opal_mutex_lock (&flist->fl_lock);
205 opal_free_list_grow_st (flist, flist->fl_num_per_alloc, &item);
206 opal_mutex_unlock (&flist->fl_lock);
207 }
208
209 return item;
210 }
211
212 static inline opal_free_list_item_t *opal_free_list_get_st (opal_free_list_t *flist)
213 {
214 opal_free_list_item_t *item =
215 (opal_free_list_item_t*) opal_lifo_pop_st (&flist->super);
216
217 if (OPAL_UNLIKELY(NULL == item)) {
218 opal_free_list_grow_st (flist, flist->fl_num_per_alloc, &item);
219 }
220
221 return item;
222 }
223
224 static inline opal_free_list_item_t *opal_free_list_get (opal_free_list_t *flist)
225 {
226 if (opal_using_threads ()) {
227 return opal_free_list_get_mt (flist);
228 }
229
230 return opal_free_list_get_st (flist);
231 }
232
233
234 #define OPAL_FREE_LIST_GET(fl, item) \
235 (item) = opal_free_list_get (fl)
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250 #define OPAL_FREE_LIST_WAIT(fl, item) \
251 (item) = opal_free_list_wait (fl)
252
253 static inline opal_free_list_item_t *opal_free_list_wait_mt (opal_free_list_t *fl)
254 {
255 opal_free_list_item_t *item =
256 (opal_free_list_item_t *) opal_lifo_pop_atomic (&fl->super);
257
258 while (NULL == item) {
259 if (!opal_mutex_trylock (&fl->fl_lock)) {
260 if (fl->fl_max_to_alloc <= fl->fl_num_allocated ||
261 OPAL_SUCCESS != opal_free_list_grow_st (fl, fl->fl_num_per_alloc, &item)) {
262 fl->fl_num_waiting++;
263 opal_condition_wait (&fl->fl_condition, &fl->fl_lock);
264 fl->fl_num_waiting--;
265 } else {
266 if (0 < fl->fl_num_waiting) {
267 if (1 == fl->fl_num_waiting) {
268 opal_condition_signal (&fl->fl_condition);
269 } else {
270 opal_condition_broadcast (&fl->fl_condition);
271 }
272 }
273 }
274 } else {
275
276
277
278
279 opal_mutex_lock (&fl->fl_lock);
280 }
281 opal_mutex_unlock (&fl->fl_lock);
282 if (NULL == item) {
283 item = (opal_free_list_item_t *) opal_lifo_pop_atomic (&fl->super);
284 }
285 }
286
287 return item;
288 }
289
290 static inline opal_free_list_item_t *opal_free_list_wait_st (opal_free_list_t *fl)
291 {
292 opal_free_list_item_t *item =
293 (opal_free_list_item_t *) opal_lifo_pop (&fl->super);
294
295 while (NULL == item) {
296 if (fl->fl_max_to_alloc <= fl->fl_num_allocated ||
297 OPAL_SUCCESS != opal_free_list_grow_st (fl, fl->fl_num_per_alloc, &item)) {
298
299 opal_progress ();
300 }
301 if (NULL == item) {
302 item = (opal_free_list_item_t *) opal_lifo_pop (&fl->super);
303 }
304 }
305
306 return item;
307 }
308
309 static inline opal_free_list_item_t *opal_free_list_wait (opal_free_list_t *fl)
310 {
311 if (opal_using_threads ()) {
312 return opal_free_list_wait_mt (fl);
313 } else {
314 return opal_free_list_wait_st (fl);
315 }
316 }
317
318
319
320
321
322
323
324
325 static inline void opal_free_list_return_mt (opal_free_list_t *flist,
326 opal_free_list_item_t *item)
327 {
328 opal_list_item_t* original;
329
330 original = opal_lifo_push_atomic (&flist->super, &item->super);
331 if (&flist->super.opal_lifo_ghost == original) {
332 if (flist->fl_num_waiting > 0) {
333
334
335
336
337 opal_condition_signal (&flist->fl_condition);
338 }
339 }
340 }
341
342 static inline void opal_free_list_return_st (opal_free_list_t *flist,
343 opal_free_list_item_t *item)
344 {
345 opal_list_item_t* original;
346
347 original = opal_lifo_push_st (&flist->super, &item->super);
348 if (&flist->super.opal_lifo_ghost == original) {
349 if (flist->fl_num_waiting > 0) {
350
351
352
353
354 opal_condition_signal (&flist->fl_condition);
355 }
356 }
357 }
358
359 static inline void opal_free_list_return (opal_free_list_t *flist,
360 opal_free_list_item_t *item)
361 {
362 if (opal_using_threads ()) {
363 opal_free_list_return_mt (flist, item);
364 } else {
365 opal_free_list_return_st (flist, item);
366 }
367 }
368
369
370 #define OPAL_FREE_LIST_RETURN(fl, item) \
371 opal_free_list_return (fl, item)
372
373 END_C_DECLS
374 #endif
375