NXRwLockUpgrade

Converts the specified reader-writer lock from read mode to write mode.

Library:LibC
Classification:NKS
Service:Synchronization

Syntax

  #include <nks/synch.h>
   
  int NXRwLockUpgrade (
     NXRwLock_t  *lock);
  

Parameters

lock

(IN) Points to the reader-writer lock to upgrade.

Return Values

If successful, returns 0; otherwise returns a nonzero error code:

Decimal

Hex

Constant

Description

9

0x09

NX_EINVAL

The mutex is not a valid mutex.

16

0x10

NX_EINUSE

The attempt to upgrade failed because another thread was already waiting to upgrade. The read lock previously held has been released.

66

0x42

NX_ENOSYS

This operation is not supported on this platform.

69

0x45

NX_EPERM

The lock has not been previously acquired for reading.

Remarks

The specified lock must be a lock already acquired in read mode and the lock must be owned by the calling thread.

The first thread, which should have acquired the read lock previously, that requests this upgrade is guaranteed to acquire it before any waiting writers. Hence, when this call returns successfully, the calling thread no longer holds a read lock, but owns the write lock which obviously no other writer is granted.

The advantage of an upgrade operation when compared to releasing a read lock to then acquire the write lock is that, if successful, the acquiring thread can be assured that the data protected by the lock has not been modified in the intervening moments of the upgrade. Consequently, it need not re-examine the data protected by the lock to see if it has changed.

See Also