mxStatus (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

ALL

Firmware version:

1.00 / 1.00.00


The mxStatus function will return the status on the specified MUTEX variable.

 

 

Input:

mx : MUTEX

The mutex to query the status on.

 

Returns: INT

0

Mutex is unlocked.

1

Mutex is not initialized.

2

Mutex is locked.

 

Declaration:

FUNCTION mxStatus : INT;
VAR_INPUT
  mx : MUTEX;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
THREAD_BLOCK Thread;
VAR_INPUT
  mx : MUTEX;
  ...
END_VAR;
  ...
  // Do until mutex is destroyed
  WHILE mxStatus(mx:=mx) <> 1 DO
     ...
  END_WHILE;
END_THREAD_BLOCK;
 
PROGRAM MutexTest;
VAR
  mx : MUTEX;
  th : ARRAY[1..3] OF Thread;
  i : INT;
  ...
END_VAR;
  // Initialize Mutex
  mx := mxInit();
  IF mxStatus(mx:=mx) = 1 THEN DebugMsg(message:="mxCnt failed to init!"); END_IF;
 
  // Initialize Threads
  FOR i := 1 TO 3 DO th[i](mx:=mx,...); END_FOR;
 
  ...
 
BEGIN
  ...
  // Only when mutex exists
  IF mxStatus(mx:=mx) <> 1 THEN
     ...
  END_IF;
  ...
  // Stop threads and destroy mutex
  IF ... THEN
    // Try to destroy until success
    WHILE mxDestroy(mx:=mx) = 2 DO END_WHILE;   // Ignore already destroyed mutex
  END_IF;
  ...
END;
 
END_PROGRAM;