diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 241c035181..58aea908e7 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -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. diff --git a/harbour/contrib/xhb/hbcompat.ch b/harbour/contrib/xhb/hbcompat.ch index 36c0676c0a..10e33b4cf0 100644 --- a/harbour/contrib/xhb/hbcompat.ch +++ b/harbour/contrib/xhb/hbcompat.ch @@ -88,6 +88,7 @@ #xtranslate hb_adler32([]) => hb_checksum() #xtranslate hb_setLastKey([]) => setLastKey() #xtranslate hb_CStr([]) => CStr() + #xtranslate hb_valToExp([]) => ValToPrgExp() #xtranslate hb_DirExists() => IsDirectory() #xtranslate hb_rddInfo([]) => rddInfo() #xtranslate hb_idleSleep([]) => SecondsSleep() @@ -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( [] ) => GetThreadId( ) + #xtranslate hb_threadStart( ) => StartThread( [] ) + #xtranslate hb_threadJoin( ) => JoinThread( ) + #xtranslate hb_threadQuitRequest( ) => KillThread( ) #xtranslate hb_threadWaitForAll() => WaitForThreads() + #xtranslate hb_threadTerminateAll() => KillAllThreads() + #xtranslate hb_mutexNotify() => Notify() + #xtranslate hb_mutexNotifyAll() => NotifyAll() + + #xtranslate hb_mutexSubscribe() => {|mtx, nTimeOut, xSubscribed| ;; + local lSubscribed ;; + xSubscribed := Subscribe( mtx, ; + iif( hb_isNumeric( nTimeOut ), nTimeOut * 1000, ), ; + @lSubscribed ) ; + return lSubscribed ; }:eval( ) + #xtranslate hb_mutexSubscribeNow() => {|mtx, nTimeOut, xSubscribed| ;; + local lSubscribed ;; + xSubscribed := SubscribeNow( mtx, ; + iif( hb_isNumeric( nTimeOut ), nTimeOut * 1000, ), ; + @lSubscribed ) ; + return lSubscribed ; }:eval( ) + + #xtranslate hb_MutexLock( , ) => iif( !hb_isNumeric( ), hb_MutexLock( ) ; + iif( <= 0, hb_MutexTryLock( ), ; + hb_MutexTimeOutLock( , ) ) ) /* Hash item functions */ #xtranslate hb_HASH([]) => HASH() @@ -253,7 +280,8 @@ #xtranslate hb_checksum([]) => hb_adler32() #xtranslate setLastKey([]) => hb_setLastKey() #xtranslate CStr([]) => hb_CStr() - #xtranslate IsDirectory() => hb_DirExists() + #xtranslate ValToPrgExp([]) => hb_valToExp() + #xtranslate IsDirectory() => hb_dirExists() #xtranslate SecondsSleep([]) => hb_idleSleep() #xtranslate NetName() => iif( hb_isNumeric( ) .AND. == 1, hb_UserName(), NetName() ) #xtranslate FileSize() => hb_FSize() @@ -314,14 +342,31 @@ #xtranslate WaitForThreads() => hb_threadWaitForAll() #xtranslate ThreadSleep( ) => hb_idleSleep( / 1000 ) - #xtranslate SecondsSleep( ) => hb_idleSleep( ) #xtranslate DestroyMutex( ) => - #xtranslate hb_MutexTryLock( ) => hb_MutexLock( , 0 ) - #xtranslate hb_MutexTimeOutLock( ) => hb_MutexLock( , 0 ) - #xtranslate hb_MutexTimeOutLock( , ) => hb_MutexLock( , / 1000 ) + #xtranslate hb_MutexTryLock( ) => hb_mutexLock( , 0 ) + #xtranslate hb_MutexTimeOutLock( ) => hb_mutexLock( , 0 ) + #xtranslate hb_MutexTimeOutLock( , ) => hb_mutexLock( , IIF( hb_isNumeric( ), / 1000, 0 ) ) + #xtranslate Notify( ) => hb_mutexNotify( ) #xtranslate NotifyAll( ) => hb_mutexNotifyAll( ) + #xtranslate Subscribe( ) => {|mtx, nTimeOut, lSubscribed| ;; + local xSubscribed ;; + lSubscribed := hb_mutexSubscribe( mtx, ; + iif( hb_isNumeric( nTimeOut ), nTimeOut / 1000, ), ; + @xSubscribed ) ; + return xSubscribed ; }:eval( ) + #xtranslate SubscribeNow( ) => {|mtx, nTimeOut, lSubscribed| ;; + local xSubscribed ;; + lSubscribed := hb_mutexSubscribeNow( mtx, ; + iif( hb_isNumeric( nTimeOut ), nTimeOut / 1000, ), ; + @xSubscribed ) ; + return xSubscribed ; }:eval( ) + + #xtranslate StartThread( [] ) => hb_threadStart( ) + #xtranslate StartThread( , [, ] ) => iif( valtype( ) == "O" .and. hb_isString( ), ; + hb_threadStart( {|...| ():&()( ... ) } [, ] ), ; + hb_threadStart( , [, ] ) ) /* 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( ) => hb_mutexUnlock( ) */ + /* hb_MutexUnlock( ) => hb_mutexUnlock( ) */ /* do not need translation only when xHarbour code is compiled by Harbour */ - /* hb_MutexLock( ) => hb_MutexLock( ) */ + /* hb_MutexLock( ) => hb_mutexLock( ) */ /* functions I do not want to document as public .prg API in Harbour */ /* ThreadInspect() */ diff --git a/harbour/contrib/xhb/xhb.ch b/harbour/contrib/xhb/xhb.ch index f0c7df310b..a7c80588f6 100644 --- a/harbour/contrib/xhb/xhb.ch +++ b/harbour/contrib/xhb/xhb.ch @@ -64,9 +64,6 @@ #xtranslate __Keyboard([]) => xhb__Keyboard() #xtranslate __CopyFile([]) => xhb_CopyFile() - #xtranslate Subscribe( ) => xhb_mutexSubscribe( ) - #xtranslate SubscribeNow( ) => xhb_mutexSubscribeNow( ) - #xtranslate StartThread( ) => xhb_StartThread( ) #endif #endif /* __HARBOUR__ */ diff --git a/harbour/contrib/xhb/xhbmt.prg b/harbour/contrib/xhb/xhbmt.prg index 0aa0b63910..3aab4473e6 100644 --- a/harbour/contrib/xhb/xhbmt.prg +++ b/harbour/contrib/xhb/xhbmt.prg @@ -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 ) )