ExAcquireSharedWaitForExclusive - NtDoc

Native API online documentation, based on the System Informer (formerly Process Hacker) phnt headers
// wdm.h

BOOLEAN ExAcquireSharedWaitForExclusive(
  [in, out] PERESOURCE Resource,
  [in]      BOOLEAN    Wait
);

View the official Windows Driver Kit DDI reference

NtDoc

No description available.

Windows Driver Kit DDI reference (nf-wdm-exacquiresharedwaitforexclusive)

ExAcquireSharedWaitForExclusive function

Description

The ExAcquireSharedWaitForExclusive routine acquires the given resource for shared access if shared access can be granted and there are no exclusive waiters.

Parameters

Resource [in, out]

A pointer to the resource to be acquired for shared access.

Wait [in]

Specifies the routine's behavior whenever the resource cannot be acquired immediately. If TRUE, the caller is put into a wait state until the resource can be acquired. If FALSE, the routine immediately returns, regardless of whether the resource can be acquired.

Return value

ExAcquireSharedWaitForExclusive returns TRUE if the requested access is granted or an exclusive owner releases the resource. This routine returns FALSE if the input Wait is FALSE and shared access cannot be granted immediately.

Remarks

Most drivers should use ExAcquireResourceSharedLite instead of ExAcquireSharedWaitForExclusive.

The caller can release the resource by calling either ExReleaseResourceLite or ExReleaseResourceForThreadLite.

If shared access cannot be granted immediately, the caller can wait for other threads to acquire and release exclusive ownership of the resource.

Whether or when the caller is given shared access to the given resource depends on the following:

The behavior of ExAcquireSharedWaitForExclusive is identical to that of ExAcquireResourceSharedLite unless the calling thread already owns the resource as shared and there are exclusive waiters. In that case, ExAcquireSharedWaitForExclusive allows the exclusive waiters to acquire exclusive ownership of the resource.

If the caller specifies TRUE for the Wait parameter, the caller blocks until another thread frees the resource on behalf of the caller, using ExReleaseResourceForThread. Driver writers must be careful to ensure that another thread actually releases the resource; otherwise the caller is deadlocked. ExAcquireResourceSharedLite does not have this property, so drivers should use that routine unless they require the particular behavior of ExAcquireSharedWaitForExclusive.

Normal kernel APC delivery must be disabled before calling this routine. Disable normal kernel APC delivery by calling KeEnterCriticalRegion. Delivery must remain disabled until the resource is released, at which point it can be reenabled by calling KeLeaveCriticalRegion. For more information, see Disabling APCs.

See also

ExAcquireResourceSharedLite

ExAcquireSharedStarveExclusive

ExConvertExclusiveToSharedLite

ExGetExclusiveWaiterCount

ExIsResourceAcquiredExclusiveLite

ExIsResourceAcquiredSharedLite

ExReleaseResourceForThread