NXLock

Locks the specified mutex.

Library:LibC
Classification:NKS
Service:Synchronization

Syntax

  #include <nks/synch.h>
   
  int NXLock(
     NXMutex_t  *mutex);
  

Parameters

mutex

(IN) Points to the mutex to lock. It is expected that the hierarchy value of this mutex is greater than any of the mutexes that might be currently held by this context. (For a discussion on lock hierarchy, see NXMutexAlloc or NXMutexInit.)

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.

Remarks

NXLock acquires the specified mutually exclusive lock. If the lock being acquired is not free (is held by a different context), the calling thread waits until the lock can be acquired. No assumptions can be made about the way the calling thread might wait for the lock to become free. The mutex is not guaranteed to be FIFO.

NKS mutexes are nonrecursive by default. If you are using a nonrecursive mutex in debug mode and try to acquire the mutex that you already locked, an assertion is generated with a message containing the filename and the line number of the offending call.

NXLock is a macro unless NDEBUG is defined; otherwise, it consumes NXMutexTestFlag, a function which should only be used for debugging and which produces an assertion if the mutex is used recursively. In production code, NDEBUG should be defined.

For sample code, see Mutex.c.

See Also