Files
harbour-core/contrib/hbnf/tests/nwsem.prg
Przemysław Czerpak 96ca3fe470 2014-01-21 20:41 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)
* Makefile
  * config/*
  * contrib/*
  * doc/*
  * extras/*
  * include/*
  * lib/*
  * package/*
  * src/*
  * tests/*
  * utils/*
    * removed empty lines left after removed '$' + 'Id' + '$' identifiers
2014-01-21 20:41:05 +01:00

48 lines
1.0 KiB
Plaintext

#require "hbnf"
#define INITIAL_SEMAPHORE_VALUE 2
#define WAIT_SECONDS 1
PROCEDURE Main()
LOCAL nInitVal, nRc, nHandle, nValue, nOpenCnt
CLS
nInitVal := INITIAL_SEMAPHORE_VALUE
ft_NWSemOpen( "TEST", nInitVal, @nHandle, @nOpenCnt )
? "Waiting ten seconds..."
nRc := ft_NWSemWait( nHandle, 180 )
? "Final nRc value = " + Str( nRc )
Inkey( 0 )
IF nRc == 254
? "Couldn't get the semaphore. Try again."
QUIT
ENDIF
CLS
@ 24, 0 SAY "Any key to exit"
@ 0, 0 SAY "Handle: " + Str( nHandle )
ft_NWSemEx( nHandle, @nValue, @nOpenCnt )
WHILE .T.
@ 23, 0 SAY "Semaphore test -> Open at [" + ;
hb_ntos( nOpenCnt ) + ;
"] stations, value is [" + ;
hb_ntos( nValue ) + "]"
IF Inkey( WAIT_SECONDS ) != 0
EXIT
ENDIF
Tone( nHandle, .5 )
ft_NWSemEx( nHandle, @nValue, @nOpenCnt )
ENDDO
? "Signal returns: " + Str( ft_NWSemSig( nHandle ) )
? "Close returns: " + Str( ft_NWSemClose( nHandle ) )
RETURN