From: ftillier Date: Mon, 19 Sep 2005 07:04:14 +0000 (+0000) Subject: Inline implementation of qlockpool functionality used by OpenSM. X-Git-Url: https://openfabrics.org/gitweb/?a=commitdiff_plain;h=9434b96f092fdce7c25c60bf4ae516ddcf87def4;p=~shefty%2Frdma-win.git Inline implementation of qlockpool functionality used by OpenSM. Submitted by Yael Kalka (yael@mellanox.co.il) git-svn-id: svn://openib.tc.cornell.edu/gen1@73 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86 --- diff --git a/trunk/inc/complib/cl_qlockpool.h b/trunk/inc/complib/cl_qlockpool.h index 9c45c872..3187dcb6 100644 --- a/trunk/inc/complib/cl_qlockpool.h +++ b/trunk/inc/complib/cl_qlockpool.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2005 SilverStorm Technologies. All rights reserved. + * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved. * Copyright (c) 1996-2003 Intel Corporation. All rights reserved. * * This software is available to you under the OpenIB.org BSD license @@ -116,9 +117,14 @@ extern "C" * * SYNOPSIS */ -CL_EXPORT void CL_API +static inline void cl_qlock_pool_construct( - IN cl_qlock_pool_t* const p_pool ); + IN cl_qlock_pool_t* const p_pool ) +{ + cl_qpool_construct( &p_pool->pool ); + cl_spinlock_construct( &p_pool->lock ); +} + /* * PARAMETERS * p_pool @@ -148,9 +154,25 @@ cl_qlock_pool_construct( * * SYNOPSIS */ -CL_EXPORT void CL_API +static inline void cl_qlock_pool_destroy( - IN cl_qlock_pool_t* const p_pool ); + IN cl_qlock_pool_t* const p_pool ) +{ + /* + If the pool has already been put into use, grab the lock + to sync with other threads before we blow everything away. + */ + if( cl_is_qpool_inited( &p_pool->pool ) ) + { + cl_spinlock_acquire( &p_pool->lock ); + cl_qpool_destroy( &p_pool->pool ); + cl_spinlock_release( &p_pool->lock ); + } + else + cl_qpool_destroy( &p_pool->pool ); + + cl_spinlock_destroy( &p_pool->lock ); +} /* * PARAMETERS * p_pool @@ -179,7 +201,7 @@ cl_qlock_pool_destroy( * * SYNOPSIS */ -CL_EXPORT cl_status_t CL_API +static inline cl_status_t cl_qlock_pool_init( IN cl_qlock_pool_t* const p_pool, IN const size_t min_size, @@ -188,7 +210,21 @@ cl_qlock_pool_init( IN const size_t object_size, IN cl_pfn_qpool_init_t pfn_initializer OPTIONAL, IN cl_pfn_qpool_dtor_t pfn_destructor OPTIONAL, - IN const void* const context ); + IN const void* const context ) +{ + cl_status_t status; + + cl_qlock_pool_construct( p_pool ); + + status = cl_spinlock_init( &p_pool->lock ); + if( status ) + return( status ); + + status = cl_qpool_init( &p_pool->pool, min_size, max_size, grow_size, + object_size, pfn_initializer, pfn_destructor, context ); + + return( status ); +} /* * PARAMETERS * p_pool @@ -256,9 +292,17 @@ cl_qlock_pool_init( * * SYNOPSIS */ -CL_EXPORT cl_pool_item_t* CL_API +static inline cl_pool_item_t* cl_qlock_pool_get( - IN cl_qlock_pool_t* const p_pool ); + IN cl_qlock_pool_t* const p_pool ) +{ + cl_pool_item_t* p_item; + cl_spinlock_acquire( &p_pool->lock ); + p_item = cl_qpool_get( &p_pool->pool ); + cl_spinlock_release( &p_pool->lock ); + return( p_item ); +} + /* * PARAMETERS * p_pool @@ -288,10 +332,15 @@ cl_qlock_pool_get( * * SYNOPSIS */ -CL_EXPORT void CL_API +static inline void cl_qlock_pool_put( IN cl_qlock_pool_t* const p_pool, - IN cl_pool_item_t* const p_item ); + IN cl_pool_item_t* const p_item ) +{ + cl_spinlock_acquire( &p_pool->lock ); + cl_qpool_put( &p_pool->pool, p_item ); + cl_spinlock_release( &p_pool->lock ); +} /* * PARAMETERS * p_pool