SleepConditionVariableSRW

SleepConditionVariableSRW atomically releases the SRW lock and waits on the condition variable. When awakened, the SRW lock is automatically reacquired in the same mode (shared or exclusive) before returning.

Syntax

Copy
BOOL SleepConditionVariableSRW(
    PCONDITION_VARIABLE pConditionVariable,
    PSRWLOCK pSrwLock,
    DWORD dwMilliseconds,
    ULONG flags
);

Parameters

pConditionVariable

A pointer to the condition variable.

pSrwLock

A pointer to the SRW lock to release. The SRW lock must be owned by caller.

dwMilliseconds

The timeout interval in milliseconds. Use INFINITE for no timeout.

flags

Lock mode flags (CONDITION_VARIABLE_LOCKMODE_SHARED or 0 for exclusive).

Return Value

This function returns TRUE if signaled. It returns FALSE if a timeout or error occurs.

Remarks

Requirements

Minimum supported version Header Library

wRTOS 1.1 SDK

windows.h

wRTOS_rtss.lib

Example

Copy
CONDITION_VARIABLE cv;
SRWLOCK lock;
BOOL condition = FALSE;

InitializeConditionVariable(&cv);
InitializeSRWLock(&lock);

// Exclusive mode example
AcquireSRWLockExclusive(&lock);
while (!condition) {
    SleepConditionVariableSRW(&cv, &lock, INFINITE, 0);
}
ReleaseSRWLockExclusive(&lock);

// Shared mode example
AcquireSRWLockShared(&lock);
while (!condition) {
    SleepConditionVariableSRW(&cv, &lock, INFINITE,
                              CONDITION_VARIABLE_LOCKMODE_SHARED);
}
ReleaseSRWLockShared(&lock);

See Also: