ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

VOID FASTCALL ExpWaitForResource ( IN PERESOURCE  Resource,
IN PVOID  Object 
)

Definition at line 618 of file resource.c.

Referenced by ExAcquireResourceExclusiveLite(), ExAcquireResourceSharedLite(), ExAcquireSharedStarveExclusive(), and ExAcquireSharedWaitForExclusive().

{
    ULONG i;
    ULONG Size;
    POWNER_ENTRY Owner;
    ULONG WaitCount = 0;
    NTSTATUS Status;
    LARGE_INTEGER Timeout;
    PKTHREAD Thread, OwnerThread;
#if DBG
    KLOCK_QUEUE_HANDLE LockHandle;
#endif

    /* Increase contention count and use a 5 second timeout */
    Resource->ContentionCount++;
    Timeout.QuadPart = 500 * -10000;
    for (;;)
    {
        /* Wait for ownership */
        Status = KeWaitForSingleObject(Object,
                                       WrResource,
                                       KernelMode,
                                       FALSE,
                                       &Timeout);
        if (Status != STATUS_TIMEOUT) break;

        /* Increase wait count */
        WaitCount++;
        Timeout = ExpTimeout;

        /* Check if we've exceeded the limit */
        if (WaitCount > ExpResourceTimeoutCount)
        {
            /* Reset wait count */
            WaitCount = 0;
#if DBG
            /* Lock the resource */
            ExAcquireResourceLock(Resource, &LockHandle);

            /* Dump debug information */
            DPRINT1("Resource @ %lx\n", Resource);
            DPRINT1(" ActiveEntries = %04lx  Flags = %s%s%s\n",
                    Resource->ActiveEntries,
                    IsOwnedExclusive(Resource) ? "IsOwnedExclusive " : "",
                    IsSharedWaiting(Resource) ? "SharedWaiter "     : "",
                    IsExclusiveWaiting(Resource) ? "ExclusiveWaiter "  : "");
            DPRINT1(" NumberOfExclusiveWaiters = %04lx\n",
                    Resource->NumberOfExclusiveWaiters);
            DPRINT1("   Thread = %08lx, Count = %02x\n",
                    Resource->OwnerEntry.OwnerThread,
                    Resource->OwnerEntry.OwnerCount);

            /* Dump out the table too */
            Owner = Resource->OwnerTable;
            if (Owner)
            {
                /* Loop every entry */
                Size = Owner->TableSize;
                for (i = 1; i < Size; i++)
                {
                    /* Print the data */
                    Owner++;
                    DPRINT1("   Thread = %08lx, Count = %02x\n",
                            Owner->OwnerThread,
                            Owner->OwnerCount);
                }
            }

            /* Break */
            DbgBreakPoint();
            DPRINT1("EX - Rewaiting\n");
            ExReleaseResourceLock(Resource, &LockHandle);
#endif
        }

        /* Check if we can boost */
        if (IsBoostAllowed(Resource))
        {
            /* Get the current kernel thread and lock the dispatcher */
            Thread = KeGetCurrentThread();
            Thread->WaitIrql = KiAcquireDispatcherLock();
            Thread->WaitNext = TRUE;

            /* Get the owner thread and boost it */
            OwnerThread = (PKTHREAD)Resource->OwnerEntry.OwnerThread;
            if (OwnerThread) ExpBoostOwnerThread(Thread, OwnerThread);

            /* If it's a shared resource */
            if (!IsOwnedExclusive(Resource))
            {
                /* Get the table */
                Owner = Resource->OwnerTable;
                if (Owner)
                {
                    /* Loop every entry */
                    Size = Owner->TableSize;
                    for (i = 1; i < Size; i++)
                    {
                        /* Move to next entry */
                        Owner++;

                        /* Get the thread */
                        OwnerThread = (PKTHREAD)Owner->OwnerThread;

                        /* Boost it */
                        if (OwnerThread) ExpBoostOwnerThread(Thread, OwnerThread);
                    }
                }
            }
        }
    }
}

Generated on Sun May 27 2012 05:04:43 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.