RReadWriteLock Class Reference
Detailed Description
A read-write lock.
This is a lock for co-ordinating readers and writers to shared resources. It is designed to allow multiple concurrent readers. It is not a kernel side object and so does not inherit from RHandleBase.
Member Enumeration Documentation
Enum TReadWriteLockClientCategoryLimit
Enumerator | Value | Description |
---|
EReadWriteLockClientCategoryLimit | KMaxTUint16 |
Maximum number of clients in each category: read locked, read lock pending, write lock pending
|
Enum TReadWriteLockPriority
Enumerator | Value | Description |
---|
EWriterPriority | |
Pending writers always get the lock before pending readers
|
EAlternatePriority | |
Lock is given alternately to pending readers and writers
|
EReaderPriority | |
Pending readers always get the lock before pending writers - beware writer starvation!
|
Constructor & Destructor Documentation
Member Function Documentation
Close ( )
Close a read-write lock object, releasing the associated semaphores.
- panic
- EReadWriteLockStillPending if there are any outstanding clients or pending clients
CreateLocal ( TReadWriteLockPriority )
Initialise a read-write lock object.
- panic
- EReadWriteLockInvalidPriority if aPriority is not valid.
Parameter | Description | aPriority | Type of priority to use - see RReadWriteLockPriority::TReadWriteLockPriority |
Returns: KErrNone Instance successfully created Otherwise an error returned by RSemaphore::CreateLocal
DowngradeWriteLock ( )
IMPORT_C void | DowngradeWriteLock | ( | ) | |
Atomically releases a held write lock and gains a read lock. Also unblocks any pending readers if:
ReadLock ( )
Ask for a read lock. Will be granted if: 1) No-one else currently holds the lock or 2) Only readers hold the lock and: a) There are no pending writers or b) The priority is for readers. Otherwise this function blocks until the lock becomes available to it. Please note that
ReadLock() is not re-entrant - calling it a second time without releasing the first lock runs the risk of being blocked and risking a deadlock situation.
- panic
- EReadWriteLockTooManyClients if the resulting number of readers or pending readers exceeds EReadWriteLockClientCategoryLimit
TryReadLock ( )
IMPORT_C TBool | TryReadLock | ( | ) | |
Ask for a read lock without blocking.
- panic
- EReadWriteLockTooManyClients if the resulting number of readers exceeds EReadWriteLockClientCategoryLimit
See also: ReadLock()
Returns: ETrue - lock granted EFalse - failed to obtain the lock
TryUpgradeReadLock ( )
IMPORT_C TBool | TryUpgradeReadLock | ( | ) | |
Tries to atomically release a read lock and gain a write lock. This function will succeed if:
This is the only reader and
Returns: ETrue - write lock granted EFalse - failed to obtain a write lock, read lock retained
TryWriteLock ( )
IMPORT_C TBool | TryWriteLock | ( | ) | |
Ask for a write lock without blocking.
See also: WriteLock()
Returns: ETrue - lock granted EFalse - failed to obtain the lock
Unlock ( )
Releases a held read or write lock. If no-one else holds this lock (ie other readers) then this will unblock one or more pending clients based on the priority: EAlternatePriority - If a read lock is being released then:
Give the lock to the first pending writer, if there is one
Else give the lock to all pending readers, if there are any
If a write lock is being released then:
If there are pending readers:
Else unblock one pending writer, if there is one EReaderPriority - Unblock all pending readers. If none then unblock one pending writer, if there is one EWriterPriority - Unblock one pending writer, if there is one. If none then unblock any and all pending readers
- panic
- EReadWriteLockBadLockState if the lock is not currently held
WriteLock ( )
Ask for a write lock. Will be granted if no-one else currently holds the lock. Otherwise this function blocks until the lock becomes available to it. Only one writer can hold the lock at one time. No readers can hold the lock while a writer has it. Please note that
WriteLock() is not re-entrant - calling it a second time without releasing the first lock will block and cause a deadlock situation.
- panic
- EReadWriteLockTooManyClients if the resulting number of pending writers exceeds EReadWriteLockClientCategoryLimit