NXMutexInit

Initializes a mutex.

Library:LibC
Classification:NKS
Service:Synchronization

Syntax

  #include <nks/synch.h>
   
  int NXMutexInit(
     NXMutex_t            *mutex, 
     unsigned long         flags,
     NXHierarchy_t         hierarchy,
     const NXLockInfo_t   *info);
  

Parameters

mutex

(IN) Points to the mutex to be initialized.

flags

(IN) Specifies the special attributes for the mutex and determines whether a mutex can be used recursively. By default (flags contains zero), a mutex is nonrecursive. If you want a recursive mutex, set flags to NX_MUTEX_RECURSIVE (0x00000001).

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 mutex.

Return Values

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

Decimal

Hex

Constant

Description

5

0x05

NX_ENOMEM

Insufficient memory to complete this call

9

0x09

NX_EINVAL

The flags parameter contains illegal values

Remarks

Mutually exclusive locks are acquired by threads on behalf of the context that they are hosting.

To help avoid deadlock, you should impose strict ordering among all locks in the application that a thread can be hold at the same time. Hierarchy violations are checked only if the application is built with the compilation options, DEBUG and _LOCKTEST.

Nonrecursive mutexes can be implemented to work faster.

For sample code, see Mutex.c.

See Also