|
Packit |
13e616 |
/*
|
|
Packit |
13e616 |
* Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved.
|
|
Packit |
13e616 |
* Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
|
|
Packit |
13e616 |
* Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* This software is available to you under a choice of one of two
|
|
Packit |
13e616 |
* licenses. You may choose to be licensed under the terms of the GNU
|
|
Packit |
13e616 |
* General Public License (GPL) Version 2, available from the file
|
|
Packit |
13e616 |
* COPYING in the main directory of this source tree, or the
|
|
Packit |
13e616 |
* OpenIB.org BSD license below:
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* Redistribution and use in source and binary forms, with or
|
|
Packit |
13e616 |
* without modification, are permitted provided that the following
|
|
Packit |
13e616 |
* conditions are met:
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* - Redistributions of source code must retain the above
|
|
Packit |
13e616 |
* copyright notice, this list of conditions and the following
|
|
Packit |
13e616 |
* disclaimer.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* - Redistributions in binary form must reproduce the above
|
|
Packit |
13e616 |
* copyright notice, this list of conditions and the following
|
|
Packit |
13e616 |
* disclaimer in the documentation and/or other materials
|
|
Packit |
13e616 |
* provided with the distribution.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
Packit |
13e616 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
Packit |
13e616 |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
Packit |
13e616 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
Packit |
13e616 |
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
Packit |
13e616 |
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
Packit |
13e616 |
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
Packit |
13e616 |
* SOFTWARE.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
*/
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
/*
|
|
Packit |
13e616 |
* Abstract:
|
|
Packit |
13e616 |
* Declaration of the composite pool.
|
|
Packit |
13e616 |
* The composite pool managers a pool of composite objects. A composite object is an object
|
|
Packit |
13e616 |
* that is made of multiple sub objects.
|
|
Packit |
13e616 |
* The pool can grow to meet demand, limited only by system memory.
|
|
Packit |
13e616 |
*/
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
#ifndef _CL_COMP_POOL_H_
|
|
Packit |
13e616 |
#define _CL_COMP_POOL_H_
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
#include <complib/cl_qcomppool.h>
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
#ifdef __cplusplus
|
|
Packit |
13e616 |
# define BEGIN_C_DECLS extern "C" {
|
|
Packit |
13e616 |
# define END_C_DECLS }
|
|
Packit |
13e616 |
#else /* !__cplusplus */
|
|
Packit |
13e616 |
# define BEGIN_C_DECLS
|
|
Packit |
13e616 |
# define END_C_DECLS
|
|
Packit |
13e616 |
#endif /* __cplusplus */
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
BEGIN_C_DECLS
|
|
Packit |
13e616 |
/****h* Component Library/Composite Pool
|
|
Packit |
13e616 |
* NAME
|
|
Packit |
13e616 |
* Composite Pool
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* DESCRIPTION
|
|
Packit |
13e616 |
* The Composite Pool provides a self-contained and self-sustaining pool of
|
|
Packit |
13e616 |
* user defined composite objects.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* A composite object is an object that is composed of one or more
|
|
Packit |
13e616 |
* sub-objects, each of which needs to be treated separately for
|
|
Packit |
13e616 |
* initialization. Objects can be retrieved from the pool as long as there
|
|
Packit |
13e616 |
* is memory in the system.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* To aid in object oriented design, the composite pool provides the user
|
|
Packit |
13e616 |
* the ability to specify callbacks that are invoked for each object for
|
|
Packit |
13e616 |
* construction, initialization, and destruction. Constructor and destructor
|
|
Packit |
13e616 |
* callback functions may not fail.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* A composite pool does not return memory to the system as the user returns
|
|
Packit |
13e616 |
* objects to the pool. The only method of returning memory to the system is
|
|
Packit |
13e616 |
* to destroy the pool.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* The composite pool functions operates on a cl_cpool_t structure which
|
|
Packit |
13e616 |
* should be treated as opaque and should be manipulated only through the
|
|
Packit |
13e616 |
* provided functions.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SEE ALSO
|
|
Packit |
13e616 |
* Structures:
|
|
Packit |
13e616 |
* cl_cpool_t
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* Callbacks:
|
|
Packit |
13e616 |
* cl_pfn_cpool_init_t, cl_pfn_cpool_dtor_t
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* Initialization/Destruction:
|
|
Packit |
13e616 |
* cl_cpool_construct, cl_cpool_init, cl_cpool_destroy
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* Manipulation:
|
|
Packit |
13e616 |
* cl_cpool_get, cl_cpool_put, cl_cpool_grow
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* Attributes:
|
|
Packit |
13e616 |
* cl_is_cpool_inited, cl_cpool_count
|
|
Packit |
13e616 |
*********/
|
|
Packit |
13e616 |
/****d* Component Library: Composite Pool/cl_pfn_cpool_init_t
|
|
Packit |
13e616 |
* NAME
|
|
Packit |
13e616 |
* cl_pfn_cpool_init_t
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* DESCRIPTION
|
|
Packit |
13e616 |
* The cl_pfn_cpool_init_t function type defines the prototype for
|
|
Packit |
13e616 |
* functions used as initializers for objects being allocated by a
|
|
Packit |
13e616 |
* composite pool.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SYNOPSIS
|
|
Packit |
13e616 |
*/
|
|
Packit |
13e616 |
typedef cl_status_t
|
|
Packit |
13e616 |
(*cl_pfn_cpool_init_t) (IN void **const p_comp_array,
|
|
Packit |
13e616 |
IN const uint32_t num_components, IN void *context);
|
|
Packit |
13e616 |
/*
|
|
Packit |
13e616 |
* PARAMETERS
|
|
Packit |
13e616 |
* p_comp_array
|
|
Packit |
13e616 |
* [in] Pointer to the first entry in an array of pointers, each of
|
|
Packit |
13e616 |
* which points to a component that makes up a composite object.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* num_components
|
|
Packit |
13e616 |
* [in] Number of components in the composite array.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* context
|
|
Packit |
13e616 |
* [in] Context provided in a call to cl_cpool_init.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* RETURN VALUES
|
|
Packit |
13e616 |
* Return CL_SUCCESS to indicates that initialization of the object
|
|
Packit |
13e616 |
* was successful and that initialization of further objects may continue.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* Other cl_status_t values will be returned by cl_cpool_init
|
|
Packit |
13e616 |
* and cl_cpool_grow.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* NOTES
|
|
Packit |
13e616 |
* This function type is provided as function prototype reference for
|
|
Packit |
13e616 |
* the function provided by the user as an optional parameter to the
|
|
Packit |
13e616 |
* cl_cpool_init function.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* The initializer is invoked once per allocated object, allowing the user
|
|
Packit |
13e616 |
* to chain components to form a composite object and perform any necessary
|
|
Packit |
13e616 |
* initialization. Returning a status other than CL_SUCCESS aborts a grow
|
|
Packit |
13e616 |
* operation, initiated either through cl_cpool_init or cl_cpool_grow, and
|
|
Packit |
13e616 |
* causes the initiating function to fail. Any non-CL_SUCCESS status will
|
|
Packit |
13e616 |
* be returned by the function that initiated the grow operation.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* All memory for the requested number of components is pre-allocated.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* When later performing a cl_cpool_get call, the return value is a pointer
|
|
Packit |
13e616 |
* to the first component.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SEE ALSO
|
|
Packit |
13e616 |
* Composite Pool, cl_cpool_init, cl_cpool_grow
|
|
Packit |
13e616 |
*********/
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
/****d* Component Library: Composite Pool/cl_pfn_cpool_dtor_t
|
|
Packit |
13e616 |
* NAME
|
|
Packit |
13e616 |
* cl_pfn_cpool_dtor_t
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* DESCRIPTION
|
|
Packit |
13e616 |
* The cl_pfn_cpool_dtor_t function type defines the prototype for
|
|
Packit |
13e616 |
* functions used as destructor for objects being deallocated by a
|
|
Packit |
13e616 |
* composite pool.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SYNOPSIS
|
|
Packit |
13e616 |
*/
|
|
Packit |
13e616 |
typedef void
|
|
Packit |
13e616 |
(*cl_pfn_cpool_dtor_t) (IN void *const p_object, IN void *context);
|
|
Packit |
13e616 |
/*
|
|
Packit |
13e616 |
* PARAMETERS
|
|
Packit |
13e616 |
* p_object
|
|
Packit |
13e616 |
* [in] Pointer to an object to destruct.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* context
|
|
Packit |
13e616 |
* [in] Context provided in the call to cl_cpool_init.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* RETURN VALUE
|
|
Packit |
13e616 |
* This function does not return a value.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* NOTES
|
|
Packit |
13e616 |
* This function type is provided as function prototype reference for
|
|
Packit |
13e616 |
* the function provided by the user as an optional parameter to the
|
|
Packit |
13e616 |
* cl_cpool_init function.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* The destructor is invoked once per allocated object, allowing the user
|
|
Packit |
13e616 |
* to perform any necessary cleanup. Users should not attempt to deallocate
|
|
Packit |
13e616 |
* the memory for the composite object, as the composite pool manages
|
|
Packit |
13e616 |
* object allocation and deallocation.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SEE ALSO
|
|
Packit |
13e616 |
* Composite Pool, cl_cpool_init
|
|
Packit |
13e616 |
*********/
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
/****s* Component Library: Composite Pool/cl_cpool_t
|
|
Packit |
13e616 |
* NAME
|
|
Packit |
13e616 |
* cl_cpool_t
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* DESCRIPTION
|
|
Packit |
13e616 |
* Composite pool structure.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* The cl_cpool_t structure should be treated as opaque and should be
|
|
Packit |
13e616 |
* manipulated only through the provided functions.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SYNOPSIS
|
|
Packit |
13e616 |
*/
|
|
Packit |
13e616 |
typedef struct _cl_cpool {
|
|
Packit |
13e616 |
cl_qcpool_t qcpool;
|
|
Packit |
13e616 |
cl_pfn_cpool_init_t pfn_init;
|
|
Packit |
13e616 |
cl_pfn_cpool_dtor_t pfn_dtor;
|
|
Packit |
13e616 |
const void *context;
|
|
Packit |
13e616 |
} cl_cpool_t;
|
|
Packit |
13e616 |
/*
|
|
Packit |
13e616 |
* FIELDS
|
|
Packit |
13e616 |
* qcpool
|
|
Packit |
13e616 |
* Quick composite pool that manages all objects.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* pfn_init
|
|
Packit |
13e616 |
* Pointer to the user's initializer callback, used by the pool
|
|
Packit |
13e616 |
* to translate the quick composite pool's initializer callback to
|
|
Packit |
13e616 |
* a composite pool initializer callback.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* pfn_dtor
|
|
Packit |
13e616 |
* Pointer to the user's destructor callback, used by the pool
|
|
Packit |
13e616 |
* to translate the quick composite pool's destructor callback to
|
|
Packit |
13e616 |
* a composite pool destructor callback.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* context
|
|
Packit |
13e616 |
* User's provided context for callback functions, used by the pool
|
|
Packit |
13e616 |
* to when invoking callbacks.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SEE ALSO
|
|
Packit |
13e616 |
* Composite Pool
|
|
Packit |
13e616 |
*********/
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
/****f* Component Library: Composite Pool/cl_cpool_construct
|
|
Packit |
13e616 |
* NAME
|
|
Packit |
13e616 |
* cl_cpool_construct
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* DESCRIPTION
|
|
Packit |
13e616 |
* The cl_cpool_construct function constructs a composite pool.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SYNOPSIS
|
|
Packit |
13e616 |
*/
|
|
Packit |
13e616 |
void cl_cpool_construct(IN cl_cpool_t * const p_pool);
|
|
Packit |
13e616 |
/*
|
|
Packit |
13e616 |
* PARAMETERS
|
|
Packit |
13e616 |
* p_pool
|
|
Packit |
13e616 |
* [in] Pointer to a cl_cpool_t structure whose state to initialize.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* RETURN VALUE
|
|
Packit |
13e616 |
* This function does not return a value.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* NOTES
|
|
Packit |
13e616 |
* Allows calling cl_pool_init, cl_cpool_destroy, cl_is_cpool_inited.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* Calling cl_cpool_construct is a prerequisite to calling any other
|
|
Packit |
13e616 |
* composite pool function except cl_cpool_init.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SEE ALSO
|
|
Packit |
13e616 |
* Composite Pool, cl_cpool_init, cl_cpool_destroy, cl_is_cpool_inited
|
|
Packit |
13e616 |
*********/
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
/****f* Component Library: Composite Pool/cl_is_cpool_inited
|
|
Packit |
13e616 |
* NAME
|
|
Packit |
13e616 |
* cl_is_cpool_inited
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* DESCRIPTION
|
|
Packit |
13e616 |
* The cl_is_cpool_inited function returns whether a composite pool was
|
|
Packit |
13e616 |
* successfully initialized.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SYNOPSIS
|
|
Packit |
13e616 |
*/
|
|
Packit |
13e616 |
static inline boolean_t cl_is_cpool_inited(IN const cl_cpool_t * const p_pool)
|
|
Packit |
13e616 |
{
|
|
Packit |
13e616 |
/* CL_ASSERT that a non-null pointer is provided. */
|
|
Packit |
13e616 |
CL_ASSERT(p_pool);
|
|
Packit |
13e616 |
return (cl_is_qcpool_inited(&p_pool->qcpool));
|
|
Packit |
13e616 |
}
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
/*
|
|
Packit |
13e616 |
* PARAMETERS
|
|
Packit |
13e616 |
* p_pool
|
|
Packit |
13e616 |
* [in] Pointer to a cl_cpool_t structure whose initialization state
|
|
Packit |
13e616 |
* to check.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* RETURN VALUES
|
|
Packit |
13e616 |
* TRUE if the composite pool was initialized successfully.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* FALSE otherwise.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* NOTES
|
|
Packit |
13e616 |
* Allows checking the state of a composite pool to determine if invoking
|
|
Packit |
13e616 |
* member functions is appropriate.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SEE ALSO
|
|
Packit |
13e616 |
* Composite Pool
|
|
Packit |
13e616 |
*********/
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
/****f* Component Library: Composite Pool/cl_cpool_init
|
|
Packit |
13e616 |
* NAME
|
|
Packit |
13e616 |
* cl_cpool_init
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* DESCRIPTION
|
|
Packit |
13e616 |
* The cl_cpool_init function initializes a composite pool for use.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SYNOPSIS
|
|
Packit |
13e616 |
*/
|
|
Packit |
13e616 |
cl_status_t
|
|
Packit |
13e616 |
cl_cpool_init(IN cl_cpool_t * const p_pool,
|
|
Packit |
13e616 |
IN const size_t min_size,
|
|
Packit |
13e616 |
IN const size_t max_size,
|
|
Packit |
13e616 |
IN const size_t grow_size,
|
|
Packit |
13e616 |
IN size_t * const component_sizes,
|
|
Packit |
13e616 |
IN const uint32_t num_components,
|
|
Packit |
13e616 |
IN cl_pfn_cpool_init_t pfn_initializer OPTIONAL,
|
|
Packit |
13e616 |
IN cl_pfn_cpool_dtor_t pfn_destructor OPTIONAL,
|
|
Packit |
13e616 |
IN const void *const context);
|
|
Packit |
13e616 |
/*
|
|
Packit |
13e616 |
* PARAMETERS
|
|
Packit |
13e616 |
* p_pool
|
|
Packit |
13e616 |
* [in] Pointer to a cl_cpool_t structure to initialize.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* min_size
|
|
Packit |
13e616 |
* [in] Minimum number of objects that the pool should support. All
|
|
Packit |
13e616 |
* necessary allocations to allow storing the minimum number of items
|
|
Packit |
13e616 |
* are performed at initialization time, and all necessary callbacks
|
|
Packit |
13e616 |
* successfully invoked.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* max_size
|
|
Packit |
13e616 |
* [in] Maximum number of objects to which the pool is allowed to grow.
|
|
Packit |
13e616 |
* A value of zero specifies no maximum.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* grow_size
|
|
Packit |
13e616 |
* [in] Number of objects to allocate when incrementally growing the pool.
|
|
Packit |
13e616 |
* A value of zero disables automatic growth.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* component_sizes
|
|
Packit |
13e616 |
* [in] Pointer to the first entry in an array of sizes describing,
|
|
Packit |
13e616 |
* in order, the sizes of the components that make up a composite object.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* num_components
|
|
Packit |
13e616 |
* [in] Number of components that make up a composite object.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* pfn_initializer
|
|
Packit |
13e616 |
* [in] Initialization callback to invoke for every new object when
|
|
Packit |
13e616 |
* growing the pool. This parameter may be NULL only if the objects
|
|
Packit |
13e616 |
* stored in the composite pool consist of only one component.
|
|
Packit |
13e616 |
* See the cl_pfn_cpool_init function type declaration for details
|
|
Packit |
13e616 |
* about the callback function.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* pfn_destructor
|
|
Packit |
13e616 |
* [in] Destructor callback to invoke for every object before memory for
|
|
Packit |
13e616 |
* that object is freed. This parameter is optional and may be NULL.
|
|
Packit |
13e616 |
* See the cl_pfn_cpool_dtor function type declaration for details
|
|
Packit |
13e616 |
* about the callback function.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* context
|
|
Packit |
13e616 |
* [in] Value to pass to the callback functions to provide context.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* RETURN VALUES
|
|
Packit |
13e616 |
* CL_SUCCESS if the composite pool was initialized successfully.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* CL_INSUFFICIENT_MEMORY if there was not enough memory to initialize the
|
|
Packit |
13e616 |
* composite pool.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* CL_INVALID_SETTING if a NULL constructor was provided for composite objects
|
|
Packit |
13e616 |
* consisting of more than one component. Also returns CL_INVALID_SETTING if
|
|
Packit |
13e616 |
* the maximum size is non-zero and less than the minimum size.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* Other cl_status_t value returned by optional initialization callback function
|
|
Packit |
13e616 |
* specified by the pfn_initializer parameter.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* NOTES
|
|
Packit |
13e616 |
* cl_cpool_init initializes, and if necessary, grows the pool to
|
|
Packit |
13e616 |
* the capacity desired.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SEE ALSO
|
|
Packit |
13e616 |
* Composite Pool, cl_cpool_construct, cl_cpool_destroy,
|
|
Packit |
13e616 |
* cl_cpool_get, cl_cpool_put, cl_cpool_grow,
|
|
Packit |
13e616 |
* cl_cpool_count, cl_pfn_cpool_ctor_t, cl_pfn_cpool_init_t,
|
|
Packit |
13e616 |
* cl_pfn_cpool_dtor_t
|
|
Packit |
13e616 |
*********/
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
/****f* Component Library: Composite Pool/cl_cpool_destroy
|
|
Packit |
13e616 |
* NAME
|
|
Packit |
13e616 |
* cl_cpool_destroy
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* DESCRIPTION
|
|
Packit |
13e616 |
* The cl_cpool_destroy function destroys a composite pool.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SYNOPSIS
|
|
Packit |
13e616 |
*/
|
|
Packit |
13e616 |
static inline void cl_cpool_destroy(IN cl_cpool_t * const p_pool)
|
|
Packit |
13e616 |
{
|
|
Packit |
13e616 |
CL_ASSERT(p_pool);
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
cl_qcpool_destroy(&p_pool->qcpool);
|
|
Packit |
13e616 |
}
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
/*
|
|
Packit |
13e616 |
* PARAMETERS
|
|
Packit |
13e616 |
* p_pool
|
|
Packit |
13e616 |
* [in] Pointer to a cl_cpool_t structure to destroy.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* RETURN VALUE
|
|
Packit |
13e616 |
* This function does not return a value.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* NOTES
|
|
Packit |
13e616 |
* All memory allocated for composite objects is freed. The destructor
|
|
Packit |
13e616 |
* callback, if any, will be invoked for every allocated object. Further
|
|
Packit |
13e616 |
* operations on the composite pool should not be attempted after
|
|
Packit |
13e616 |
* cl_cpool_destroy is invoked.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* This function should only be called after a call to cl_cpool_construct.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* In a debug build, cl_cpool_destroy asserts that all objects are in
|
|
Packit |
13e616 |
* the pool.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SEE ALSO
|
|
Packit |
13e616 |
* Composite Pool, cl_cpool_construct, cl_cpool_init
|
|
Packit |
13e616 |
*********/
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
/****f* Component Library: Composite Pool/cl_cpool_count
|
|
Packit |
13e616 |
* NAME
|
|
Packit |
13e616 |
* cl_cpool_count
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* DESCRIPTION
|
|
Packit |
13e616 |
* The cl_cpool_count function returns the number of available objects
|
|
Packit |
13e616 |
* in a composite pool.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SYNOPSIS
|
|
Packit |
13e616 |
*/
|
|
Packit |
13e616 |
static inline size_t cl_cpool_count(IN cl_cpool_t * const p_pool)
|
|
Packit |
13e616 |
{
|
|
Packit |
13e616 |
CL_ASSERT(p_pool);
|
|
Packit |
13e616 |
return (cl_qcpool_count(&p_pool->qcpool));
|
|
Packit |
13e616 |
}
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
/*
|
|
Packit |
13e616 |
* PARAMETERS
|
|
Packit |
13e616 |
* p_pool
|
|
Packit |
13e616 |
* [in] Pointer to a cl_cpool_t structure for which the number of
|
|
Packit |
13e616 |
* available objects is requested.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* RETURN VALUE
|
|
Packit |
13e616 |
* Returns the number of objects available in the specified
|
|
Packit |
13e616 |
* composite pool.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SEE ALSO
|
|
Packit |
13e616 |
* Composite Pool
|
|
Packit |
13e616 |
*********/
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
/****f* Component Library: Composite Pool/cl_cpool_get
|
|
Packit |
13e616 |
* NAME
|
|
Packit |
13e616 |
* cl_cpool_get
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* DESCRIPTION
|
|
Packit |
13e616 |
* The cl_cpool_get function retrieves an object from a
|
|
Packit |
13e616 |
* composite pool.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SYNOPSIS
|
|
Packit |
13e616 |
*/
|
|
Packit |
13e616 |
static inline void *cl_cpool_get(IN cl_cpool_t * const p_pool)
|
|
Packit |
13e616 |
{
|
|
Packit |
13e616 |
cl_pool_obj_t *p_pool_obj;
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
CL_ASSERT(p_pool);
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
p_pool_obj = (cl_pool_obj_t *) cl_qcpool_get(&p_pool->qcpool);
|
|
Packit |
13e616 |
if (!p_pool_obj)
|
|
Packit |
13e616 |
return (NULL);
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
CL_ASSERT(p_pool_obj->p_object);
|
|
Packit |
13e616 |
return ((void *)p_pool_obj->p_object);
|
|
Packit |
13e616 |
}
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
/*
|
|
Packit |
13e616 |
* PARAMETERS
|
|
Packit |
13e616 |
* p_pool
|
|
Packit |
13e616 |
* [in] Pointer to a cl_cpool_t structure from which to retrieve
|
|
Packit |
13e616 |
* an object.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* RETURN VALUES
|
|
Packit |
13e616 |
* Returns a pointer to the first component of a composite object.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* Returns NULL if the pool is empty and can not be grown automatically.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* NOTES
|
|
Packit |
13e616 |
* cl_cpool_get returns the object at the head of the pool. If the pool is
|
|
Packit |
13e616 |
* empty, it is automatically grown to accommodate this request unless the
|
|
Packit |
13e616 |
* grow_size parameter passed to the cl_cpool_init function was zero.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SEE ALSO
|
|
Packit |
13e616 |
* Composite Pool, cl_cpool_get_tail, cl_cpool_put, cl_cpool_grow,
|
|
Packit |
13e616 |
* cl_cpool_count
|
|
Packit |
13e616 |
*********/
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
/****f* Component Library: Composite Pool/cl_cpool_put
|
|
Packit |
13e616 |
* NAME
|
|
Packit |
13e616 |
* cl_cpool_put
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* DESCRIPTION
|
|
Packit |
13e616 |
* The cl_cpool_put function returns an object to a composite pool.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SYNOPSIS
|
|
Packit |
13e616 |
*/
|
|
Packit |
13e616 |
static inline void
|
|
Packit |
13e616 |
cl_cpool_put(IN cl_cpool_t * const p_pool, IN void *const p_object)
|
|
Packit |
13e616 |
{
|
|
Packit |
13e616 |
cl_pool_obj_t *p_pool_obj;
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
CL_ASSERT(p_pool);
|
|
Packit |
13e616 |
CL_ASSERT(p_object);
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
/* Calculate the offset to the list object representing this object. */
|
|
Packit |
13e616 |
p_pool_obj = (cl_pool_obj_t *)
|
|
Packit |
13e616 |
(((uint8_t *) p_object) - sizeof(cl_pool_obj_t));
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
/* good sanity check */
|
|
Packit |
13e616 |
CL_ASSERT(p_pool_obj->p_object == p_object);
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
cl_qcpool_put(&p_pool->qcpool, &p_pool_obj->pool_item);
|
|
Packit |
13e616 |
}
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
/*
|
|
Packit |
13e616 |
* PARAMETERS
|
|
Packit |
13e616 |
* p_pool
|
|
Packit |
13e616 |
* [in] Pointer to a cl_cpool_t structure to which to return
|
|
Packit |
13e616 |
* an object.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* p_object
|
|
Packit |
13e616 |
* [in] Pointer to the first component of an object to return to the pool.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* RETURN VALUE
|
|
Packit |
13e616 |
* This function does not return a value.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* NOTES
|
|
Packit |
13e616 |
* cl_cpool_put places the returned object at the head of the pool.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* The object specified by the p_object parameter must have been
|
|
Packit |
13e616 |
* retrieved from the pool by a previous call to cl_cpool_get.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SEE ALSO
|
|
Packit |
13e616 |
* Composite Pool, cl_cpool_put_tail, cl_cpool_get
|
|
Packit |
13e616 |
*********/
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
/****f* Component Library: Composite Pool/cl_cpool_grow
|
|
Packit |
13e616 |
* NAME
|
|
Packit |
13e616 |
* cl_cpool_grow
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* DESCRIPTION
|
|
Packit |
13e616 |
* The cl_cpool_grow function grows a composite pool by
|
|
Packit |
13e616 |
* the specified number of objects.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SYNOPSIS
|
|
Packit |
13e616 |
*/
|
|
Packit |
13e616 |
static inline cl_status_t
|
|
Packit |
13e616 |
cl_cpool_grow(IN cl_cpool_t * const p_pool, IN const uint32_t obj_count)
|
|
Packit |
13e616 |
{
|
|
Packit |
13e616 |
CL_ASSERT(p_pool);
|
|
Packit |
13e616 |
return (cl_qcpool_grow(&p_pool->qcpool, obj_count));
|
|
Packit |
13e616 |
}
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
/*
|
|
Packit |
13e616 |
* PARAMETERS
|
|
Packit |
13e616 |
* p_pool
|
|
Packit |
13e616 |
* [in] Pointer to a cl_cpool_t structure whose capacity to grow.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* obj_count
|
|
Packit |
13e616 |
* [in] Number of objects by which to grow the pool.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* RETURN VALUES
|
|
Packit |
13e616 |
* CL_SUCCESS if the composite pool grew successfully.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* CL_INSUFFICIENT_MEMORY if there was not enough memory to grow the
|
|
Packit |
13e616 |
* composite pool.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* cl_status_t value returned by optional initialization callback function
|
|
Packit |
13e616 |
* specified by the pfn_initializer parameter passed to the
|
|
Packit |
13e616 |
* cl_cpool_init function.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* NOTES
|
|
Packit |
13e616 |
* It is not necessary to call cl_cpool_grow if the pool is
|
|
Packit |
13e616 |
* configured to grow automatically.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SEE ALSO
|
|
Packit |
13e616 |
* Composite Pool
|
|
Packit |
13e616 |
*********/
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
END_C_DECLS
|
|
Packit |
13e616 |
#endif /* _CL_COMP_POOL_H_ */
|