NXRwLockAlloc

Allocates and initializes a reader-writer lock.

Library:LibC
Classification:NKS
Service:Synchronization

Syntax

  #include <nks/synch.h>
   
  NXRwLock_t *NXRwLockAlloc (
     NXHierarchy_t          hierarchy, 
     const NXLockInfo_t    *info);
  

Parameters

hierarchy

(IN) Specifies the hierarchy value to be associated with the mutex. It specifies the order in which this mutex can be acquired relative to other mutexes a context can own. If a context wants to acquire a mutex unconditionally (see NXLock), this value for the mutex being acquired must be greater than the value of any mutexes that the context is currently holding.

info

(IN) Points to the information block to be associated with the reader-writer lock.

Return Values

If successful, returns a pointer to the allocated reader-writer lock; otherwise returns a NULL pointer.

Remarks

Because the NXRwLockAlloc function allocates and initializes the lock, do not followed it with a call to NXRwLockInit.

A reader-writer lock can be acquired either in the read mode or in the write mode. When the lock is held in the read mode, the lock can be held by multiple contexts and can enhance concurrency when the state protected by the lock is mostly read-only.

Imposing strict ordering among all locks in the application that can be held by a context at the same time avoids deadlock. Hierarchy violations are checked only if the application is built with the following options: DEBUG and _LOCKSTEST.

Nonrecursive mutexes can be implemented to work faster.

See Also