On Mon, 16 Mar 2009, Szak�ts Viktor wrote:
Hi,
> I'm trying to map all xhb MT functions to Harbour equivalents
> to aid porting some MT dependent parts. Here's my rough
> results. Please extend, correct and if we reach a usable state,
> I'd like to add it to hbcompat.ch.
It may not be such simple. There are some serious differences between
Harbour and xHarbour in MT mode so even if we create final mapping
then it does not mean that the applications will work.
Anyhow we can alwas try ;-)
Here is the list of Harbour MT functions:
hb_threadStart( [<nThreadAttrs> ,] <@sStart()> | <bStart> | <cStart> [,
<params,...> ] ) -> <pThID>
hb_threadSelf() -> <pThID> | NIL
hb_threadId( [ <pThID> ] ) -> <nThNo>
hb_threadJoin( <pThID> [, @<xRetCode> ] ) -> <lOK>
hb_threadDetach( <pThID> ) -> <lOK>
* hb_threadQuitRequest( <pThID> ) -> <lOK> /* can be ignored !!! */
hb_threadTerminateAll() -> NIL
hb_threadWaitForAll() -> NIL
hb_threadWait( <pThID> | <apThID>, [ <nTimeOut> ] [, <lAll> ] ) => <nThInd>
| <nThCount> | 0
hb_threadOnce( @<onceControl> [, <bAction> ] ) -> <lFirstCall>
hb_mutexCreate() -> <pMtx>
hb_mutexLock( <pMtx> [, <nTimeOut> ] ) -> <lLocked>
hb_mutexUnlock( <pMtx> ) -> <lOK>
hb_mutexNotify( <pMtx> [, <xVal>] ) -> NIL
hb_mutexNotifyAll( <pMtx> [, <xVal>] ) -> NIL
hb_mutexSubscribe( <pMtx>, [ <nTimeOut> ] [, @<xSubscribed> ] ) ->
<lSubscribed>
hb_mutexSubscribeNow( <pMtx>, [ <nTimeOut> ] [, @<xSubscribed> ] ) ->
<lSubscribed>
* - this function call can be ignored by the destination thread in some
cases. HVM does not guaranties that the QUIT signal will be always
delivered.
Now translations from xHarbour code to Harbour:
#xtranslate hb_MultiThread() => hb_mtvm()
#xtranslate GetCurrentThread() => hb_threadSelf()
#xtranslate GetThreadId( [<x,...>] ) => hb_threadId( <x> )
#xtranslate ThreadGetCurrentInternal() => hb_threadId()
#xtranslate IsSameThread( <x> [,<y>] ) => ( hb_threadId( <x> ) ==
hb_threadId( <y> ) )
#xtranslate IsValidThread( <x> ) => ( hb_threadId( <x> ) != 0 )
#xtranslate JoinThread( <x> ) => hb_threadJoin( <x> )
#xtranslate KillThread( <x> ) => hb_threadQuitRequest( <x> )
#xtranslate StopThread( <x> ) => hb_threadQuitRequest( <x>
);hb_threadJoin( <x> )
#xtranslate KillAllThreads() => hb_threadTerminateAll()
#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 Notify( <x,...> ) => hb_mutexNotify( <x> )
#xtranslate NotifyAll( <x,...> ) => hb_mutexNotifyAll( <x> )
#xtranslate Subscribe( <x,...> ) => xhb_mutexSubscribe( <x> )
#xtranslate SubscribeNow( <x,...> ) => xhb_mutexSubscribeNow( <x> )
#xtranslate StartThread( <x,...> ) => xhb_StartThread( <x> )
/* do not need translation */
// hb_MutexCreate() => hb_mutexCreate()
// hb_mutexUnlock( <x> ) => hb_mutexUnlock( <x> )
/* do not need translation only when xHarbour code is compiled by Harbour */
// hb_MutexLock( <x> ) => hb_MutexLock( <x> )
/* not possible to well replicate xHarbour behavior because its buggy
these function results are different on different platform, chosen
translation which returns compatible types (numeric) */
#xtranslate ThreadGetCurrent() => hb_threadId()
#xtranslate GetSystemThreadId( [<x,...>] ) => hb_threadId( <x> )
/* functions I do not want to document as public .prg API in Harbour */
// ThreadInspect()
// ThreadInspectEnd()
// ThreadIsInspect()
/* functions which are not necessary in Harbour */
// hb_ThreadGetTryErrorArray()
// ThreadIdleFence()
/* function which I can add but it's not very usable in real life */
// hb_ThreadCountStacks()
/* real functions used as wrappers in above translations */
function xhb_StartThread( p1, p2, ... )
if PCount() < 2
return hb_threadStart( p1 )
elseif valtype( p1 ) == "O" .and. valtype( p2 ) == "C"
return hb_threadStart( {|...| p1:&p2( ... ) }, ... )
endif
return hb_threadStart( p1, p2, ... )
function xhb_mutexSubscribe( mtx, nTimeOut, lSubscribed )
local xSubscribed
lSubscribed := hb_mutexSubscribe( mtx, nTimeOut, @xSubscribed )
return xSubscribed
function xhb_mutexSubscribeNow( mtx, nTimeOut, lSubscribed )
local xSubscribed
lSubscribed := hb_mutexSubscribeNow( mtx, nTimeOut, @xSubscribed )
return xSubscribed
best regards,
Przemek
_______________________________________________
Harbour mailing list
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour