1 #ifndef _PH_QUEUEDLOCK_H
2 #define _PH_QUEUEDLOCK_H
8 #define PH_QUEUED_LOCK_OWNED ((ULONG_PTR)0x1)
9 #define PH_QUEUED_LOCK_OWNED_SHIFT 0
10 #define PH_QUEUED_LOCK_WAITERS ((ULONG_PTR)0x2)
13 #define PH_QUEUED_LOCK_SHARED_INC ((ULONG_PTR)0x4)
14 #define PH_QUEUED_LOCK_SHARED_SHIFT 2
17 #define PH_QUEUED_LOCK_TRAVERSING ((ULONG_PTR)0x4)
18 #define PH_QUEUED_LOCK_MULTIPLE_SHARED ((ULONG_PTR)0x8)
20 #define PH_QUEUED_LOCK_FLAGS ((ULONG_PTR)0xf)
22 #define PhGetQueuedLockSharedOwners(Value) \
23 ((ULONG_PTR)(Value) >> PH_QUEUED_LOCK_SHARED_SHIFT)
24 #define PhGetQueuedLockWaitBlock(Value) \
25 ((PPH_QUEUED_WAIT_BLOCK)((ULONG_PTR)(Value) & ~PH_QUEUED_LOCK_FLAGS))
32 #define PH_QUEUED_LOCK_INIT { 0 }
34 #define PH_QUEUED_WAITER_EXCLUSIVE 0x1
35 #define PH_QUEUED_WAITER_SPINNING 0x2
36 #define PH_QUEUED_WAITER_SPINNING_SHIFT 1
42 struct _PH_QUEUED_WAIT_BLOCK *Next;
45 struct _PH_QUEUED_WAIT_BLOCK *Previous;
48 struct _PH_QUEUED_WAIT_BLOCK *Last;
59 _Out_ PPH_QUEUED_LOCK QueuedLock
62 QueuedLock->Value = 0;
69 _Inout_ PPH_QUEUED_LOCK QueuedLock
76 _Inout_ PPH_QUEUED_LOCK QueuedLock
83 _Inout_ PPH_QUEUED_LOCK QueuedLock
90 _Inout_ PPH_QUEUED_LOCK QueuedLock
97 _Inout_ PPH_QUEUED_LOCK QueuedLock
104 _Inout_ PPH_QUEUED_LOCK QueuedLock,
108 #define PhPulseCondition PhfPulseCondition
113 _Inout_ PPH_QUEUED_LOCK Condition
116 #define PhPulseAllCondition PhfPulseAllCondition
121 _Inout_ PPH_QUEUED_LOCK Condition
124 #define PhWaitForCondition PhfWaitForCondition
129 _Inout_ PPH_QUEUED_LOCK Condition,
130 _Inout_ PPH_QUEUED_LOCK Lock,
131 _In_opt_ PLARGE_INTEGER Timeout
134 #define PH_CONDITION_WAIT_QUEUED_LOCK 0x1
135 #define PH_CONDITION_WAIT_CRITICAL_SECTION 0x2
136 #define PH_CONDITION_WAIT_FAST_LOCK 0x4
137 #define PH_CONDITION_WAIT_LOCK_TYPE_MASK 0xfff
139 #define PH_CONDITION_WAIT_SHARED 0x1000
140 #define PH_CONDITION_WAIT_SPIN 0x2000
142 #define PhWaitForConditionEx PhfWaitForConditionEx
147 _Inout_ PPH_QUEUED_LOCK Condition,
150 _In_opt_ PLARGE_INTEGER Timeout
153 #define PhQueueWakeEvent PhfQueueWakeEvent
158 _Inout_ PPH_QUEUED_LOCK WakeEvent,
159 _Out_ PPH_QUEUED_WAIT_BLOCK WaitBlock
166 _Inout_ PPH_QUEUED_LOCK WakeEvent,
167 _Inout_opt_ PPH_QUEUED_WAIT_BLOCK WaitBlock
170 #define PhWaitForWakeEvent PhfWaitForWakeEvent
175 _Inout_ PPH_QUEUED_LOCK WakeEvent,
176 _Inout_ PPH_QUEUED_WAIT_BLOCK WaitBlock,
178 _In_opt_ PLARGE_INTEGER Timeout
183 _Acquires_exclusive_lock_(*QueuedLock)
185 _Inout_ PPH_QUEUED_LOCK QueuedLock
195 _Acquires_shared_lock_(*QueuedLock)
197 _Inout_ PPH_QUEUED_LOCK QueuedLock
201 (PVOID *)&QueuedLock->Value,
210 _When_(
return != 0, _Acquires_exclusive_lock_(*QueuedLock))
211 FORCEINLINE BOOLEAN PhTryAcquireQueuedLockExclusive(
212 _Inout_ PPH_QUEUED_LOCK QueuedLock
225 _Releases_exclusive_lock_(*QueuedLock)
227 _Inout_ PPH_QUEUED_LOCK QueuedLock
240 _Releases_shared_lock_(*QueuedLock)
242 _Inout_ PPH_QUEUED_LOCK QueuedLock
250 (PVOID *)&QueuedLock->Value,
260 _Inout_ PPH_QUEUED_LOCK QueuedLock
277 _Inout_ PPH_QUEUED_LOCK QueuedLock
293 _Inout_ PPH_QUEUED_LOCK WakeEvent,
294 _Inout_opt_ PPH_QUEUED_WAIT_BLOCK WaitBlock
303 if (WakeEvent->Value || WaitBlock)