home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / reclock.prg < prev    next >
Text File  |  1993-10-14  |  2KB  |  82 lines

  1. /*
  2.  * File......: RECLOCK.PRG
  3.  * Author....: Martin Colloby
  4.  * BBS.......: The Dark Knight Returns
  5.  * Net/Node..: 050/069
  6.  * User Name.: Martin Colloby
  7.  * Date......: 18/4/93
  8.  * Revision..: 1.0
  9.  *
  10.  * This is an original work by Martin Colloby and is placed in the public
  11.  * domain.
  12.  *
  13.  * Modification history:
  14.  * ---------------------
  15.  *
  16.  * $Log$
  17.  *
  18.  */
  19.  
  20.  
  21. /*  $DOC$
  22.  *  $FUNCNAME$
  23.  *      GT_RECLOCK()
  24.  *  $CATEGORY$
  25.  *      General
  26.  *  $ONELINER$
  27.  *      Lock a record with optional retries
  28.  *  $SYNTAX$
  29.  *      GT_RecLock( nSeconds )
  30.  *  $ARGUMENTS$
  31.  *      nSeconds - Number of retries
  32.  *  $RETURNS$
  33.  *      .T. if record locked
  34.  *  $DESCRIPTION$
  35.  *      Attempts to lock the current record in the current workarea.
  36.  *      If unsuccessful, will pause for 1 second and retry.  After nSeconds
  37.  *      retries it will abort.  If nSeconds is 0, will retry indefinatley.
  38.  *  $EXAMPLES$
  39.  *
  40.  *  $SEEALSO$
  41.  *
  42.  *  $INCLUDE$
  43.  *
  44.  *  $END$
  45.  */
  46. *
  47. FUNCTION GT_RecLock( nSeconds )
  48.  
  49. /*****************************************************************************
  50.  Purpose - Attempt to RLOCK() with optional retry
  51.  Returns - .T. if successful
  52.  Author  - Martin Colloby
  53.  Created - 20/05/92
  54. ******************************************************************************
  55.  Parameters - nSeconds - Number of attempts
  56.  Privates   - None
  57.  Locals     - lForever - If .T., loop forever
  58.  Externals  - None
  59. *****************************************************************************/
  60.  
  61. LOCAL lForever := (nSeconds == 0)
  62.  
  63. IF RLOCK()
  64.     * Locked
  65.     RETURN (.T.)
  66. ENDIF
  67.  
  68. DO WHILE (lForever .OR. nSeconds > 0)
  69.     IF RLOCK()
  70.         * Locked
  71.         RETURN (.T.)
  72.     ENDIF
  73.  
  74.     * Wait 1/2 second
  75.     INKEY(.5)
  76.     nSeconds := nSeconds - .5
  77. ENDDO
  78.  
  79. * Not locked
  80. RETURN (.F.)
  81. *
  82.