RtlInitializeResource

Go to Home Page

Initializes a fat read/write lock structure

Syntax

void WINAPI RtlInitializeResource (
    PRTL_RESOURCE pResource
)

Parameters

pResource
A pointer to the caller allocated structure to initialize

Return Value

None

Remarks

A fat read/write lock works exactly like the SRW locks featured in the Windows SDK. The main difference is that these fat versions can be acquired recursively. Access cannot be upgraded from shared to exclusive without releasing the lock first but shared access will be granted if the thread already has exclusive access.

The resource must be freed with RtlDeleteResource when it is no longer required

The definition of RTL_RESOURCE is as follows:

#define RTL_RESOURCE_WAIT_INDEFINITIELY 0x1
typedef struct _RTL_RESOURCE
{
    CRITICAL_SECTION CSection;
    HANDLE hSharedSemaphore;
    ULONG sharedExclusive;
    HANDLE hExclusiveSemaphore;
    ULONG exclusiveWaiters;
    ULONG numberOfWaiters;
    HANDLE hOwnerThread;
    ULONG flags;
    PRTL_RESOURCE_DEBUG DebugInfo;
} RTL_RESOURCE, *PRTL_RESOURCE;

After initialization, flags can be set to RTL_RESOURCE_WAIT_INDEFINITIELY to change the wait timeout in the RtlAcquireResource* functions. Setting the bit enables infinite waits. Without it, the wait timeout is the value of Peb->CriticalSectionTimeout which defaults to 30 days.