      SUBROUTINE PLW.ILOCK(CMD,A1,A2,A3,RES,R2)
*PIC-LAN
*
*ALL
*PC
*N
*
*
*
*
******************************************************************************
******************************************************************************
***                                                                        ***
*** (C) Copyright 1990-2005 Doug Dumitru, All Rights Reserved.             ***
***                                                                        ***
*** This program is licensed under the terms of the GNU General Public     ***
*** License, version 2.0 with attached notices.                            ***
***                                                                        ***
*** The full text can be found in the LICENSE.TXT file in the              ***
*** PLIP.BP database file (the /usr/qmweb/PLIP.BP/PLIP.BP directory).      ***
***                                                                        ***
******************************************************************************
******************************************************************************
*
      INCLUDE SYS.TYPE.INCLUDE
*
      P.NO = FIELD(OCONV('','U50BB'),' ',1)
      RES.ID = 'ILOCK*' : P.NO
*
      OPEN 'WWW.CTRL,STATES' TO STATE.FD ELSE CALL PLXX.STOP(201,'WWW.CTRL,STATES')
*
      RES = ''
*
      PL_READU ILOCK.Q FROM STATE.FD , 'ILOCK*Q' ELSE
         ILOCK.Q = ''
      END
      BEGIN CASE
         CASE CMD = 'LOCK'
            ILOCK.Q<-1> =  'LOCK' : VM : P.NO : VM : A1 : SVM : A2 : VM : A3
         CASE CMD = 'UNLOCK'
            ILOCK.Q<-1> =  'UNLOCK' : VM : P.NO : VM : A1
         CASE CMD = 'CHECK'
            ILOCK.Q<-1> =  'CHECK' : VM : P.NO : VM : A1 : VM : A2
         CASE YES
            RES = 'ERROR'
            R2 = 'Invalid command'
      END CASE
*
      WRITE ILOCK.Q ON STATE.FD , 'ILOCK*Q'
*
      IF RES <> '' THEN RETURN
*
      TM0 = PL_NOW()
*
      LOOP
         READ D FROM STATE.FD , RES.ID THEN
            RES = D<1>
            R2 = D<2>
            DELETE STATE.FD , RES.ID
            RETURN
         END
*
         IF PL_NOW() - TM0 > 30 THEN
            RES = 'ERROR'
            R2 = 'Supervisor process timeout'
            RETURN
         END
         IF PL_NOW() < TM0 THEN
            TM0 = PL_NOW()
         END
      WHILE 1 DO
         SLEEP 0
      REPEAT
   END
