NXTryLock

Makes a single attempt to acquire the specified mutex.

Library:LibC
Classification:NKS
Service:Synchronization

Syntax

  #include <nks/synch.h>
   
  NXBool_t  NXTryLock(
     NXMutex_t  *mutex);
  

Parameters

mutex

(IN) Points to the mutex to acquire.

Return Values

TRUE

The calling thread owns the specified lock in the specified mode.

FALSE

The calling thread does not own the specified lock in the specified mode.

Remarks

Because this is a conditional acquisition, the hierarchy constraint for locks is relaxed for this acquisition. If the lock being acquired is not available (is held by a different context), NXTryLock makes no further attempt and returns FALSE.

NXTryLock 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