36 #define PH_LOCK_OWNED 0x1
37 #define PH_LOCK_EXCLUSIVE_WAKING 0x2
39 #define PH_LOCK_SHARED_OWNERS_SHIFT 2
40 #define PH_LOCK_SHARED_OWNERS_MASK 0x3ff
41 #define PH_LOCK_SHARED_OWNERS_INC 0x4
43 #define PH_LOCK_SHARED_WAITERS_SHIFT 12
44 #define PH_LOCK_SHARED_WAITERS_MASK 0x3ff
45 #define PH_LOCK_SHARED_WAITERS_INC 0x1000
47 #define PH_LOCK_EXCLUSIVE_WAITERS_SHIFT 22
48 #define PH_LOCK_EXCLUSIVE_WAITERS_MASK 0x3ff
49 #define PH_LOCK_EXCLUSIVE_WAITERS_INC 0x400000
51 #define PH_LOCK_EXCLUSIVE_MASK \
52 (PH_LOCK_EXCLUSIVE_WAKING | \
53 (PH_LOCK_EXCLUSIVE_WAITERS_MASK << PH_LOCK_EXCLUSIVE_WAITERS_SHIFT))
60 FastLock->ExclusiveWakeEvent = NULL;
61 FastLock->SharedWakeEvent = NULL;
68 if (FastLock->ExclusiveWakeEvent)
70 NtClose(FastLock->ExclusiveWakeEvent);
71 FastLock->ExclusiveWakeEvent = NULL;
74 if (FastLock->SharedWakeEvent)
76 NtClose(FastLock->SharedWakeEvent);
77 FastLock->SharedWakeEvent = NULL;
82 _Inout_ PHANDLE Handle
90 NtCreateSemaphore(&handle, SEMAPHORE_ALL_ACCESS, NULL, 0, MAXLONG);
124 value = FastLock->Value;
128 if (_InterlockedCompareExchange(
135 else if (i >= spinCount)
139 if (_InterlockedCompareExchange(
145 if (NtWaitForSingleObject(
146 FastLock->ExclusiveWakeEvent,
154 value = FastLock->Value;
155 }
while (_InterlockedCompareExchange(
182 value = FastLock->Value;
190 if (_InterlockedCompareExchange(
203 if (_InterlockedCompareExchange(
210 else if (i >= spinCount)
214 if (_InterlockedCompareExchange(
220 if (NtWaitForSingleObject(
221 FastLock->SharedWakeEvent,
244 value = FastLock->Value;
248 if (_InterlockedCompareExchange(
254 NtReleaseSemaphore(FastLock->ExclusiveWakeEvent, 1, NULL);
265 if (_InterlockedCompareExchange(
272 NtReleaseSemaphore(FastLock->SharedWakeEvent, sharedWaiters, 0);
290 value = FastLock->Value;
294 if (_InterlockedCompareExchange(
303 if (_InterlockedCompareExchange(
310 NtReleaseSemaphore(FastLock->ExclusiveWakeEvent, 1, NULL);
317 if (_InterlockedCompareExchange(
335 value = FastLock->Value;
340 return _InterlockedCompareExchange(
353 value = FastLock->Value;
360 return _InterlockedCompareExchange(
368 return _InterlockedCompareExchange(