Inline implementation of qlockpool functionality used by OpenSM.
authorftillier <ftillier@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 19 Sep 2005 07:04:14 +0000 (07:04 +0000)
committerftillier <ftillier@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 19 Sep 2005 07:04:14 +0000 (07:04 +0000)
Submitted by Yael Kalka (yael@mellanox.co.il)

git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@73 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

inc/complib/cl_qlockpool.h

index 9c45c87..3187dcb 100644 (file)
@@ -1,5 +1,6 @@
 /*\r
  * Copyright (c) 2005 SilverStorm Technologies.  All rights reserved.\r
+ * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.\r
  * Copyright (c) 1996-2003 Intel Corporation. All rights reserved. \r
  *\r
  * This software is available to you under the OpenIB.org BSD license\r
@@ -116,9 +117,14 @@ extern "C"
 *\r
 * SYNOPSIS\r
 */\r
-CL_EXPORT void CL_API\r
+static inline void\r
 cl_qlock_pool_construct(\r
-       IN cl_qlock_pool_t* const p_pool );\r
+       IN cl_qlock_pool_t* const p_pool )\r
+{\r
+       cl_qpool_construct( &p_pool->pool );\r
+       cl_spinlock_construct( &p_pool->lock );\r
+}\r
+\r
 /*\r
 * PARAMETERS\r
 *      p_pool\r
@@ -148,9 +154,25 @@ cl_qlock_pool_construct(
 *\r
 * SYNOPSIS\r
 */\r
-CL_EXPORT void CL_API\r
+static inline void\r
 cl_qlock_pool_destroy(\r
-       IN cl_qlock_pool_t* const p_pool );\r
+       IN cl_qlock_pool_t* const p_pool )\r
+{\r
+       /*\r
+               If the pool has already been put into use, grab the lock\r
+               to sync with other threads before we blow everything away.\r
+       */\r
+       if( cl_is_qpool_inited( &p_pool->pool ) )\r
+       {\r
+               cl_spinlock_acquire( &p_pool->lock );\r
+               cl_qpool_destroy( &p_pool->pool );\r
+               cl_spinlock_release( &p_pool->lock );\r
+       }\r
+       else\r
+               cl_qpool_destroy( &p_pool->pool );\r
+\r
+       cl_spinlock_destroy( &p_pool->lock );\r
+}\r
 /*\r
 * PARAMETERS\r
 *      p_pool\r
@@ -179,7 +201,7 @@ cl_qlock_pool_destroy(
 *\r
 * SYNOPSIS\r
 */\r
-CL_EXPORT cl_status_t CL_API\r
+static inline cl_status_t\r
 cl_qlock_pool_init(\r
        IN cl_qlock_pool_t*                     const p_pool,\r
        IN      const size_t                    min_size,\r
@@ -188,7 +210,21 @@ cl_qlock_pool_init(
        IN      const size_t                    object_size,\r
        IN      cl_pfn_qpool_init_t             pfn_initializer OPTIONAL,\r
        IN      cl_pfn_qpool_dtor_t             pfn_destructor OPTIONAL,\r
-       IN      const void* const               context );\r
+       IN      const void* const               context )\r
+{\r
+       cl_status_t status;\r
+\r
+       cl_qlock_pool_construct( p_pool );\r
+\r
+       status = cl_spinlock_init( &p_pool->lock );\r
+       if( status )\r
+               return( status );\r
+\r
+       status = cl_qpool_init( &p_pool->pool, min_size, max_size, grow_size,\r
+                       object_size, pfn_initializer, pfn_destructor, context );\r
+\r
+       return( status );\r
+}\r
 /*\r
 * PARAMETERS\r
 *      p_pool\r
@@ -256,9 +292,17 @@ cl_qlock_pool_init(
 *\r
 * SYNOPSIS\r
 */\r
-CL_EXPORT cl_pool_item_t* CL_API\r
+static inline cl_pool_item_t*\r
 cl_qlock_pool_get(\r
-       IN cl_qlock_pool_t* const p_pool );\r
+       IN cl_qlock_pool_t* const p_pool )\r
+{\r
+       cl_pool_item_t* p_item;\r
+       cl_spinlock_acquire( &p_pool->lock );\r
+       p_item = cl_qpool_get( &p_pool->pool );\r
+       cl_spinlock_release( &p_pool->lock );\r
+       return( p_item );\r
+}\r
+\r
 /*\r
 * PARAMETERS\r
 *      p_pool\r
@@ -288,10 +332,15 @@ cl_qlock_pool_get(
 *\r
 * SYNOPSIS\r
 */\r
-CL_EXPORT void CL_API\r
+static inline void\r
 cl_qlock_pool_put(\r
        IN cl_qlock_pool_t* const p_pool,\r
-       IN cl_pool_item_t* const p_item );\r
+       IN cl_pool_item_t* const p_item )\r
+{\r
+       cl_spinlock_acquire( &p_pool->lock );\r
+       cl_qpool_put( &p_pool->pool, p_item );\r
+       cl_spinlock_release( &p_pool->lock );\r
+}\r
 /*\r
 * PARAMETERS\r
 *      p_pool\r