ReactOS 0.4.15-dev-8241-g63935f8
control.c File Reference
#include "ndissys.h"
Include dependency graph for control.c:

Go to the source code of this file.

Functions

VOID EXPORT NdisInitializeReadWriteLock (IN PNDIS_RW_LOCK Lock)
 
VOID EXPORT NdisAcquireReadWriteLock (IN PNDIS_RW_LOCK Lock, IN BOOLEAN fWrite, IN PLOCK_STATE LockState)
 
VOID EXPORT NdisReleaseReadWriteLock (IN PNDIS_RW_LOCK Lock, IN PLOCK_STATE LockState)
 
VOID EXPORT NdisAcquireSpinLock (IN PNDIS_SPIN_LOCK SpinLock)
 
VOID EXPORT NdisAllocateSpinLock (IN PNDIS_SPIN_LOCK SpinLock)
 
VOID EXPORT NdisDprAcquireSpinLock (IN PNDIS_SPIN_LOCK SpinLock)
 
VOID EXPORT NdisDprReleaseSpinLock (IN PNDIS_SPIN_LOCK SpinLock)
 
VOID EXPORT NdisFreeSpinLock (IN PNDIS_SPIN_LOCK SpinLock)
 
VOID EXPORT NdisInitializeEvent (IN PNDIS_EVENT Event)
 
VOID EXPORT NdisReleaseSpinLock (IN PNDIS_SPIN_LOCK SpinLock)
 
VOID EXPORT NdisResetEvent (IN PNDIS_EVENT Event)
 
VOID EXPORT NdisSetEvent (IN PNDIS_EVENT Event)
 
BOOLEAN EXPORT NdisWaitEvent (IN PNDIS_EVENT Event, IN UINT MsToWait)
 

Function Documentation

◆ NdisAcquireReadWriteLock()

VOID EXPORT NdisAcquireReadWriteLock ( IN PNDIS_RW_LOCK  Lock,
IN BOOLEAN  fWrite,
IN PLOCK_STATE  LockState 
)

Definition at line 40 of file control.c.

50{
51 ULONG RefCount;
52 UCHAR ProcessorNumber;
53 volatile UCHAR BusyLoop;
54
56
57 if (fWrite) {
58 if (Lock->Context == PsGetCurrentThread()) {
59 LockState->LockState = 2;
60 } else {
61 KeAcquireSpinLock(&Lock->SpinLock, &LockState->OldIrql);
62 /* Check if any other processor helds a shared lock. */
63 for (ProcessorNumber = KeNumberProcessors; ProcessorNumber--; ) {
64 if (ProcessorNumber != KeGetCurrentProcessorNumber()) {
65 /* Wait till the shared lock is released. */
66 while (Lock->RefCount[ProcessorNumber].RefCount != 0) {
67 for (BusyLoop = 32; BusyLoop--; )
68 ;
69 }
70 }
71 }
72 Lock->Context = PsGetCurrentThread();
73 LockState->LockState = 4;
74 }
75 } else {
77 RefCount = InterlockedIncrement((PLONG)&Lock->RefCount[KeGetCurrentProcessorNumber()].RefCount);
78 /* Racing with a exclusive write lock case. */
79 if (Lock->SpinLock != 0) {
80 if (RefCount == 1) {
81 if (Lock->Context != PsGetCurrentThread()) {
82 /* Wait for the exclusive lock to be released. */
83 Lock->RefCount[KeGetCurrentProcessorNumber()].RefCount--;
85 Lock->RefCount[KeGetCurrentProcessorNumber()].RefCount++;
87 }
88 }
89 }
90 Lock->Context = PsGetCurrentThread();
91 LockState->LockState = 3;
92 }
93}
#define InterlockedIncrement
Definition: armddk.h:53
#define ASSERT_IRQL(x)
Definition: debug.h:42
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG IN OUT PLONG IN LONG Increment IN PNDIS_RW_LOCK Lock IN PNDIS_RW_LOCK IN PLOCK_STATE LockState
Definition: CrNtStubs.h:104
CCHAR KeNumberProcessors
Definition: krnlinit.c:35
_Acquires_exclusive_lock_ Lock _In_ BOOLEAN fWrite
Definition: ndis.h:4586
FORCEINLINE ULONG KeGetCurrentProcessorNumber(VOID)
Definition: ke.h:341
#define KeAcquireSpinLockAtDpcLevel(SpinLock)
Definition: ke.h:125
#define KeReleaseSpinLockFromDpcLevel(SpinLock)
Definition: ke.h:135
int32_t * PLONG
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:127
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ NdisAcquireSpinLock()

VOID EXPORT NdisAcquireSpinLock ( IN PNDIS_SPIN_LOCK  SpinLock)

Definition at line 135 of file control.c.

142{
143 KeAcquireSpinLock(&SpinLock->SpinLock, &SpinLock->OldIrql);
144}
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFSPINLOCK * SpinLock
Definition: wdfsync.h:228

◆ NdisAllocateSpinLock()

VOID EXPORT NdisAllocateSpinLock ( IN PNDIS_SPIN_LOCK  SpinLock)

Definition at line 152 of file control.c.

159{
160 KeInitializeSpinLock(&SpinLock->SpinLock);
161}
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604

◆ NdisDprAcquireSpinLock()

VOID EXPORT NdisDprAcquireSpinLock ( IN PNDIS_SPIN_LOCK  SpinLock)

Definition at line 169 of file control.c.

176{
178 SpinLock->OldIrql = DISPATCH_LEVEL;
179}

◆ NdisDprReleaseSpinLock()

VOID EXPORT NdisDprReleaseSpinLock ( IN PNDIS_SPIN_LOCK  SpinLock)

Definition at line 187 of file control.c.

194{
196}

◆ NdisFreeSpinLock()

VOID EXPORT NdisFreeSpinLock ( IN PNDIS_SPIN_LOCK  SpinLock)

Definition at line 204 of file control.c.

211{
212 /* Nothing to do here! */
213}

◆ NdisInitializeEvent()

VOID EXPORT NdisInitializeEvent ( IN PNDIS_EVENT  Event)

Definition at line 221 of file control.c.

228{
230}
#define FALSE
Definition: types.h:117
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
@ NotificationEvent

Referenced by ParaNdis_FinishSpecificInitialization(), and ParaNdis_InitializeContext().

◆ NdisInitializeReadWriteLock()

VOID EXPORT NdisInitializeReadWriteLock ( IN PNDIS_RW_LOCK  Lock)

Definition at line 20 of file control.c.

29{
31
32 KeInitializeSpinLock(&Lock->SpinLock);
33}
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

◆ NdisReleaseReadWriteLock()

VOID EXPORT NdisReleaseReadWriteLock ( IN PNDIS_RW_LOCK  Lock,
IN PLOCK_STATE  LockState 
)

Definition at line 100 of file control.c.

109{
110 switch (LockState->LockState) {
111 case 2: /* Exclusive write lock, recursive */
112 return;
113
114 case 3: /* Shared read lock */
115 Lock->RefCount[KeGetCurrentProcessorNumber()].RefCount--;
116 LockState->LockState = -1;
117 if (LockState->OldIrql < DISPATCH_LEVEL)
118 KeLowerIrql(LockState->OldIrql);
119 return;
120
121 case 4: /* Exclusive write lock */
122 Lock->Context = NULL;
123 LockState->LockState = -1;
124 KeReleaseSpinLock(&Lock->SpinLock, LockState->OldIrql);
125 return;
126 }
127}
#define NULL
Definition: types.h:112
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602

◆ NdisReleaseSpinLock()

VOID EXPORT NdisReleaseSpinLock ( IN PNDIS_SPIN_LOCK  SpinLock)

Definition at line 239 of file control.c.

246{
247 KeReleaseSpinLock(&SpinLock->SpinLock, SpinLock->OldIrql);
248}

◆ NdisResetEvent()

VOID EXPORT NdisResetEvent ( IN PNDIS_EVENT  Event)

Definition at line 256 of file control.c.

263{
264 KeClearEvent(&Event->Event);
265}
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22

Referenced by ParaNdis5_Halt(), and ParaNdis_Suspend().

◆ NdisSetEvent()

VOID EXPORT NdisSetEvent ( IN PNDIS_EVENT  Event)

Definition at line 273 of file control.c.

280{
282}
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define IO_NO_INCREMENT
Definition: iotypes.h:598

Referenced by OnReceiveStopped(), OnReceiveStoppedOnReset(), OnSendStopped(), OnSendStoppedOnReset(), ParaNdis5_Halt(), and ParaNdis_Suspend().

◆ NdisWaitEvent()

BOOLEAN EXPORT NdisWaitEvent ( IN PNDIS_EVENT  Event,
IN UINT  MsToWait 
)

Definition at line 290 of file control.c.

301{
304
305 Timeout.QuadPart = Int32x32To64(MsToWait, -10000);
306
308
309 return (Status == STATUS_SUCCESS);
310}
LONG NTSTATUS
Definition: precomp.h:26
#define TRUE
Definition: types.h:120
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
Status
Definition: gdiplustypes.h:25
_In_ UINT MsToWait
Definition: ndis.h:5881
#define KernelMode
Definition: asm.h:34
#define Int32x32To64(a, b)
static ULONG Timeout
Definition: ping.c:61
#define STATUS_SUCCESS
Definition: shellext.h:65
@ Executive
Definition: ketypes.h:415

Referenced by ParaNdis_Suspend(), and WaitHaltEvent().