ReactOS Fundraising Campaign 2012
 
€ 11,198 / € 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

BOOLEAN NTAPI ExAcquireResourceExclusiveLite ( IN PERESOURCE  Resource,
IN BOOLEAN  Wait 
)

Definition at line 770 of file resource.c.

Referenced by CdfsAcquireForLazyWrite(), CdfsCleanup(), CdfsCreate(), CdfsShortNameCacheGet(), CdfsVerifyVolume(), CmpLockHiveFlusherExclusive(), CmpLockRegistryExclusive(), CountAvailableClusters(), DxEngLockHdev(), ExAcquireTimeRefreshLock(), ExEnterCriticalRegionAndAcquireResourceExclusive(), Ext2AcqLazyWrite(), Ext2CloseClosableFCB(), Ext2CommonCleanup(), Ext2CommonClose(), Ext2CommonCreate(), Ext2CommonFileInfo(), Ext2CommonFlush(), Ext2CommonWrite(), Ext2CreateFile(), Ext2FastIoAcqCreateSec(), Ext2FlushLogicalVolume(), Ext2InitializeVCB(), Ext2QueryDirectory(), FatAcquireExclusiveFcb(), FatAcquireExclusiveVcb(), FatiCleanup(), FatiCleanVcbs(), FatiCommonClose(), FatiOpenExistingFcb(), FatiOverwriteFile(), FatPendingClose(), FatSetEndOfFileInfo(), FsRtlCopyWrite(), FsRtlPrepareMdlWriteDev(), GetNextClusterExtend(), IntGdiAcquireSemaphore(), IoEnumerateRegisteredFiltersList(), IopBootLog(), IopCreateLogFile(), IopSaveBootLogToFile(), IoRegisterFileSystem(), IoRegisterFsRegistrationChange(), IoShutdownSystem(), IoUnregisterFileSystem(), IoUnregisterFsRegistrationChange(), KsAcquireDeviceSecurityLock(), KspSynchronizedEventRoutine(), MiProcessLoaderEntry(), NtfsFsdCreate(), ObpAcquireObjectLock(), ObpEnterObjectTypeMutex(), QSI_DEF(), ReadVolumeLabel(), RtlEnterHeapLock(), UserEnterExclusive(), VfatAcquireForCcFlush(), VfatAcquireForLazyWrite(), VfatAcquireForReadAhead(), VfatCleanup(), VfatCleanupFile(), VfatClose(), VfatCreate(), VfatCreateFile(), VfatFlush(), VfatFlushVolume(), VfatMount(), VfatSetInformation(), VfatSetVolumeInformation(), VfatShutdown(), VfatWrite(), and WriteCluster().

{
    KLOCK_QUEUE_HANDLE LockHandle;
    ERESOURCE_THREAD Thread;
    BOOLEAN Success;

    /* Sanity check */
    ASSERT((Resource->Flag & ResourceNeverExclusive) == 0);

    /* Get the thread */
    Thread = ExGetCurrentResourceThread();

    /* Sanity check and validation */
    ASSERT(KeIsExecutingDpc() == FALSE);
    ExpVerifyResource(Resource);

    /* Acquire the lock */
    ExAcquireResourceLock(Resource, &LockHandle);
    ExpCheckForApcsDisabled(LockHandle.OldIrql, Resource, (PKTHREAD)Thread);

    /* Check if there is a shared owner or exclusive owner */
TryAcquire:
    if (Resource->ActiveEntries)
    {
        /* Check if it's exclusively owned, and we own it */   
        if ((IsOwnedExclusive(Resource)) &&
            (Resource->OwnerEntry.OwnerThread == Thread))
        {
            /* Increase the owning count */
            Resource->OwnerEntry.OwnerCount++;
            Success = TRUE;
        }
        else
        {
            /*
             * If the caller doesn't want us to wait, we can't acquire the
             * resource because someone else then us owns it. If we can wait,
             * then we'll wait.
             */
            if (!Wait)
            {
                Success = FALSE;
            }
            else
            {
                /* Check if it has exclusive waiters */
                if (!Resource->ExclusiveWaiters)
                {
                    /* It doesn't, allocate the event and try acquiring again */
                    ExpAllocateExclusiveWaiterEvent(Resource, &LockHandle);
                    goto TryAcquire;
                }

                /* Has exclusive waiters, wait on it */
                Resource->NumberOfExclusiveWaiters++;
                ExReleaseResourceLock(Resource, &LockHandle);
                ExpWaitForResource(Resource, Resource->ExclusiveWaiters);

                /* Set owner and return success */
                Resource->OwnerEntry.OwnerThread = ExGetCurrentResourceThread();
                return TRUE;
            }
        }
    }
    else
    {
        /* Nobody owns it, so let's! */
        ASSERT(Resource->ActiveEntries == 0);
        ASSERT(Resource->ActiveCount == 0);
        Resource->Flag |= ResourceOwnedExclusive;
        Resource->ActiveEntries = 1;
        Resource->ActiveCount = 1;
        Resource->OwnerEntry.OwnerThread = Thread;
        Resource->OwnerEntry.OwnerCount = 1;
        Success = TRUE;
    }

    /* Release the lock and return */
    ExReleaseResourceLock(Resource, &LockHandle);
    return Success;
}

Generated on Thu Oct 25 2012 05:02:04 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.