102 _In_ ULONG_PTR Value,
103 _In_ BOOLEAN IgnoreOwned,
107 static HANDLE PhQueuedLockKeyedEventHandle;
108 static ULONG PhQueuedLockSpinCount = 2000;
115 &PhQueuedLockKeyedEventHandle,
116 KEYEDEVENT_ALL_ACCESS,
123 PhQueuedLockSpinCount = 4000;
125 PhQueuedLockSpinCount = 0;
162 _In_ ULONG_PTR Value,
163 _In_ BOOLEAN Exclusive,
165 _Out_ PBOOLEAN Optimize,
166 _Out_ PULONG_PTR NewValue,
167 _Out_ PULONG_PTR CurrentValue
173 WaitBlock->Previous = NULL;
185 WaitBlock->Last = NULL;
187 WaitBlock->SharedOwners = 0;
201 WaitBlock->Last = WaitBlock;
208 if (WaitBlock->SharedOwners > 1)
225 WaitBlock->SharedOwners = 0;
232 *Optimize = optimize;
233 *CurrentValue = newValue;
236 (PVOID *)&QueuedLock->Value,
241 *NewValue = newValue;
243 return newValue == Value;
273 lastWaitBlock = waitBlock->Last;
281 waitBlock = lastWaitBlock;
285 waitBlock = waitBlock->Next;
301 _In_opt_ PLARGE_INTEGER Timeout
311 for (i = PhQueuedLockSpinCount; i != 0; i--)
314 return STATUS_SUCCESS;
324 status = NtWaitForKeyedEvent(
325 PhQueuedLockKeyedEventHandle,
338 status = STATUS_SUCCESS;
362 PhQueuedLockKeyedEventHandle,
384 _In_ ULONG_PTR Value,
385 _In_ BOOLEAN IgnoreOwned
411 firstWaitBlock = waitBlock;
415 lastWaitBlock = waitBlock->Last;
426 firstWaitBlock->Last = lastWaitBlock;
430 previousWaitBlock = waitBlock;
431 waitBlock = waitBlock->Next;
432 waitBlock->Previous = previousWaitBlock;
440 (PVOID *)&QueuedLock->Value,
484 _In_ ULONG_PTR Value,
485 _In_ BOOLEAN IgnoreOwned,
516 (PVOID *)&QueuedLock->Value,
530 firstWaitBlock = waitBlock;
534 lastWaitBlock = waitBlock->Last;
538 waitBlock = lastWaitBlock;
542 previousWaitBlock = waitBlock;
543 waitBlock = waitBlock->Next;
544 waitBlock->Previous = previousWaitBlock;
553 (previousWaitBlock = waitBlock->Previous)
567 firstWaitBlock->Last = previousWaitBlock;
570 waitBlock->Previous = NULL;
589 (PVOID *)&QueuedLock->Value,
630 previousWaitBlock = waitBlock->Previous;
632 waitBlock = previousWaitBlock;
653 _In_ ULONG_PTR Value,
654 _In_ BOOLEAN IgnoreOwned,
667 previousWaitBlock = waitBlock->Previous;
669 waitBlock = previousWaitBlock;
684 ULONG_PTR currentValue;
688 value = QueuedLock->Value;
695 (PVOID *)&QueuedLock->Value,
696 (PVOID)(value + PH_QUEUED_LOCK_OWNED),
736 ULONG_PTR currentValue;
740 value = QueuedLock->Value;
757 (PVOID *)&QueuedLock->Value,
798 ULONG_PTR currentValue;
800 value = QueuedLock->Value;
818 (PVOID *)&QueuedLock->Value,
830 currentValue = newValue;
833 (PVOID *)&QueuedLock->Value,
858 ULONG_PTR currentValue;
861 value = QueuedLock->Value;
874 (PVOID *)&QueuedLock->Value,
889 if ((ULONG)_InterlockedDecrement((PLONG)&waitBlock->SharedOwners) > 0)
900 (PVOID *)&QueuedLock->Value,
910 currentValue = newValue;
913 (PVOID *)&QueuedLock->Value,
942 value = QueuedLock->Value;
954 (PVOID *)&QueuedLock->Value,
984 (PVOID *)&QueuedLock->Value,
1038 _In_opt_ PLARGE_INTEGER Timeout
1042 ULONG_PTR currentValue;
1046 value = Condition->Value;
1090 _In_opt_ PLARGE_INTEGER Timeout
1094 ULONG_PTR currentValue;
1098 value = Condition->Value;
1129 if (!(Flags & PH_CONDITION_WAIT_SHARED))
1145 switch (Flags & PH_CONDITION_WAIT_LOCK_TYPE_MASK)
1157 if (!(Flags & PH_CONDITION_WAIT_SHARED))
1193 WaitBlock->Next = value;
1196 (PVOID *)&WakeEvent->Value,
1227 nextWaitBlock = waitBlock->Next;
1229 waitBlock = nextWaitBlock;
1278 _In_opt_ PLARGE_INTEGER Timeout
1285 if (status != STATUS_SUCCESS)