NdisDprAllocatePacketNonInterlocked

VOID
    NdisDprAllocatePacketNonInterlocked(
        OUT PNDIS_STATUS  Status,
        OUT PNDIS_PACKET  *Packet,
        IN NDIS_HANDLE  PoolHandle
        ); 

NdisDprAllocatePacketNonInterlocked allocates and initializes a packet descriptor when the caller is running at IRQL DISPATCH_LEVEL and that caller provides internal synchronization for accessing packet pool.

Parameters

Status
Points to a caller-supplied variable in which this function returns the final status of the request, which can be one of the following:
NDIS_STATUS_SUCCESS
The caller can use the packet descriptor returned at Packet.
NDIS_STATUS_RESOURCES
The free list for the packet pool currently has no available entries. A subsequent call to NdisDprFreePacketNonInterlocked will return the given entry to the free list. The variable at Packet is set to NULL.
Packet
Points to a caller-supplied variable in which this function returns a pointer to the allocated packet descriptor.
PoolHandle
Specifies the handle returned by a preceding call to NdisAllocatePacketPool.

Comments

A caller of NdisDprAllocatePacketNonInterlocked and its reciprocal NdisDprFreePacketNonInterlocked is responsible for synchronizing all accesses to the packet pool that driver allocated with NdisAllocatePacketPool. Otherwise, the driver should let NDIS manage this synchronization on its behalf by calling NdisAllocatePacket or NdisDprAllocatePacket.

NdisDprAllocatePacketNonInterlocked runs slightly faster than NdisAllocatePacket because NDIS need not acquire a spin lock, which NDIS typically uses to synchronize access to packet pools that drivers allocate.

Instead, a caller of NdisDprAllocatePacketNonInterlocked and NdisDprFreePacketNonInterlocked manages the synchronization of its accesses to packet pool internally.

Usually, such a driver protects its packet pool with a driver-allocated spin lock. Before calling NdisDprAllocatePacketNonInterlocked, the driver calls NdisAcquireSpinLock, which raises IRQL to DISPATCH_LEVEL. Only when the driver resumes execution holding its spin lock does it call NdisDprAllocatePacketNonInterlocked. Such a driver releases its spin lock with NdisReleaseSpinLock when NdisDprAllocatePacketNonInterlocked returns control.

In a similar manner, such a driver calls NdisAcquireSpinLock before it releases a packet descriptor back to pool with NdisDprFreePacketNonInterlocked and, then, it calls NdisReleaseSpinLock.

Any packet descriptor allocated with NdisDprAllocatePacketNonInterlocked must be freed with NdisDprFreePacketNonInterlocked except, possibly, when a driver is releasing its allocated resources just before being unloaded. Otherwise, it is a runtime synchronization error that can cause race conditions to release any packet descriptor with NdisDprFreePacket or NdisFreePacket if that packet descriptor was allocated with NdisDprAllocatePacketNonInterlocked.

The caller of NdisDprAllocatePacketNonInterlocked must be running at IRQL DISPATCH_LEVEL.

See Also

NdisAcquireSpinLock, NdisAllocatePacket, NdisAllocatePacketPool, NdisAllocateSpinLock, NdisDprAllocatePacket, NdisDprFreePacket, NdisDprFreePacketNonInterlocked, NdisFreePacket, NdisReleaseSpinLock