ReactOS  0.4.14-dev-845-g8381e29
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 {
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  }
73  LockState->LockState = 4;
74  }
75  } else {
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. */
87  }
88  }
89  }
91  LockState->LockState = 3;
92  }
93 }
PVOID Context
Definition: rwlock.h:17
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
FORCEINLINE ULONG KeGetCurrentProcessorNumber(VOID)
Definition: ke.h:337
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:99
_Acquires_exclusive_lock_ Lock _In_ BOOLEAN fWrite
Definition: ndis.h:4586
KSPIN_LOCK SpinLock
Definition: rwlock.h:16
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
unsigned char UCHAR
Definition: xmlstorage.h:181
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG IN OUT PLONG IN LONG Increment IN PNDIS_RW_LOCK Lock
Definition: CrNtStubs.h:75
CCHAR KeNumberProcessors
Definition: krnlinit.c:35
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
unsigned int RefCount
Definition: rwlock.h:9
#define InterlockedIncrement
Definition: armddk.h:53
NDIS_RW_LOCK_REFCOUNT RefCount[MAXIMUM_PROCESSORS]
Definition: rwlock.h:22
unsigned int ULONG
Definition: retypes.h:1
#define ASSERT_IRQL(x)
Definition: debug.h:42
signed int * PLONG
Definition: retypes.h:5

◆ 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 }
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK SpinLock
Definition: iofuncs.h:798
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609

Referenced by MiniportQueryInformation(), MiniportSend(), and MiniportSetInformation().

◆ NdisAllocateSpinLock()

VOID EXPORT NdisAllocateSpinLock ( IN PNDIS_SPIN_LOCK  SpinLock)

Definition at line 152 of file control.c.

159 {
160  KeInitializeSpinLock(&SpinLock->SpinLock);
161 }
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK SpinLock
Definition: iofuncs.h:798
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238

Referenced by MiniportInitialize().

◆ NdisDprAcquireSpinLock()

VOID EXPORT NdisDprAcquireSpinLock ( IN PNDIS_SPIN_LOCK  SpinLock)

Definition at line 169 of file control.c.

176 {
178  SpinLock->OldIrql = DISPATCH_LEVEL;
179 }
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK SpinLock
Definition: iofuncs.h:798
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696

Referenced by MiniportHandleInterrupt(), and MiniportSend().

◆ NdisDprReleaseSpinLock()

VOID EXPORT NdisDprReleaseSpinLock ( IN PNDIS_SPIN_LOCK  SpinLock)

Definition at line 187 of file control.c.

194 {
196 }
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK SpinLock
Definition: iofuncs.h:798
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215

Referenced by MiniportHandleInterrupt(), and MiniportSend().

◆ NdisFreeSpinLock()

VOID EXPORT NdisFreeSpinLock ( IN PNDIS_SPIN_LOCK  SpinLock)

Definition at line 204 of file control.c.

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

Referenced by MiniportHalt().

◆ NdisInitializeEvent()

VOID EXPORT NdisInitializeEvent ( IN PNDIS_EVENT  Event)

Definition at line 221 of file control.c.

228 {
230 }
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477

◆ NdisInitializeReadWriteLock()

VOID EXPORT NdisInitializeReadWriteLock ( IN PNDIS_RW_LOCK  Lock)

Definition at line 20 of file control.c.

29 {
31 
33 }
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238
KSPIN_LOCK SpinLock
Definition: rwlock.h:16
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG IN OUT PLONG IN LONG Increment IN PNDIS_RW_LOCK Lock
Definition: CrNtStubs.h:75
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261

◆ 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 */
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;
125  return;
126  }
127 }
PVOID Context
Definition: rwlock.h:17
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
FORCEINLINE ULONG KeGetCurrentProcessorNumber(VOID)
Definition: ke.h:337
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:99
smooth NULL
Definition: ftsmooth.c:416
KSPIN_LOCK SpinLock
Definition: rwlock.h:16
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG IN OUT PLONG IN LONG Increment IN PNDIS_RW_LOCK Lock
Definition: CrNtStubs.h:75
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
unsigned int RefCount
Definition: rwlock.h:9
NDIS_RW_LOCK_REFCOUNT RefCount[MAXIMUM_PROCESSORS]
Definition: rwlock.h:22
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627

◆ 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 }
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK SpinLock
Definition: iofuncs.h:798
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627

Referenced by MiniportQueryInformation(), MiniportSend(), and MiniportSetInformation().

◆ 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

◆ NdisSetEvent()

VOID EXPORT NdisSetEvent ( IN PNDIS_EVENT  Event)

Definition at line 273 of file control.c.

280 {
282 }
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define IO_NO_INCREMENT
Definition: iotypes.h:566

◆ 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 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
Status
Definition: gdiplustypes.h:24
static ULONG Timeout
Definition: ping.c:61
_In_ UINT MsToWait
Definition: ndis.h:5881
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define Int32x32To64(a, b)