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
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
- The SRW lock is released atomically before waiting and reacquired in the same mode before the function returns.
- Use flags = CONDITION_VARIABLE_LOCKMODE_SHARED (0x1) if holding a shared lock.
- Use flags = 0 if holding an exclusive lock.
- The caller must hold the lock in the mode specified by flags.
- On timeout, this function sets last error to ERROR_TIMEOUT.
- This function sets ERROR_INVALID_PARAMETER if parameters are NULL.
- The implementation trusts the caller’s flags parameter.
Requirements
| Minimum supported version | Header | Library |
|---|---|---|
|
wRTOS 1.1 SDK |
windows.h |
wRTOS_rtss.lib |
Example
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:
- RTL_CONDITION_VARIABLE
- InitializeConditionVariable
- SleepConditionVariableCS
- WakeConditionVariable
- WakeAllConditionVariable