-static BOOLEAN
-ExLockHandleTableEntryNoDestructionCheck(IN PHANDLE_TABLE HandleTable,
- IN PHANDLE_TABLE_ENTRY Entry)
-{
- ULONG_PTR Current, New;
-
- PAGED_CODE();
-
- DPRINT("Entering handle table entry 0x%p lock...\n", Entry);
-
- ASSERT(HandleTable);
- ASSERT(Entry);
-
- for(;;)
- {
- Current = (volatile ULONG_PTR)Entry->u1.Object;
-
- if(!Current)
- {
- DPRINT("Attempted to lock empty handle table entry 0x%p or handle table shut down\n", Entry);
- break;
- }
-
- if(!(Current & EX_HANDLE_ENTRY_LOCKED))
- {
- New = Current | EX_HANDLE_ENTRY_LOCKED;
- if(InterlockedCompareExchangePointer(&Entry->u1.Object,
- (PVOID)New,
- (PVOID)Current) == (PVOID)Current)
- {
- DPRINT("SUCCESS handle table 0x%p entry 0x%p lock\n", HandleTable, Entry);
- /* we acquired the lock */
- return TRUE;
- }
- }
-
- /* wait about 5ms at maximum so we don't wait forever in unfortunate
- co-incidences where releasing the lock in another thread happens right
- before we're waiting on the contention event to get pulsed, which might
- never happen again... */
- KeWaitForSingleObject(&HandleTable->HandleContentionEvent,
- Executive,
- KernelMode,
- FALSE,
- &ExpHandleShortWait);
- }
-
- return FALSE;
-}
-