Author: cgutman
Date: Fri Jan 8 19:21:52 2010
New Revision: 45006
URL:
http://svn.reactos.org/svn/reactos?rev=45006&view=rev
Log:
- Use a spin lock to protect the port bitmap instead of a fast mutex
Modified:
branches/aicom-network-branch/drivers/network/tcpip/include/ports.h
branches/aicom-network-branch/lib/drivers/ip/network/ports.c
Modified: branches/aicom-network-branch/drivers/network/tcpip/include/ports.h
URL:
http://svn.reactos.org/svn/reactos/branches/aicom-network-branch/drivers/ne…
==============================================================================
--- branches/aicom-network-branch/drivers/network/tcpip/include/ports.h [iso-8859-1]
(original)
+++ branches/aicom-network-branch/drivers/network/tcpip/include/ports.h [iso-8859-1] Fri
Jan 8 19:21:52 2010
@@ -16,7 +16,7 @@
PVOID ProtoBitBuffer;
UINT StartingPort;
UINT PortsToOversee;
- FAST_MUTEX Mutex;
+ KSPIN_LOCK Lock;
} PORT_SET, *PPORT_SET;
NTSTATUS PortsStartup( PPORT_SET PortSet,
Modified: branches/aicom-network-branch/lib/drivers/ip/network/ports.c
URL:
http://svn.reactos.org/svn/reactos/branches/aicom-network-branch/lib/driver…
==============================================================================
--- branches/aicom-network-branch/lib/drivers/ip/network/ports.c [iso-8859-1] (original)
+++ branches/aicom-network-branch/lib/drivers/ip/network/ports.c [iso-8859-1] Fri Jan 8
19:21:52 2010
@@ -24,7 +24,7 @@
PortSet->ProtoBitBuffer,
PortSet->PortsToOversee );
RtlClearAllBits( &PortSet->ProtoBitmap );
- ExInitializeFastMutex( &PortSet->Mutex );
+ KeInitializeSpinLock( &PortSet->Lock );
return STATUS_SUCCESS;
}
@@ -33,17 +33,20 @@
}
VOID DeallocatePort( PPORT_SET PortSet, ULONG Port ) {
+ KIRQL OldIrql;
+
Port = htons(Port);
ASSERT(Port >= PortSet->StartingPort);
ASSERT(Port < PortSet->StartingPort + PortSet->PortsToOversee);
- ExAcquireFastMutex( &PortSet->Mutex );
+ KeAcquireSpinLock( &PortSet->Lock, &OldIrql );
RtlClearBits( &PortSet->ProtoBitmap, Port - PortSet->StartingPort, 1 );
- ExReleaseFastMutex( &PortSet->Mutex );
+ KeReleaseSpinLock( &PortSet->Lock, OldIrql );
}
BOOLEAN AllocatePort( PPORT_SET PortSet, ULONG Port ) {
BOOLEAN Clear;
+ KIRQL OldIrql;
Port = htons(Port);
@@ -55,32 +58,34 @@
Port -= PortSet->StartingPort;
- ExAcquireFastMutex( &PortSet->Mutex );
+ KeAcquireSpinLock( &PortSet->Lock, &OldIrql );
Clear = RtlAreBitsClear( &PortSet->ProtoBitmap, Port, 1 );
if( Clear ) RtlSetBits( &PortSet->ProtoBitmap, Port, 1 );
- ExReleaseFastMutex( &PortSet->Mutex );
+ KeReleaseSpinLock( &PortSet->Lock, OldIrql );
return Clear;
}
ULONG AllocateAnyPort( PPORT_SET PortSet ) {
ULONG AllocatedPort;
+ KIRQL OldIrql;
- ExAcquireFastMutex( &PortSet->Mutex );
+ KeAcquireSpinLock( &PortSet->Lock, &OldIrql );
AllocatedPort = RtlFindClearBits( &PortSet->ProtoBitmap, 1, 0 );
if( AllocatedPort != (ULONG)-1 ) {
RtlSetBit( &PortSet->ProtoBitmap, AllocatedPort );
AllocatedPort += PortSet->StartingPort;
- ExReleaseFastMutex( &PortSet->Mutex );
+ KeReleaseSpinLock( &PortSet->Lock, OldIrql );
return htons(AllocatedPort);
}
- ExReleaseFastMutex( &PortSet->Mutex );
+ KeReleaseSpinLock( &PortSet->Lock, OldIrql );
return -1;
}
ULONG AllocatePortFromRange( PPORT_SET PortSet, ULONG Lowest, ULONG Highest ) {
ULONG AllocatedPort;
+ KIRQL OldIrql;
if ((Lowest < PortSet->StartingPort) ||
(Highest >= PortSet->StartingPort + PortSet->PortsToOversee))
@@ -91,15 +96,15 @@
Lowest -= PortSet->StartingPort;
Highest -= PortSet->StartingPort;
- ExAcquireFastMutex( &PortSet->Mutex );
+ KeAcquireSpinLock( &PortSet->Lock, &OldIrql );
AllocatedPort = RtlFindClearBits( &PortSet->ProtoBitmap, 1, Lowest );
if( AllocatedPort != (ULONG)-1 && AllocatedPort <= Highest) {
RtlSetBit( &PortSet->ProtoBitmap, AllocatedPort );
AllocatedPort += PortSet->StartingPort;
- ExReleaseFastMutex( &PortSet->Mutex );
+ KeReleaseSpinLock( &PortSet->Lock, OldIrql );
return htons(AllocatedPort);
}
- ExReleaseFastMutex( &PortSet->Mutex );
+ KeReleaseSpinLock( &PortSet->Lock, OldIrql );
return -1;
}