mxDestroy (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

ALL

Firmware version:

1.00 / 1.00.00


The mxDestory() function will destroy a MUTEX variable.

After the call to mxDestroy(), the mutex variable cannot be used in further operations.

 

Input:

mx : MUTEX

The mutex to destroy.                

 

Returns: INT

0

Mutex is destroyed.

1

Mutex is not initialized.

2

Mutex is busy.

 

Declaration:

FUNCTION mxDestroy : 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 exsists
  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 allready destroyed mutex
  END_IF;
  ...
END;
 
END_PROGRAM;