2009-08-18 01:29 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/contrib/xhb/xhbmt.prg
* renamed: xhb_StartThread() => StartThread(),
xhb_mutexSubscribe() => Subscribe(),
xhb_mutexSubscribeNow() => SubscribeNow()
! fixed timeout parameter used in Subscribe[Now]()
Harbour uses seconds and xHarbour milliseconds
+ added xHarbour compatible MT functions:
hb_MultiThread(), GetCurrentThread(), GetThreadId( pThID ),
ThreadGetCurrentInternal(), IsSameThread( pThID1, pThID2 ),
IsValidThread( pThID ), JoinThread( pThID ), KillThread( pThID ),
StopThread( pThID ), KillAllThreads(), WaitForThreads(),
ThreadSleep( nTimeOut ), DestroyMutex( mtx ),
hb_MutexTryLock( mtx ), hb_MutexTimeOutLock( mtx, nTimeOut ),
Notify( mtx, xVal ), NotifyAll( mtx, xVal ),
ThreadGetCurrent(), GetSystemThreadId( pThID )
* harbour/contrib/xhb/xhb.ch
* removed not longer necessary translation rules
* harbour/contrib/xhb/hbcompat.ch
+ added missing translation rules for MT functions for both Harbour
and xHarbour sections.
Please synchronize this file with xHarbour.
It's enough to copy it to xHarbour CVS - it should also fix some
problems reported by xHarbour users on comp.lang.xharbour
This commit is contained in:
@@ -17,6 +17,33 @@
|
||||
past entries belonging to author(s): Viktor Szakats.
|
||||
*/
|
||||
|
||||
2009-08-18 01:29 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
|
||||
* harbour/contrib/xhb/xhbmt.prg
|
||||
* renamed: xhb_StartThread() => StartThread(),
|
||||
xhb_mutexSubscribe() => Subscribe(),
|
||||
xhb_mutexSubscribeNow() => SubscribeNow()
|
||||
! fixed timeout parameter used in Subscribe[Now]()
|
||||
Harbour uses seconds and xHarbour milliseconds
|
||||
+ added xHarbour compatible MT functions:
|
||||
hb_MultiThread(), GetCurrentThread(), GetThreadId( pThID ),
|
||||
ThreadGetCurrentInternal(), IsSameThread( pThID1, pThID2 ),
|
||||
IsValidThread( pThID ), JoinThread( pThID ), KillThread( pThID ),
|
||||
StopThread( pThID ), KillAllThreads(), WaitForThreads(),
|
||||
ThreadSleep( nTimeOut ), DestroyMutex( mtx ),
|
||||
hb_MutexTryLock( mtx ), hb_MutexTimeOutLock( mtx, nTimeOut ),
|
||||
Notify( mtx, xVal ), NotifyAll( mtx, xVal ),
|
||||
ThreadGetCurrent(), GetSystemThreadId( pThID )
|
||||
|
||||
* harbour/contrib/xhb/xhb.ch
|
||||
* removed not longer necessary translation rules
|
||||
|
||||
* harbour/contrib/xhb/hbcompat.ch
|
||||
+ added missing translation rules for MT functions for both Harbour
|
||||
and xHarbour sections.
|
||||
Please synchronize this file with xHarbour.
|
||||
It's enough to copy it to xHarbour CVS - it should also fix some
|
||||
problems reported by xHarbour users on comp.lang.xharbour
|
||||
|
||||
2009-08-17 22:47 UTC+0200 Viktor Szakats (harbour.01 syenar.hu)
|
||||
* config/global.mk
|
||||
! Fixed previous commit after actual testing.
|
||||
|
||||
@@ -88,6 +88,7 @@
|
||||
#xtranslate hb_adler32([<x,...>]) => hb_checksum(<x>)
|
||||
#xtranslate hb_setLastKey([<x,...>]) => setLastKey(<x>)
|
||||
#xtranslate hb_CStr([<x,...>]) => CStr(<x>)
|
||||
#xtranslate hb_valToExp([<x,...>]) => ValToPrgExp(<x>)
|
||||
#xtranslate hb_DirExists(<x>) => IsDirectory(<x>)
|
||||
#xtranslate hb_rddInfo([<x,...>]) => rddInfo(<x>)
|
||||
#xtranslate hb_idleSleep([<x,...>]) => SecondsSleep(<x>)
|
||||
@@ -131,9 +132,35 @@
|
||||
#xtranslate hb_gtLock() => HBCONSOLELOCK()
|
||||
#xtranslate hb_gtUnLock() => HBCONSOLEUNLOCK()
|
||||
|
||||
/* MT functions */
|
||||
#xtranslate hb_mtvm() => hb_multiThread()
|
||||
#xtranslate hb_threadSelf() => GetCurrentThread()
|
||||
#xtranslate hb_threadId( [<x,...>] ) => GetThreadId( <x> )
|
||||
#xtranslate hb_threadStart( <x,...> ) => StartThread( [<x>] )
|
||||
#xtranslate hb_threadJoin( <x> ) => JoinThread( <x> )
|
||||
#xtranslate hb_threadQuitRequest( <x> ) => KillThread( <x> )
|
||||
#xtranslate hb_threadWaitForAll() => WaitForThreads()
|
||||
#xtranslate hb_threadTerminateAll() => KillAllThreads()
|
||||
|
||||
#xtranslate hb_mutexNotify(<x,...>) => Notify(<x>)
|
||||
#xtranslate hb_mutexNotifyAll(<x,...>) => NotifyAll(<x>)
|
||||
|
||||
#xtranslate hb_mutexSubscribe(<x,...>) => {|mtx, nTimeOut, xSubscribed| ;;
|
||||
local lSubscribed ;;
|
||||
xSubscribed := Subscribe( mtx, ;
|
||||
iif( hb_isNumeric( nTimeOut ), nTimeOut * 1000, ), ;
|
||||
@lSubscribed ) ;
|
||||
return lSubscribed ; }:eval( <x> )
|
||||
#xtranslate hb_mutexSubscribeNow(<x,...>) => {|mtx, nTimeOut, xSubscribed| ;;
|
||||
local lSubscribed ;;
|
||||
xSubscribed := SubscribeNow( mtx, ;
|
||||
iif( hb_isNumeric( nTimeOut ), nTimeOut * 1000, ), ;
|
||||
@lSubscribed ) ;
|
||||
return lSubscribed ; }:eval( <x> )
|
||||
|
||||
#xtranslate hb_MutexLock( <x>, <n> ) => iif( !hb_isNumeric( <n> ), hb_MutexLock( <x> ) ;
|
||||
iif( <n> <= 0, hb_MutexTryLock( <x> ), ;
|
||||
hb_MutexTimeOutLock( <x>, <n> ) ) )
|
||||
|
||||
/* Hash item functions */
|
||||
#xtranslate hb_HASH([<x,...>]) => HASH(<x>)
|
||||
@@ -253,7 +280,8 @@
|
||||
#xtranslate hb_checksum([<x,...>]) => hb_adler32(<x>)
|
||||
#xtranslate setLastKey([<x,...>]) => hb_setLastKey(<x>)
|
||||
#xtranslate CStr([<x,...>]) => hb_CStr(<x>)
|
||||
#xtranslate IsDirectory(<x>) => hb_DirExists(<x>)
|
||||
#xtranslate ValToPrgExp([<x,...>]) => hb_valToExp(<x>)
|
||||
#xtranslate IsDirectory(<x>) => hb_dirExists(<x>)
|
||||
#xtranslate SecondsSleep([<x,...>]) => hb_idleSleep(<x>)
|
||||
#xtranslate NetName(<n>) => iif( hb_isNumeric( <n> ) .AND. <n> == 1, hb_UserName(), NetName() )
|
||||
#xtranslate FileSize(<x>) => hb_FSize(<x>)
|
||||
@@ -314,14 +342,31 @@
|
||||
#xtranslate WaitForThreads() => hb_threadWaitForAll()
|
||||
|
||||
#xtranslate ThreadSleep( <x> ) => hb_idleSleep( <x> / 1000 )
|
||||
#xtranslate SecondsSleep( <x> ) => hb_idleSleep( <x> )
|
||||
|
||||
#xtranslate DestroyMutex( <x> ) =>
|
||||
#xtranslate hb_MutexTryLock( <x> ) => hb_MutexLock( <x>, 0 )
|
||||
#xtranslate hb_MutexTimeOutLock( <x> ) => hb_MutexLock( <x>, 0 )
|
||||
#xtranslate hb_MutexTimeOutLock( <x>, <n> ) => hb_MutexLock( <x>, <n> / 1000 )
|
||||
#xtranslate hb_MutexTryLock( <x> ) => hb_mutexLock( <x>, 0 )
|
||||
#xtranslate hb_MutexTimeOutLock( <x> ) => hb_mutexLock( <x>, 0 )
|
||||
#xtranslate hb_MutexTimeOutLock( <x>, <n> ) => hb_mutexLock( <x>, IIF( hb_isNumeric( <n> ), <n> / 1000, 0 ) )
|
||||
|
||||
#xtranslate Notify( <x,...> ) => hb_mutexNotify( <x> )
|
||||
#xtranslate NotifyAll( <x,...> ) => hb_mutexNotifyAll( <x> )
|
||||
#xtranslate Subscribe( <x,...> ) => {|mtx, nTimeOut, lSubscribed| ;;
|
||||
local xSubscribed ;;
|
||||
lSubscribed := hb_mutexSubscribe( mtx, ;
|
||||
iif( hb_isNumeric( nTimeOut ), nTimeOut / 1000, ), ;
|
||||
@xSubscribed ) ;
|
||||
return xSubscribed ; }:eval( <x> )
|
||||
#xtranslate SubscribeNow( <x,...> ) => {|mtx, nTimeOut, lSubscribed| ;;
|
||||
local xSubscribed ;;
|
||||
lSubscribed := hb_mutexSubscribeNow( mtx, ;
|
||||
iif( hb_isNumeric( nTimeOut ), nTimeOut / 1000, ), ;
|
||||
@xSubscribed ) ;
|
||||
return xSubscribed ; }:eval( <x> )
|
||||
|
||||
#xtranslate StartThread( [<x>] ) => hb_threadStart( <x> )
|
||||
#xtranslate StartThread( <x>, <y> [, <z,...>] ) => iif( valtype( <x> ) == "O" .and. hb_isString( <y> ), ;
|
||||
hb_threadStart( {|...| (<x>):&(<y>)( ... ) } [, <z>] ), ;
|
||||
hb_threadStart( <x>, <y> [, <z>] ) )
|
||||
|
||||
/* not possible to well replicate xHarbour behavior because its buggy
|
||||
these function results are different on different platform, chosen
|
||||
@@ -331,10 +376,10 @@
|
||||
|
||||
/* do not need translation */
|
||||
/* hb_MutexCreate() => hb_mutexCreate() */
|
||||
/* hb_mutexUnlock( <x> ) => hb_mutexUnlock( <x> ) */
|
||||
/* hb_MutexUnlock( <x> ) => hb_mutexUnlock( <x> ) */
|
||||
|
||||
/* do not need translation only when xHarbour code is compiled by Harbour */
|
||||
/* hb_MutexLock( <x> ) => hb_MutexLock( <x> ) */
|
||||
/* hb_MutexLock( <x> ) => hb_mutexLock( <x> ) */
|
||||
|
||||
/* functions I do not want to document as public .prg API in Harbour */
|
||||
/* ThreadInspect() */
|
||||
|
||||
@@ -64,9 +64,6 @@
|
||||
#xtranslate __Keyboard([<x,...>]) => xhb__Keyboard(<x>)
|
||||
#xtranslate __CopyFile([<x,...>]) => xhb_CopyFile(<x>)
|
||||
|
||||
#xtranslate Subscribe( <x,...> ) => xhb_mutexSubscribe( <x> )
|
||||
#xtranslate SubscribeNow( <x,...> ) => xhb_mutexSubscribeNow( <x> )
|
||||
#xtranslate StartThread( <x,...> ) => xhb_StartThread( <x> )
|
||||
#endif
|
||||
|
||||
#endif /* __HARBOUR__ */
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
|
||||
/* real functions used as wrappers in above translations */
|
||||
|
||||
function xhb_StartThread( p1, p2, ... )
|
||||
function StartThread( p1, p2, ... )
|
||||
if PCount() < 2
|
||||
return hb_threadStart( p1 )
|
||||
elseif valtype( p1 ) == "O" .and. ISCHARACTER( p2 )
|
||||
@@ -62,12 +62,107 @@ function xhb_StartThread( p1, p2, ... )
|
||||
endif
|
||||
return hb_threadStart( p1, p2, ... )
|
||||
|
||||
function xhb_mutexSubscribe( mtx, nTimeOut, lSubscribed )
|
||||
|
||||
function Subscribe( mtx, nTimeOut, lSubscribed )
|
||||
local xSubscribed
|
||||
lSubscribed := hb_mutexSubscribe( mtx, nTimeOut, @xSubscribed )
|
||||
lSubscribed := hb_mutexSubscribe( mtx, ;
|
||||
iif( ISNUMBER( nTimeOut ), nTimeOut / 1000, ), ;
|
||||
@xSubscribed )
|
||||
return xSubscribed
|
||||
|
||||
function xhb_mutexSubscribeNow( mtx, nTimeOut, lSubscribed )
|
||||
|
||||
function SubscribeNow( mtx, nTimeOut, lSubscribed )
|
||||
local xSubscribed
|
||||
lSubscribed := hb_mutexSubscribeNow( mtx, nTimeOut, @xSubscribed )
|
||||
lSubscribed := hb_mutexSubscribeNow( mtx, ;
|
||||
iif( ISNUMBER( nTimeOut ), nTimeOut / 1000, ), ;
|
||||
@xSubscribed )
|
||||
return xSubscribed
|
||||
|
||||
|
||||
function hb_MultiThread()
|
||||
return hb_mtvm()
|
||||
|
||||
|
||||
function GetCurrentThread()
|
||||
return hb_threadSelf()
|
||||
|
||||
|
||||
function GetThreadId( pThID )
|
||||
return hb_threadId( pThID )
|
||||
|
||||
|
||||
function ThreadGetCurrentInternal()
|
||||
return hb_threadId()
|
||||
|
||||
|
||||
function IsSameThread( pThID1, pThID2 )
|
||||
return hb_threadId( pThID1 ) == iif( pcount() < 2, hb_threadId(), ;
|
||||
hb_threadId( pThID2 ) )
|
||||
|
||||
|
||||
function IsValidThread( pThID )
|
||||
local lValid
|
||||
|
||||
begin sequence with {|| break() }
|
||||
lValid := hb_threadId( pThID ) != 0
|
||||
recover
|
||||
lValid := .F.
|
||||
end sequence
|
||||
|
||||
return lValid
|
||||
|
||||
|
||||
function JoinThread( pThID )
|
||||
return hb_threadJoin( pThID )
|
||||
|
||||
|
||||
function KillThread( pThID )
|
||||
hb_threadQuitRequest( pThID )
|
||||
return NIL
|
||||
|
||||
|
||||
function StopThread( pThID )
|
||||
hb_threadQuitRequest( pThID )
|
||||
hb_threadJoin( pThID )
|
||||
return NIL
|
||||
|
||||
|
||||
function KillAllThreads()
|
||||
return hb_threadTerminateAll()
|
||||
|
||||
|
||||
function WaitForThreads()
|
||||
return hb_threadWaitForAll()
|
||||
|
||||
|
||||
function ThreadSleep( nTimeOut )
|
||||
return hb_idleSleep( nTimeOut / 1000 )
|
||||
|
||||
|
||||
function DestroyMutex( mtx )
|
||||
HB_SYMBOL_UNUSED( mtx )
|
||||
return NIL
|
||||
|
||||
|
||||
function hb_MutexTryLock( mtx )
|
||||
return hb_mutexLock( mtx, 0 )
|
||||
|
||||
|
||||
function hb_MutexTimeOutLock( mtx, nTimeOut )
|
||||
return hb_mutexLock( mtx, IIF( hb_isNumeric( nTimeOut ), nTimeOut / 1000, 0 ) )
|
||||
|
||||
|
||||
function Notify( mtx, xVal )
|
||||
return hb_mutexNotify( mtx, xVal )
|
||||
|
||||
|
||||
function NotifyAll( mtx, xVal )
|
||||
return hb_mutexNotifyAll( mtx, xVal )
|
||||
|
||||
|
||||
function ThreadGetCurrent()
|
||||
return hb_threadId()
|
||||
|
||||
|
||||
function GetSystemThreadId( pThID )
|
||||
return iif( PCount() < 1, hb_threadId(), hb_threadId( pThID ) )
|
||||
|
||||
Reference in New Issue
Block a user