[WSD] Use socket reference count to control destruction.
authorftillier <ftillier@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Tue, 27 Sep 2005 00:45:47 +0000 (00:45 +0000)
committerftillier <ftillier@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Tue, 27 Sep 2005 00:45:47 +0000 (00:45 +0000)
Signed-off-by: Fab Tillier (ftillier@silverstorm.com)
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@95 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

ulp/wsd/user/ibspdll.c
ulp/wsd/user/ibspproto.h
ulp/wsd/user/ibspstruct.h
ulp/wsd/user/sockinfo.c

index d0fd7a5..7933df0 100644 (file)
@@ -416,7 +416,7 @@ reject:
 \r
                IBSP_ERROR_EXIT(\r
                        ("WPUCreateSocketHandle() failed: %d", *lpErrno) );\r
-               free_socket_info( new_socket_info );\r
+               deref_socket_info( new_socket_info );\r
                return INVALID_SOCKET;\r
        }\r
 \r
@@ -487,12 +487,13 @@ reject:
                {\r
                        STAT_DEC( wpusocket_num );\r
                }\r
+               new_socket_info->switch_socket = INVALID_SOCKET;\r
 \r
                CloseHandle( new_socket_info->h_event );\r
 \r
                ib_destroy_socket( new_socket_info );\r
 \r
-               free_socket_info( new_socket_info );\r
+               deref_socket_info( new_socket_info );\r
 \r
                /* Be nice and reject that connection. */\r
                ib_reject( incoming->cm_req_received.h_cm_req, IB_REJ_INSUF_QP );\r
@@ -547,9 +548,10 @@ reject:
                                {\r
                                        STAT_DEC( wpusocket_num );\r
                                }\r
+                               new_socket_info->switch_socket = INVALID_SOCKET;\r
 \r
                                ib_destroy_socket( new_socket_info );\r
-                               free_socket_info( new_socket_info );\r
+                               deref_socket_info( new_socket_info );\r
 \r
                                *lpErrno = WSAEACCES;\r
 \r
@@ -2200,7 +2202,7 @@ IBSPSocket(
 \r
 error:\r
        if( socket_info )\r
-               free_socket_info( socket_info );\r
+               deref_socket_info( socket_info );\r
 \r
        CL_ASSERT( *lpErrno != 0 );\r
 \r
index fa0a102..eb84bd0 100644 (file)
 struct ibsp_socket_info *\r
 create_socket_info( void );\r
 \r
-void\r
-free_socket_info(\r
-       struct ibsp_socket_info *socket_info );\r
-\r
-void\r
+void AL_API\r
 deref_socket_info(\r
        IN                              struct ibsp_socket_info         *p_socket );\r
 \r
@@ -119,6 +115,7 @@ ibsp_initialize( void );
 void\r
 ib_release_cq_tinfo(\r
                                        struct cq_thread_info           *cq_tinfo );\r
+\r
 void\r
 ib_destroy_cq_tinfo(\r
                                        struct cq_thread_info           *cq_tinfo );\r
@@ -135,10 +132,6 @@ void
 shutdown_and_destroy_socket_info(\r
        IN      OUT                     struct ibsp_socket_info         *socket_info );\r
 \r
-void\r
-destroy_qp_and_release_ressources(\r
-       IN      OUT                     struct ibsp_socket_info         *socket_info );\r
-\r
 void\r
 ib_cq_comp(\r
                                        void                                            *cq_context );\r
index 59316c4..45dc6dd 100644 (file)
@@ -234,8 +234,8 @@ struct ibsp_socket_info
                struct listen_req_param listen_req_param;\r
        } listen;\r
 \r
-       /* Event for blocking accept, connect, and disconnect */\r
-       HANDLE h_event;\r
+       /* Event for blocking accept, and connect */\r
+       HANDLE  h_event;\r
 \r
        /* Variables associated with IBSPSelectEvent */\r
        WSAEVENT event_select;          /* Handle to Event Object */\r
index bdad2f7..883a9bc 100644 (file)
@@ -73,7 +73,7 @@ create_socket_info(void)
        socket_info->switch_socket = INVALID_SOCKET;\r
        /*\r
         * Preset to 1, IBSPCloseSocket will decrement it, and switch socket\r
-        * will be freed once it goes to zero after an upcall.\r
+        * will be freed once it goes to zero.\r
         */\r
        socket_info->ref_cnt = 1;\r
 \r
@@ -85,39 +85,20 @@ create_socket_info(void)
 \r
 \r
 /* \r
- * Function: free_sock_info\r
+ * Function: deref_sock_info\r
  * \r
  * Description:\r
- *  This routine frees the socket context structure.\r
+ *     This routine decrements a socket context's reference count, and if\r
+ *     it reaches zero, frees the socket context structure.\r
  */\r
-void\r
-free_socket_info(\r
-                                       struct ibsp_socket_info         *socket_info )\r
-{\r
-       IBSP_ENTER( IBSP_DBG_SI );\r
-\r
-       CL_ASSERT( !socket_info->conn_item.p_map );\r
-\r
-       cl_spinlock_destroy( &socket_info->buf_mem_list.mutex );\r
-       cl_spinlock_destroy( &socket_info->mutex );\r
-\r
-       cl_spinlock_destroy( &socket_info->send_lock );\r
-       cl_spinlock_destroy( &socket_info->recv_lock );\r
-\r
-       HeapFree( g_ibsp.heap, 0, socket_info );\r
-\r
-       IBSP_TRACE( IBSP_DBG_SI, ("socket_info (%p)\n", socket_info) );\r
-\r
-       IBSP_EXIT( IBSP_DBG_SI );\r
-}\r
-\r
-\r
-void\r
+void AL_API\r
 deref_socket_info(\r
        IN                              struct ibsp_socket_info         *p_socket )\r
 {\r
        int             ret, error;\r
 \r
+       IBSP_ENTER( IBSP_DBG_SI );\r
+\r
        if( !cl_atomic_dec( &p_socket->ref_cnt ) )\r
        {\r
                if( p_socket->switch_socket != INVALID_SOCKET )\r
@@ -141,13 +122,18 @@ deref_socket_info(
                        p_socket->switch_socket = INVALID_SOCKET;\r
                }\r
 \r
-               /*\r
-                * This only works because the socket doesn't have its own CQ.  If it\r
-                * did CQ destruction would have to be async since IBSPCloseSocket can\r
-                * be invoked from the CQ callback thread context, and freeing the\r
-                * socket structure would need to be delayed until the CQ's destroy\r
-                * callback.\r
-                */\r
-               free_socket_info( p_socket );\r
+               CL_ASSERT( !p_socket->qp );\r
+               CL_ASSERT( !p_socket->conn_item.p_map );\r
+\r
+               cl_spinlock_destroy( &p_socket->buf_mem_list.mutex );\r
+               cl_spinlock_destroy( &p_socket->mutex );\r
+\r
+               cl_spinlock_destroy( &p_socket->send_lock );\r
+               cl_spinlock_destroy( &p_socket->recv_lock );\r
+\r
+               HeapFree( g_ibsp.heap, 0, p_socket );\r
+\r
+               IBSP_TRACE( IBSP_DBG_SI, ("Freed socket_info (%p)\n", p_socket) );\r
        }\r
+       IBSP_EXIT( IBSP_DBG_SI );\r
 }\r