[ros-diffs] [cgutman] 41751: - TCPIP locking rewrite (part 2 of x) - Add locking in places that need it - Eliminate double acquisition of TCPLock for the same request - Next step: Verify that all places that need locking have it

cgutman at svn.reactos.org cgutman at svn.reactos.org
Fri Jul 3 02:57:48 CEST 2009


Author: cgutman
Date: Fri Jul  3 04:57:47 2009
New Revision: 41751

URL: http://svn.reactos.org/svn/reactos?rev=41751&view=rev
Log:
 - TCPIP locking rewrite (part 2 of x)
 - Add locking in places that need it
 - Eliminate double acquisition of TCPLock for the same request
 - Next step: Verify that all places that need locking have it

Modified:
    trunk/reactos/drivers/network/tcpip/tcpip/dispatch.c
    trunk/reactos/lib/drivers/ip/transport/tcp/accept.c
    trunk/reactos/lib/drivers/ip/transport/tcp/tcp.c

Modified: trunk/reactos/drivers/network/tcpip/tcpip/dispatch.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/tcpip/tcpip/dispatch.c?rev=41751&r1=41750&r2=41751&view=diff
==============================================================================
--- trunk/reactos/drivers/network/tcpip/tcpip/dispatch.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/tcpip/tcpip/dispatch.c [iso-8859-1] Fri Jul  3 04:57:47 2009
@@ -646,15 +646,19 @@
   PTDI_REQUEST_KERNEL_QUERY_INFORMATION Parameters;
   PTRANSPORT_CONTEXT TranContext;
   PIO_STACK_LOCATION IrpSp;
+  NTSTATUS Status;
 
   TI_DbgPrint(DEBUG_IRP, ("Called.\n"));
 
   IrpSp = IoGetCurrentIrpStackLocation(Irp);
   Parameters = (PTDI_REQUEST_KERNEL_QUERY_INFORMATION)&IrpSp->Parameters;
+
+  TcpipRecursiveMutexEnter( &TCPLock, TRUE );
 
   TranContext = IrpSp->FileObject->FsContext;
   if (!TranContext) {
     TI_DbgPrint(MID_TRACE, ("Bad transport context.\n"));
+    TcpipRecursiveMutexLeave(&TCPLock);
     return STATUS_INVALID_PARAMETER;
   }
 
@@ -672,6 +676,7 @@
             (FIELD_OFFSET(TDI_ADDRESS_INFO, Address.Address[0].Address) +
              sizeof(TDI_ADDRESS_IP))) {
           TI_DbgPrint(MID_TRACE, ("MDL buffer too small.\n"));
+          TcpipRecursiveMutexLeave(&TCPLock);
           return STATUS_BUFFER_TOO_SMALL;
         }
 
@@ -690,6 +695,7 @@
 			RtlZeroMemory(
 				&Address->Address[0].Address[0].sin_zero,
 				sizeof(Address->Address[0].Address[0].sin_zero));
+			TcpipRecursiveMutexLeave(&TCPLock);
 			return STATUS_SUCCESS;
 
           case TDI_CONNECTION_FILE:
@@ -700,18 +706,22 @@
 			RtlZeroMemory(
 				&Address->Address[0].Address[0].sin_zero,
 				sizeof(Address->Address[0].Address[0].sin_zero));
+			TcpipRecursiveMutexLeave(&TCPLock);
 			return STATUS_SUCCESS;
 
           default:
             TI_DbgPrint(MIN_TRACE, ("Invalid transport context\n"));
+            TcpipRecursiveMutexLeave(&TCPLock);
             return STATUS_INVALID_PARAMETER;
         }
 
         if (!AddrFile) {
           TI_DbgPrint(MID_TRACE, ("No address file object.\n"));
+          TcpipRecursiveMutexLeave(&TCPLock);
           return STATUS_INVALID_PARAMETER;
         }
 
+        TcpipRecursiveMutexLeave(&TCPLock);
         return STATUS_SUCCESS;
       }
 
@@ -725,6 +735,7 @@
             (FIELD_OFFSET(TDI_CONNECTION_INFORMATION, RemoteAddress) +
              sizeof(PVOID))) {
           TI_DbgPrint(MID_TRACE, ("MDL buffer too small (ptr).\n"));
+          TcpipRecursiveMutexLeave(&TCPLock);
           return STATUS_BUFFER_TOO_SMALL;
         }
 
@@ -743,18 +754,24 @@
 
           default:
             TI_DbgPrint(MIN_TRACE, ("Invalid transport context\n"));
+            TcpipRecursiveMutexLeave(&TCPLock);
             return STATUS_INVALID_PARAMETER;
         }
 
         if (!Endpoint) {
           TI_DbgPrint(MID_TRACE, ("No connection object.\n"));
+          TcpipRecursiveMutexLeave(&TCPLock);
           return STATUS_INVALID_PARAMETER;
         }
 
-        return TCPGetSockAddress( Endpoint, AddressInfo->RemoteAddress, TRUE );
+        Status = TCPGetSockAddress( Endpoint, AddressInfo->RemoteAddress, TRUE );
+
+        TcpipRecursiveMutexLeave(&TCPLock);
+        return Status;
       }
   }
 
+  TcpipRecursiveMutexLeave(&TCPLock);
   return STATUS_NOT_IMPLEMENTED;
 }
 

Modified: trunk/reactos/lib/drivers/ip/transport/tcp/accept.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/transport/tcp/accept.c?rev=41751&r1=41750&r2=41751&view=diff
==============================================================================
--- trunk/reactos/lib/drivers/ip/transport/tcp/accept.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/ip/transport/tcp/accept.c [iso-8859-1] Fri Jul  3 04:57:47 2009
@@ -142,6 +142,8 @@
     Status = TCPServiceListeningSocket( Listener, Connection,
                        (PTDI_REQUEST_KERNEL)Request );
 
+    TcpipRecursiveMutexLeave( &TCPLock );
+
     if( Status == STATUS_PENDING ) {
         Bucket = exAllocatePool( NonPagedPool, sizeof(*Bucket) );
 
@@ -155,8 +157,6 @@
             Status = STATUS_NO_MEMORY;
     }
 
-    TcpipRecursiveMutexLeave( &TCPLock );
-
     TI_DbgPrint(DEBUG_TCP,("TCPAccept finished %x\n", Status));
     return Status;
 }

Modified: trunk/reactos/lib/drivers/ip/transport/tcp/tcp.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/transport/tcp/tcp.c?rev=41751&r1=41750&r2=41751&view=diff
==============================================================================
--- trunk/reactos/lib/drivers/ip/transport/tcp/tcp.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/ip/transport/tcp/tcp.c [iso-8859-1] Fri Jul  3 04:57:47 2009
@@ -332,7 +332,6 @@
                            "Proto %d\n",
                            Connection, Family, Type, Proto));
 
-    TcpipRecursiveMutexEnter( &TCPLock, TRUE );
     Status = TCPTranslateError( OskitTCPSocket( Connection,
                                                 &Connection->SocketContext,
                                                 Family,
@@ -343,8 +342,6 @@
 
     TI_DbgPrint(DEBUG_TCP,("Connection->SocketContext %x\n",
                            Connection->SocketContext));
-
-    TcpipRecursiveMutexLeave( &TCPLock );
 
     return Status;
 }
@@ -599,11 +596,8 @@
         return STATUS_NETWORK_UNREACHABLE;
     }
 
-    TcpipRecursiveMutexEnter( &TCPLock, TRUE );
-
     if (Connection->State & SEL_FIN)
     {
-        TcpipRecursiveMutexLeave( &TCPLock );
         return STATUS_REMOTE_DISCONNECT;
     }
 
@@ -649,8 +643,6 @@
         }
     }
 
-    TcpipRecursiveMutexLeave( &TCPLock );
-
     return Status;
 }
 
@@ -665,8 +657,6 @@
 
     TI_DbgPrint(DEBUG_TCP,("started\n"));
 
-    TcpipRecursiveMutexEnter( &TCPLock, TRUE );
-
     switch( Flags & (TDI_DISCONNECT_ABORT | TDI_DISCONNECT_RELEASE) ) {
     case 0:
     case TDI_DISCONNECT_ABORT:
@@ -685,8 +675,6 @@
     Status = TCPTranslateError
         ( OskitTCPShutdown( Connection->SocketContext, Flags ) );
 
-    TcpipRecursiveMutexLeave( &TCPLock );
-
     TI_DbgPrint(DEBUG_TCP,("finished %x\n", Status));
 
     return Status;
@@ -698,15 +686,11 @@
 
     TI_DbgPrint(DEBUG_TCP,("TCPClose started\n"));
 
-    TcpipRecursiveMutexEnter( &TCPLock, TRUE );
-
     /* Make our code remove all pending IRPs */
     Connection->State |= SEL_FIN;
     DrainSignals();
 
     Status = TCPTranslateError( OskitTCPClose( Connection->SocketContext ) );
-
-    TcpipRecursiveMutexLeave( &TCPLock );
 
     TI_DbgPrint(DEBUG_TCP,("TCPClose finished %x\n", Status));
 
@@ -731,12 +715,9 @@
 
     ASSERT_KM_POINTER(Connection->SocketContext);
 
-    TcpipRecursiveMutexEnter( &TCPLock, TRUE );
-
     /* Closing */
     if (Connection->State & SEL_FIN)
     {
-        TcpipRecursiveMutexLeave( &TCPLock );
         *BytesReceived = 0;
         return STATUS_REMOTE_DISCONNECT;
     }
@@ -761,7 +742,6 @@
         Bucket = exAllocatePool( NonPagedPool, sizeof(*Bucket) );
         if( !Bucket ) {
             TI_DbgPrint(DEBUG_TCP,("Failed to allocate bucket\n"));
-            TcpipRecursiveMutexLeave( &TCPLock );
             return STATUS_NO_MEMORY;
         }
 
@@ -777,8 +757,6 @@
         TI_DbgPrint(DEBUG_TCP,("Got status %x, bytes %d\n", Status, Received));
         *BytesReceived = Received;
     }
-
-    TcpipRecursiveMutexLeave( &TCPLock );
 
     TI_DbgPrint(DEBUG_TCP,("Status %x\n", Status));
 
@@ -802,8 +780,6 @@
 
     ASSERT_KM_POINTER(Connection->SocketContext);
 
-    TcpipRecursiveMutexEnter( &TCPLock, TRUE );
-
     TI_DbgPrint(DEBUG_TCP,("Connection = %x\n", Connection));
     TI_DbgPrint(DEBUG_TCP,("Connection->SocketContext = %x\n",
                            Connection->SocketContext));
@@ -811,7 +787,6 @@
     /* Closing */
     if (Connection->State & SEL_FIN)
     {
-        TcpipRecursiveMutexLeave( &TCPLock );
         *BytesSent = 0;
         return STATUS_REMOTE_DISCONNECT;
     }
@@ -829,7 +804,6 @@
         Bucket = exAllocatePool( NonPagedPool, sizeof(*Bucket) );
         if( !Bucket ) {
             TI_DbgPrint(DEBUG_TCP,("Failed to allocate bucket\n"));
-            TcpipRecursiveMutexLeave( &TCPLock );
             return STATUS_NO_MEMORY;
         }
         
@@ -846,8 +820,6 @@
         *BytesSent = Sent;
     }
     
-    TcpipRecursiveMutexLeave( &TCPLock );
-    
     TI_DbgPrint(DEBUG_TCP,("Status %x\n", Status));
 
     return Status;
@@ -880,8 +852,6 @@
     OSK_UI16 LocalPort, RemotePort;
     PTA_IP_ADDRESS AddressIP = (PTA_IP_ADDRESS)Address;
 
-    TcpipRecursiveMutexEnter( &TCPLock, TRUE );
-
     OskitTCPGetAddress
         ( Connection->SocketContext,
           &LocalAddress, &LocalPort,
@@ -892,8 +862,6 @@
     AddressIP->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
     AddressIP->Address[0].Address[0].sin_port = GetRemote ? RemotePort : LocalPort;
     AddressIP->Address[0].Address[0].in_addr = GetRemote ? RemoteAddress : LocalAddress;
-
-    TcpipRecursiveMutexLeave( &TCPLock );
 
     return STATUS_SUCCESS;
 }



More information about the Ros-diffs mailing list