[IBAL] add ref count to ioc
authorsleybo <sleybo@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Tue, 28 Nov 2006 18:32:06 +0000 (18:32 +0000)
committersleybo <sleybo@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Tue, 28 Nov 2006 18:32:06 +0000 (18:32 +0000)
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@553 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

core/al/kernel/al_ioc_pnp.c

index cf72009..343a0fd 100644 (file)
@@ -272,6 +272,7 @@ typedef struct _iou_ioc
        ib_ioc_profile_t                profile;\r
        uint8_t                                 num_valid_entries;\r
        ib_svc_entry_t                  *p_svc_entries;\r
+       atomic32_t                              ref_cnt;\r
 \r
 }      iou_ioc_t;\r
 #pragma warning(default:4324)\r
@@ -1052,13 +1053,15 @@ __get_ioc(
 \r
        p_ioc = PARENT_STRUCT( PARENT_STRUCT( p_item, cl_map_item_t, pool_item ),\r
                iou_ioc_t, map_item );\r
+       \r
+       CL_ASSERT( !p_ioc->ref_cnt );\r
 \r
        CL_ASSERT( !(ioc_slot >> 8) );\r
        p_ioc->slot = (uint8_t)ioc_slot;\r
        p_ioc->profile = *p_profile;\r
        p_ioc->num_valid_entries = 0;\r
        p_ioc->p_svc_entries = p_svc_entries;\r
-\r
+       cl_atomic_inc( &p_ioc->ref_cnt );\r
        return p_ioc;\r
 }\r
 \r
@@ -1068,12 +1071,14 @@ __put_ioc(
        IN                              ioc_pnp_mgr_t* const            p_ioc_mgr,\r
        IN                              iou_ioc_t* const                        p_ioc )\r
 {\r
-       CL_ASSERT( p_ioc->p_svc_entries );\r
-       cl_free( p_ioc->p_svc_entries );\r
+       if( cl_atomic_dec( &p_ioc->ref_cnt ) == 0 )\r
+       {\r
+               cl_free( p_ioc->p_svc_entries );\r
 \r
-       cl_spinlock_acquire( &p_ioc_mgr->ioc_pool_lock );\r
-       cl_qpool_put( &p_ioc_mgr->ioc_pool, &p_ioc->map_item.pool_item );\r
-       cl_spinlock_release( &p_ioc_mgr->ioc_pool_lock );\r
+               cl_spinlock_acquire( &p_ioc_mgr->ioc_pool_lock );\r
+               cl_qpool_put( &p_ioc_mgr->ioc_pool, &p_ioc->map_item.pool_item );\r
+               cl_spinlock_release( &p_ioc_mgr->ioc_pool_lock );\r
+       }\r
 }\r
 \r
 \r
@@ -1096,9 +1101,12 @@ __put_ioc_map(
                p_ioc = PARENT_STRUCT(\r
                        PARENT_STRUCT( p_item, cl_map_item_t, pool_item ),\r
                        iou_ioc_t, map_item );\r
-\r
-               cl_free( p_ioc->p_svc_entries );\r
-               cl_qlist_insert_head( &list, &p_item->pool_item.list_item );\r
+               \r
+               if( cl_atomic_dec( &p_ioc->ref_cnt ) == 0 )\r
+               {\r
+                       cl_free( p_ioc->p_svc_entries );\r
+                       cl_qlist_insert_head( &list, &p_item->pool_item.list_item );\r
+               }\r
                p_item = cl_qmap_head( p_ioc_map );\r
        }\r
        cl_spinlock_acquire( &p_ioc_mgr->ioc_pool_lock );\r
@@ -2479,6 +2487,7 @@ __query_svc_entries(
                                p_mad->p_next = p_mad_list;\r
                                p_mad_list = p_mad;\r
 \r
+                               cl_atomic_inc( &p_ioc->ref_cnt );\r
                                cl_atomic_inc( &p_results->p_svc->query_cnt );\r
                        }\r
                }\r
@@ -2502,6 +2511,8 @@ __query_svc_entries(
                {\r
                        p_mad_list = p_mad->p_next;\r
                        p_mad->p_next = NULL;\r
+                       p_ioc = (iou_ioc_t* __ptr64)p_mad->context2;\r
+                       cl_atomic_dec( &p_ioc->ref_cnt );\r
                        ib_put_mad( p_mad );\r
                        if( !cl_atomic_dec( &p_results->p_svc->query_cnt ) &&\r
                                status == IB_SUCCESS )\r
@@ -3297,3 +3308,5 @@ ioc_pnp_process_dereg(
        AL_EXIT( AL_DBG_PNP );\r
 }\r
 \r
+\r
+\r