Lines Matching +full:composite +full:- +full:in

2  * Copyright (c) 2004-2009 Voltaire, Inc. All rights reserved.
3 * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
4 * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
9 * COPYING in the main directory of this source tree, or the
12 * Redistribution and use in source and binary forms, with or
16 * - Redistributions of source code must retain the above
20 * - Redistributions in binary form must reproduce the above
22 * disclaimer in the documentation and/or other materials
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
56 * IMPLEMENTATION OF QUICK COMPOSITE POOL
58 void cl_qcpool_construct(IN cl_qcpool_t * const p_pool) in cl_qcpool_construct()
64 p_pool->state = CL_UNINITIALIZED; in cl_qcpool_construct()
67 cl_status_t cl_qcpool_init(IN cl_qcpool_t * const p_pool, in cl_qcpool_init()
68 IN const size_t min_size, IN const size_t max_size, in cl_qcpool_init()
69 IN const size_t grow_size, in cl_qcpool_init()
70 IN const size_t * const component_sizes, in cl_qcpool_init()
71 IN const uint32_t num_components, in cl_qcpool_init()
72 IN cl_pfn_qcpool_init_t pfn_initializer OPTIONAL, in cl_qcpool_init()
73 IN cl_pfn_qcpool_dtor_t pfn_destructor OPTIONAL, in cl_qcpool_init()
74 IN const void *const context) in cl_qcpool_init()
101 * in one allocation. in cl_qcpool_init()
103 p_pool->component_sizes = (size_t *) malloc((sizeof(size_t) + in cl_qcpool_init()
107 if (!p_pool->component_sizes) in cl_qcpool_init()
110 memset(p_pool->component_sizes, 0, in cl_qcpool_init()
114 p_pool->p_components = in cl_qcpool_init()
115 (void **)(p_pool->component_sizes + num_components); in cl_qcpool_init()
118 memcpy(p_pool->component_sizes, component_sizes, in cl_qcpool_init()
122 p_pool->num_components = num_components; in cl_qcpool_init()
130 p_pool->component_sizes[i] = in cl_qcpool_init()
131 ROUNDUP(p_pool->component_sizes[i], sizeof(uintptr_t)); in cl_qcpool_init()
134 p_pool->max_objects = max_size ? max_size : ~(size_t) 0; in cl_qcpool_init()
135 p_pool->grow_size = grow_size; in cl_qcpool_init()
138 p_pool->pfn_init = pfn_initializer; /* may be NULL */ in cl_qcpool_init()
139 p_pool->pfn_dtor = pfn_destructor; /* may be NULL */ in cl_qcpool_init()
140 p_pool->context = context; in cl_qcpool_init()
142 cl_qlist_init(&p_pool->alloc_list); in cl_qcpool_init()
144 cl_qlist_init(&p_pool->free_list); in cl_qcpool_init()
150 p_pool->state = CL_INITIALIZED; in cl_qcpool_init()
164 void cl_qcpool_destroy(IN cl_qcpool_t * const p_pool) in cl_qcpool_destroy()
166 /* CL_ASSERT that a non-NULL pointer was provided. */ in cl_qcpool_destroy()
168 /* CL_ASSERT that we are in a valid state (not uninitialized memory). */ in cl_qcpool_destroy()
169 CL_ASSERT(cl_is_state_valid(p_pool->state)); in cl_qcpool_destroy()
171 if (p_pool->state == CL_INITIALIZED) { in cl_qcpool_destroy()
173 * Assert if the user hasn't put everything back in the pool in cl_qcpool_destroy()
180 CL_ASSERT(cl_qcpool_count(p_pool) == p_pool->num_objects); in cl_qcpool_destroy()
182 /* call the user's destructor for each object in the pool */ in cl_qcpool_destroy()
183 if (p_pool->pfn_dtor) { in cl_qcpool_destroy()
184 while (!cl_is_qlist_empty(&p_pool->free_list)) { in cl_qcpool_destroy()
185 p_pool->pfn_dtor((cl_pool_item_t *) in cl_qcpool_destroy()
186 cl_qlist_remove_head(&p_pool-> in cl_qcpool_destroy()
188 (void *)p_pool->context); in cl_qcpool_destroy()
191 cl_qlist_remove_all(&p_pool->free_list); in cl_qcpool_destroy()
195 while (!cl_is_qlist_empty(&p_pool->alloc_list)) in cl_qcpool_destroy()
196 free(cl_qlist_remove_head(&p_pool->alloc_list)); in cl_qcpool_destroy()
198 if (p_pool->component_sizes) { in cl_qcpool_destroy()
199 free(p_pool->component_sizes); in cl_qcpool_destroy()
200 p_pool->component_sizes = NULL; in cl_qcpool_destroy()
204 p_pool->state = CL_UNINITIALIZED; in cl_qcpool_destroy()
207 cl_status_t cl_qcpool_grow(IN cl_qcpool_t * const p_pool, IN size_t obj_count) in cl_qcpool_grow()
216 CL_ASSERT(p_pool->state == CL_INITIALIZED); in cl_qcpool_grow()
220 if (p_pool->num_objects == p_pool->max_objects) in cl_qcpool_grow()
224 if (obj_count > (p_pool->max_objects - p_pool->num_objects)) in cl_qcpool_grow()
225 obj_count = p_pool->max_objects - p_pool->num_objects; in cl_qcpool_grow()
229 for (i = 0; i < p_pool->num_components; i++) in cl_qcpool_grow()
230 obj_size += p_pool->component_sizes[i]; in cl_qcpool_grow()
243 /* Insert the allocation in our list. */ in cl_qcpool_grow()
244 cl_qlist_insert_tail(&p_pool->alloc_list, (cl_list_item_t *) p_objects); in cl_qcpool_grow()
248 while (obj_count--) { in cl_qcpool_grow()
250 p_pool->p_components[0] = p_objects; in cl_qcpool_grow()
251 for (i = 1; i < p_pool->num_components; i++) { in cl_qcpool_grow()
253 p_pool->p_components[i] = in cl_qcpool_grow()
254 (uint8_t *) p_pool->p_components[i - 1] + in cl_qcpool_grow()
255 p_pool->component_sizes[i - 1]; in cl_qcpool_grow()
262 if (p_pool->pfn_init) { in cl_qcpool_grow()
264 status = p_pool->pfn_init(p_pool->p_components, in cl_qcpool_grow()
265 p_pool->num_components, in cl_qcpool_grow()
266 (void *)p_pool->context, in cl_qcpool_grow()
275 if (p_pool->pfn_dtor) in cl_qcpool_grow()
276 p_pool->pfn_dtor(p_pool_item, in cl_qcpool_grow()
277 (void *)p_pool-> in cl_qcpool_grow()
290 (cl_pool_item_t *) p_pool->p_components[0]; in cl_qcpool_grow()
298 p_pool_item->p_pool = p_pool; in cl_qcpool_grow()
301 /* Insert the new item in the free list, traping for failure. */ in cl_qcpool_grow()
302 cl_qlist_insert_head(&p_pool->free_list, in cl_qcpool_grow()
303 &p_pool_item->list_item); in cl_qcpool_grow()
305 p_pool->num_objects++; in cl_qcpool_grow()
314 cl_pool_item_t *cl_qcpool_get(IN cl_qcpool_t * const p_pool) in cl_qcpool_get()
319 CL_ASSERT(p_pool->state == CL_INITIALIZED); in cl_qcpool_get()
321 if (cl_is_qlist_empty(&p_pool->free_list)) { in cl_qcpool_get()
326 if (!p_pool->grow_size) in cl_qcpool_get()
330 cl_qcpool_grow(p_pool, p_pool->grow_size); in cl_qcpool_get()
335 if (cl_is_qlist_empty(&p_pool->free_list)) in cl_qcpool_get()
339 p_list_item = cl_qlist_remove_head(&p_pool->free_list); in cl_qcpool_get()
341 CL_ASSERT(p_list_item != cl_qlist_end(&p_pool->free_list)); in cl_qcpool_get()
345 cl_pool_item_t *cl_qcpool_get_tail(IN cl_qcpool_t * const p_pool) in cl_qcpool_get_tail()
350 CL_ASSERT(p_pool->state == CL_INITIALIZED); in cl_qcpool_get_tail()
352 if (cl_is_qlist_empty(&p_pool->free_list)) { in cl_qcpool_get_tail()
357 if (!p_pool->grow_size) in cl_qcpool_get_tail()
361 cl_qcpool_grow(p_pool, p_pool->grow_size); in cl_qcpool_get_tail()
366 if (cl_is_qlist_empty(&p_pool->free_list)) in cl_qcpool_get_tail()
370 p_list_item = cl_qlist_remove_tail(&p_pool->free_list); in cl_qcpool_get_tail()
372 CL_ASSERT(p_list_item != cl_qlist_end(&p_pool->free_list)); in cl_qcpool_get_tail()
381 * Callback to translate quick composite to quick grow pool
384 static cl_status_t __cl_qpool_init_cb(IN void **const p_comp_array, in __cl_qpool_init_cb()
385 IN const uint32_t num_components, in __cl_qpool_init_cb()
386 IN void *const context, in __cl_qpool_init_cb()
392 CL_ASSERT(p_pool->pfn_init); in __cl_qpool_init_cb()
397 return (p_pool->pfn_init(p_comp_array[0], (void *)p_pool->context, in __cl_qpool_init_cb()
402 * Callback to translate quick composite to quick grow pool
405 static void __cl_qpool_dtor_cb(IN const cl_pool_item_t * const p_pool_item, in __cl_qpool_dtor_cb()
406 IN void *const context) in __cl_qpool_dtor_cb()
411 CL_ASSERT(p_pool->pfn_dtor); in __cl_qpool_dtor_cb()
413 p_pool->pfn_dtor(p_pool_item, (void *)p_pool->context); in __cl_qpool_dtor_cb()
416 void cl_qpool_construct(IN cl_qpool_t * const p_pool) in cl_qpool_construct()
420 cl_qcpool_construct(&p_pool->qcpool); in cl_qpool_construct()
423 cl_status_t cl_qpool_init(IN cl_qpool_t * const p_pool, in cl_qpool_init()
424 IN const size_t min_size, IN const size_t max_size, in cl_qpool_init()
425 IN const size_t grow_size, in cl_qpool_init()
426 IN const size_t object_size, in cl_qpool_init()
427 IN cl_pfn_qpool_init_t pfn_initializer OPTIONAL, in cl_qpool_init()
428 IN cl_pfn_qpool_dtor_t pfn_destructor OPTIONAL, in cl_qpool_init()
429 IN const void *const context) in cl_qpool_init()
435 p_pool->pfn_init = pfn_initializer; /* may be NULL */ in cl_qpool_init()
436 p_pool->pfn_dtor = pfn_destructor; /* may be NULL */ in cl_qpool_init()
437 p_pool->context = context; in cl_qpool_init()
439 status = cl_qcpool_init(&p_pool->qcpool, min_size, max_size, grow_size, in cl_qpool_init()
449 * IMPLEMENTATION OF COMPOSITE POOL
453 * Callback to translate quick composite to compsite pool
456 static cl_status_t __cl_cpool_init_cb(IN void **const p_comp_array, in __cl_cpool_init_cb()
457 IN const uint32_t num_components, in __cl_cpool_init_cb()
458 IN void *const context, in __cl_cpool_init_cb()
473 *pp_pool_item = &p_pool_obj->pool_item; in __cl_cpool_init_cb()
479 * Set the object pointer in the pool object to point to the first of the in __cl_cpool_init_cb()
482 p_pool_obj->p_object = p_comp_array[0]; in __cl_cpool_init_cb()
485 if (p_pool->pfn_init) { in __cl_cpool_init_cb()
486 status = p_pool->pfn_init(p_comp_array, num_components, in __cl_cpool_init_cb()
487 (void *)p_pool->context); in __cl_cpool_init_cb()
494 * Callback to translate quick composite to composite pool
497 static void __cl_cpool_dtor_cb(IN const cl_pool_item_t * const p_pool_item, in __cl_cpool_dtor_cb()
498 IN void *const context) in __cl_cpool_dtor_cb()
503 CL_ASSERT(p_pool->pfn_dtor); in __cl_cpool_dtor_cb()
504 CL_ASSERT(((cl_pool_obj_t *) p_pool_item)->p_object); in __cl_cpool_dtor_cb()
507 p_pool->pfn_dtor((void *)((cl_pool_obj_t *) p_pool_item)->p_object, in __cl_cpool_dtor_cb()
508 (void *)p_pool->context); in __cl_cpool_dtor_cb()
511 void cl_cpool_construct(IN cl_cpool_t * const p_pool) in cl_cpool_construct()
517 cl_qcpool_construct(&p_pool->qcpool); in cl_cpool_construct()
520 cl_status_t cl_cpool_init(IN cl_cpool_t * const p_pool, in cl_cpool_init()
521 IN const size_t min_size, IN const size_t max_size, in cl_cpool_init()
522 IN const size_t grow_size, in cl_cpool_init()
523 IN size_t * const component_sizes, in cl_cpool_init()
524 IN const uint32_t num_components, in cl_cpool_init()
525 IN cl_pfn_cpool_init_t pfn_initializer OPTIONAL, in cl_cpool_init()
526 IN cl_pfn_cpool_dtor_t pfn_destructor OPTIONAL, in cl_cpool_init()
527 IN const void *const context) in cl_cpool_init()
539 p_pool->pfn_init = pfn_initializer; /* may be NULL */ in cl_cpool_init()
540 p_pool->pfn_dtor = pfn_destructor; /* may be NULL */ in cl_cpool_init()
541 p_pool->context = context; in cl_cpool_init()
543 status = cl_qcpool_init(&p_pool->qcpool, min_size, max_size, grow_size, in cl_cpool_init()
550 component_sizes[0] -= sizeof(cl_pool_obj_t); in cl_cpool_init()
560 * Callback to translate quick composite to grow pool constructor callback.
562 static cl_status_t __cl_pool_init_cb(IN void **const pp_obj, in __cl_pool_init_cb()
563 IN const uint32_t count, in __cl_pool_init_cb()
564 IN void *const context, in __cl_pool_init_cb()
582 *pp_pool_item = &p_pool_obj->pool_item; in __cl_pool_init_cb()
588 * Set the object pointer in the pool item to point to the first of the in __cl_pool_init_cb()
591 p_pool_obj->p_object = *pp_obj; in __cl_pool_init_cb()
594 if (p_pool->pfn_init) in __cl_pool_init_cb()
595 status = p_pool->pfn_init(*pp_obj, (void *)p_pool->context); in __cl_pool_init_cb()
601 * Callback to translate quick composite to grow pool destructor callback.
603 static void __cl_pool_dtor_cb(IN const cl_pool_item_t * const p_pool_item, in __cl_pool_dtor_cb()
604 IN void *const context) in __cl_pool_dtor_cb()
609 CL_ASSERT(p_pool->pfn_dtor); in __cl_pool_dtor_cb()
610 CL_ASSERT(((cl_pool_obj_t *) p_pool_item)->p_object); in __cl_pool_dtor_cb()
613 p_pool->pfn_dtor((void *)((cl_pool_obj_t *) p_pool_item)->p_object, in __cl_pool_dtor_cb()
614 (void *)p_pool->context); in __cl_pool_dtor_cb()
617 void cl_pool_construct(IN cl_pool_t * const p_pool) in cl_pool_construct()
623 cl_qcpool_construct(&p_pool->qcpool); in cl_pool_construct()
626 cl_status_t cl_pool_init(IN cl_pool_t * const p_pool, IN const size_t min_size, in cl_pool_init()
627 IN const size_t max_size, IN const size_t grow_size, in cl_pool_init()
628 IN const size_t object_size, in cl_pool_init()
629 IN cl_pfn_pool_init_t pfn_initializer OPTIONAL, in cl_pool_init()
630 IN cl_pfn_pool_dtor_t pfn_destructor OPTIONAL, in cl_pool_init()
631 IN const void *const context) in cl_pool_init()
642 p_pool->pfn_init = pfn_initializer; /* may be NULL */ in cl_pool_init()
643 p_pool->pfn_dtor = pfn_destructor; /* may be NULL */ in cl_pool_init()
644 p_pool->context = context; in cl_pool_init()
647 * We need an initializer in all cases for quick composite pool, since in cl_pool_init()
650 status = cl_qcpool_init(&p_pool->qcpool, min_size, max_size, grow_size, in cl_pool_init()