Files
harbour-core/tests/flock.prg
Viktor Szakats 0caff16650 2017-09-13 12:38 UTC Viktor Szakats (vszakats users.noreply.github.com)
- doc/en/hashes.txt
  - doc/en/rdddb.txt
  * .gitattributes
  * contrib/3rd/sqlite3/sqlite3.hbp
  * contrib/hbbz2/3rd/bz2/bz2.hbp
  * contrib/hbexpat/3rd/expat/expat.hbp
  * contrib/hbfimage/hbfimage.hbp
  * contrib/hbhpdf/3rd/libhpdf/libhpdf.hbp
  * contrib/hblzf/3rd/liblzf/lzf.hbp
  * contrib/hbmxml/3rd/minixml/mxml.hbp
  * contrib/hbmzip/3rd/minizip/minizip.hbp
  * contrib/hbodbc/hbodbc.hbp
  * contrib/hbtinymt/3rd/tinymt/tinymt.hbp
  * contrib/hbxdiff/3rd/libxdiff/xdiff.hbp
  * contrib/sddsqlt3/tests/test.prg
  * ChangeLog.txt
  * doc/Makefile
  * doc/oldnews.txt
  * extras/ps32/readme.txt
  * extras/superlib/readme.txt
  * src/3rd/jpeg/Makefile
  * src/3rd/pcre/Makefile
  * src/3rd/png/Makefile
  * src/3rd/tiff/Makefile
  * src/3rd/zlib/Makefile
  + contrib/hbsms/DEPRECATED.txt
  + contrib/hbtpathy/DEPRECATED.txt
  + contrib/xhb/WARNING.txt
  * contrib/3rd/sqlite3/sqlite3.dif -> contrib/3rd/sqlite3/sqlite3.diff
  * contrib/hbbz2/3rd/bz2/bz2.dif -> contrib/hbbz2/3rd/bz2/bz2.diff
  * contrib/hbexpat/3rd/expat/expat.dif -> contrib/hbexpat/3rd/expat/expat.diff
  * contrib/hbhpdf/3rd/libhpdf/libhpdf.dif -> contrib/hbhpdf/3rd/libhpdf/libhpdf.diff
  * contrib/hblzf/3rd/liblzf/liblzf.dif -> contrib/hblzf/3rd/liblzf/liblzf.diff
  * contrib/hbmxml/3rd/minixml/minixml.dif -> contrib/hbmxml/3rd/minixml/minixml.diff
  * contrib/hbmzip/3rd/minizip/minizip.dif -> contrib/hbmzip/3rd/minizip/minizip.diff
  * contrib/hbtinymt/3rd/tinymt/tinymt.dif -> contrib/hbtinymt/3rd/tinymt/tinymt.diff
  * contrib/hbxdiff/3rd/libxdiff/libxdiff.dif -> contrib/hbxdiff/3rd/libxdiff/xdiff.diff
  * contrib/sddsqlt3/tests/test.sq3 -> contrib/sddsqlt3/tests/test.sqlite3
  * extras/dbu/dbu52.dif -> extras/dbu/dbu52.patch
  * extras/dbu/dbu53.dif -> extras/dbu/dbu53.patch
  * extras/ps32/ps32.dif -> extras/ps32/ps32.patch
  * extras/rl/rl.dif -> extras/rl/rl.patch
  * extras/superlib/superlib.dif -> extras/superlib/superlib.patch
  * extras/template/readme.txt -> extras/template/README.md
  * src/3rd/hbdossrl/README -> src/3rd/hbdossrl/README.txt
  * src/3rd/jpeg/jpeg.dif -> src/3rd/jpeg/jpeg.diff
  * src/3rd/pcre/pcre.dif -> src/3rd/pcre/pcre.diff
  * src/3rd/png/png.dif -> src/3rd/png/png.diff
  * src/3rd/tiff/tiff.dif -> src/3rd/tiff/tiff.diff
  * src/3rd/zlib/zlib.dif -> src/3rd/zlib/zlib.diff
  * tests/hbpptest/_pp_test.prg -> tests/hbpp/_pp_test.prg
  * tests/hbpptest/compare.hb -> tests/hbpp/compare.hb
  * tests/hbpptest/hbpptest.hbp -> tests/hbpp/hbpptest.hbp
  * tests/hbpptest/hbpptest.prg -> tests/hbpp/hbpptest.prg
  * tests/tflock.prg -> tests/flock.prg
  * contrib/hbfimage/fi_wrp.c -> contrib/hbfimage/core.c
  * contrib/hbodbc/browodbc.prg -> contrib/hbodbc/browse.prg
  * doc/cmdline.txt -> doc/cmdline.md
  * extras/dbu/readme.txt -> extras/dbu/README.md
  * extras/rl/readme.txt -> extras/rl/README.md
    * some file renames synced with 3.4 fork, plus the content of
      some of them. Some new text files added as well.
      Note, 3rd party code rediffing won't work anymore on 8.3
      filesystems.
2017-09-13 12:39:48 +00:00

136 lines
3.5 KiB
Plaintext

/* test file locking */
#include "fileio.ch"
#include "inkey.ch"
#define FLX_EXCLUSIVE 0x0000 /* Exclusive lock */
#define FLX_SHARED 0x0100 /* Shared lock */
#define FLX_NO_WAIT 0x0000 /* Immediate return */
#define FLX_WAIT 0x0200 /* Wait for lock until success */
#define hb_keyCode( x ) Asc( x )
STATIC s_lLocked
STATIC s_lExclusive
STATIC s_lBlocking
PROCEDURE Main()
LOCAL hLockFile
LOCAL lSuccess
LOCAL nExclusivity
LOCAL nBlocking
LOCAL nKeyHit
LOCAL nLockType
CLS
IF ! hb_FileExists( "emphasis.6lo" )
hb_MemoWrit( "emphasis.6lo", "" )
ENDIF
? "Opening lock file"
IF ( hLockFile := FOpen( "emphasis.6lo", FO_READWRITE ) ) == F_ERROR
? "ERROR: Cannot open Lock File"
RETURN
ENDIF
? "Lock file opened - handle is", hb_ntos( hLockFile )
?
s_lLocked := .F.
s_lExclusive := .T.
s_lBlocking := .F.
nExclusivity := FLX_EXCLUSIVE
nBlocking := FLX_NO_WAIT
ShowStatus()
? "[+] to get a lock, [-] to release it, [Esc] to exit, [E] for exclusive, [S] for shared, [B] for blocking, [N] for non-blocking"
DO WHILE .T.
nKeyHit := Inkey( 0 )
SWITCH nKeyHit
CASE hb_keyCode( "+" )
IF s_lLocked
? "Already locked"
ELSE
nLockType := nExclusivity + nBlocking
? "Requesting Lock"
lSuccess := hb_FLock( hLockFile, 0, 1, nLockType )
IF lSuccess
? "Lock has been obtained"
s_lLocked := .T.
ELSE
? "Lock Request Failed - Error Code:", FError()
ENDIF
ENDIF
EXIT
CASE hb_keyCode( "-" )
IF ! s_lLocked
? "Lock not currently held"
ELSE
lSuccess := hb_FUnlock( hLockFile, 0, 1 )
IF lSuccess
? "Lock has been released"
s_lLocked := .F.
ELSE
? "Unlock Request Failed - Error Code:", FError()
ENDIF
ENDIF
EXIT
CASE hb_keyCode( "E" )
CASE hb_keyCode( "e" )
IF s_lLocked
? "Release Lock before changing lock type"
ELSE
s_lExclusive := .T.
nExclusivity := FLX_EXCLUSIVE
ShowStatus()
ENDIF
EXIT
CASE hb_keyCode( "S" )
CASE hb_keyCode( "s" )
IF s_lLocked
? "Release Lock before changing lock type"
ELSE
s_lExclusive := .F.
nExclusivity := FLX_SHARED
ShowStatus()
ENDIF
EXIT
CASE hb_keyCode( "B" )
CASE hb_keyCode( "b" )
IF s_lLocked
? "Release Lock before changing function mode"
ELSE
s_lBlocking := .T.
nExclusivity := FLX_WAIT
ShowStatus()
ENDIF
EXIT
CASE hb_keyCode( "N" )
CASE hb_keyCode( "n" )
IF s_lLocked
? "Release Lock before changing function mode"
ELSE
s_lBlocking := .F.
nExclusivity := FLX_NO_WAIT
ShowStatus()
ENDIF
EXIT
CASE K_ESC
?
FClose( hLockFile )
? "Exiting"
RETURN
OTHERWISE
? "Key not supported", nKeyHit
ENDSWITCH
ENDDO
RETURN
PROCEDURE ShowStatus()
? "Lock: " + iif( s_lLocked, "Held", "Released" ) +;
" Type: " + iif( s_lExclusive, "Exclusive", "Shared" ) +;
" Request is: " + iif( s_lBlocking, "Blocking", "Non-Blocking" )
RETURN