Edit

Share via


SRWLock Class

Represents a slim reader/writer lock.

Syntax

class SRWLock;

Remarks

A slim reader/writer lock is used to synchronize access across threads to an object or resource. For more information, see Synchronization Functions.

Members

Public Typedefs

Name Description
SyncLockExclusive Synonym for an SRWLock object that is acquired in exclusive mode.
SyncLockShared Synonym for an SRWLock object that is acquired in shared mode.

Public Constructors

Name Description
SRWLock::SRWLock Initializes a new instance of the SRWLock class.
SRWLock::~SRWLock Deinitializes an instance of the SRWLock class.

Public Methods

Name Description
SRWLock::LockExclusive Acquires an SRWLock object in exclusive mode.
SRWLock::LockShared Acquires an SRWLock object in shared mode.
SRWLock::TryLockExclusive Attempts to acquire a SRWLock object in exclusive mode for the current or specified SRWLock object.
SRWLock::TryLockShared Attempts to acquire a SRWLock object in shared mode for the current or specified SRWLock object.

Protected Data Member

Name Description
SRWLock::SRWLock_ Contains the underlying lock variable for the current SRWLock object.

Inheritance Hierarchy

SRWLock

Requirements

Header: corewrappers.h

Namespace: Microsoft::WRL::Wrappers

SRWLock::~SRWLock

Deinitializes an instance of the SRWLock class.

~SRWLock();

SRWLock::LockExclusive

Acquires an SRWLock object in exclusive mode.

SyncLockExclusive LockExclusive();

static SyncLockExclusive LockExclusive(
   _In_ SRWLOCK* lock
);

Parameters

lock
Pointer to an SRWLock object.

Return Value

An SRWLock object in exclusive mode.

SRWLock::LockShared

Acquires an SRWLock object in shared mode.

SyncLockShared LockShared();

static SyncLockShared LockShared(
   _In_ SRWLOCK* lock
);

Parameters

lock
Pointer to an SRWLock object.

Return Value

An SRWLock object in shared mode.

SRWLock::SRWLock

Initializes a new instance of the SRWLock class.

SRWLock();

SRWLock::SRWLock_

Contains the underlying lock variable for the current SRWLock object.

SRWLOCK SRWLock_;

SRWLock::TryLockExclusive

Attempts to acquire a SRWLock object in exclusive mode for the current or specified SRWLock object. If the call is successful, the calling thread takes ownership of the lock.

SyncLockExclusive TryLockExclusive();

static SyncLockExclusive TryLockExclusive(
   _In_ SRWLOCK* lock
);

Parameters

lock
Pointer to an SRWLock object.

Return Value

If successful, an SRWLock object in exclusive mode and the calling thread takes ownership of the lock. Otherwise, an SRWLock object whose state is invalid.

SRWLock::TryLockShared

Attempts to acquire a SRWLock object in shared mode for the current or specified SRWLock object.

WRL_NOTHROW SyncLockShared TryLockShared();
WRL_NOTHROW static SyncLockShared TryLockShared(
   _In_ SRWLOCK* lock
);

Parameters

lock
Pointer to an SRWLock object.

Return Value

If successful, an SRWLock object in shared mode and the calling thread takes ownership of the lock. Otherwise, an SRWLock object whose state is invalid.