From d4b61aece8e34fe7a69aa77ad16e61d5761cbc27 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Fri, 10 Oct 2008 04:26:42 +0000 Subject: [PATCH] 2008-10-10 06:26 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbvm.h * harbour/source/vm/hvm.c + added hb_vmProcessDynLibSymbols() which works like hb_vmProcessSymbolsEx() but always mark registered modules as dynamic * harbour/source/vm/maindllp.c * redirect hb_vmProcessSymbolsEx() to hb_vmProcessDynLibSymbols() * harbour/source/vm/thread.c * disabled some low level locking code in non MT HVM mode --- harbour/ChangeLog | 13 +++++++ harbour/include/hbvm.h | 1 + harbour/source/vm/hvm.c | 36 ++++++++++++----- harbour/source/vm/maindllp.c | 75 ++++++++++++++++++------------------ harbour/source/vm/thread.c | 53 +++++++++++++++++++++++++ 5 files changed, 131 insertions(+), 47 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 3282be0e20..6fc7af06c2 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,19 @@ 2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2008-10-10 06:26 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/hbvm.h + * harbour/source/vm/hvm.c + + added hb_vmProcessDynLibSymbols() which works like + hb_vmProcessSymbolsEx() but always mark registered modules as + dynamic + + * harbour/source/vm/maindllp.c + * redirect hb_vmProcessSymbolsEx() to hb_vmProcessDynLibSymbols() + + * harbour/source/vm/thread.c + * disabled some low level locking code in non MT HVM mode + 2008-10-10 01:43 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbgtcore.h * harbour/source/rtl/hbgtcore.c diff --git a/harbour/include/hbvm.h b/harbour/include/hbvm.h index 657ee04764..1db69976a0 100644 --- a/harbour/include/hbvm.h +++ b/harbour/include/hbvm.h @@ -71,6 +71,7 @@ extern HB_EXPORT void hb_vmAtExit( HB_INIT_FUNC pFunc, void * cargo ); extern HB_EXPORT void hb_vmExecute( const BYTE * pCode, PHB_SYMB pSymbols ); /* invokes the virtual machine */ extern HB_EXPORT PHB_SYMB hb_vmProcessSymbols( PHB_SYMB pSymbols, USHORT uiSymbols ); /* old module symbols initialization */ extern HB_EXPORT PHB_SYMB hb_vmProcessSymbolsEx( PHB_SYMB pSymbols, USHORT uiSymbols, const char * szModuleName, ULONG ulID, USHORT uiPcodeVer ); /* module symbols initialization with extended information */ +extern HB_EXPORT PHB_SYMB hb_vmProcessDynLibSymbols( PHB_SYMB pSymbols, USHORT uiSymbols, const char * szModuleName, ULONG ulID, USHORT uiPcodeVer ); /* module symbols initialization with extended information */ #ifdef _HB_API_INTERNAL_ typedef struct _HB_SYMBOLS diff --git a/harbour/source/vm/hvm.c b/harbour/source/vm/hvm.c index 37906a85a6..f89a4802fd 100644 --- a/harbour/source/vm/hvm.c +++ b/harbour/source/vm/hvm.c @@ -7304,15 +7304,8 @@ PHB_SYMBOLS hb_vmRegisterSymbols( PHB_SYMB pModuleSymbols, USHORT uiSymbols, return pNewSymbols; } -/* - * module symbols initialization with extended information - */ -HB_EXPORT PHB_SYMB hb_vmProcessSymbolsEx( PHB_SYMB pSymbols, USHORT uiModuleSymbols, - const char * szModuleName, ULONG ulID, - USHORT uiPCodeVer ) +static void hb_vmVerifyPCodeVersion( const char * szModuleName, USHORT uiPCodeVer ) { - HB_TRACE(HB_TR_DEBUG, ("hb_vmProcessSymbolsEx(%p,%hu,%s,%lu,%hu)", pSymbols, uiModuleSymbols, szModuleName, ulID, uiPCodeVer)); - if( uiPCodeVer != 0 ) { if( uiPCodeVer > HB_PCODE_VER || /* the module is compiled with newer compiler version then HVM */ @@ -7327,10 +7320,33 @@ HB_EXPORT PHB_SYMB hb_vmProcessSymbolsEx( PHB_SYMB pSymbols, USHORT uiModuleSymb } } +} + +/* + * module symbols initialization with extended information + */ +HB_EXPORT PHB_SYMB hb_vmProcessSymbolsEx( PHB_SYMB pSymbols, USHORT uiModuleSymbols, + const char * szModuleName, ULONG ulID, + USHORT uiPCodeVer ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_vmProcessSymbolsEx(%p,%hu,%s,%lu,%hu)", pSymbols, uiModuleSymbols, szModuleName, ulID, uiPCodeVer)); + + hb_vmVerifyPCodeVersion( szModuleName, uiPCodeVer ); return hb_vmRegisterSymbols( pSymbols, uiModuleSymbols, szModuleName, ulID, s_fCloneSym, s_fCloneSym )->pModuleSymbols; } +HB_EXPORT PHB_SYMB hb_vmProcessDynLibSymbols( PHB_SYMB pSymbols, USHORT uiModuleSymbols, + const char * szModuleName, ULONG ulID, + USHORT uiPCodeVer ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_vmProcessDynLibSymbols(%p,%hu,%s,%lu,%hu)", pSymbols, uiModuleSymbols, szModuleName, ulID, uiPCodeVer)); + + hb_vmVerifyPCodeVersion( szModuleName, uiPCodeVer ); + return hb_vmRegisterSymbols( pSymbols, uiModuleSymbols, szModuleName, ulID, + TRUE, TRUE )->pModuleSymbols; +} + /* * old module symbols initialization - do not use it. */ @@ -7349,8 +7365,8 @@ HB_EXPORT PHB_SYMB hb_vmProcessDllSymbols( PHB_SYMB pSymbols, USHORT uiModuleSym { HB_TRACE(HB_TR_DEBUG, ("hb_vmProcessDllSymbols(%p,%hu)", pSymbols, uiModuleSymbols)); - return hb_vmRegisterSymbols( pSymbols, uiModuleSymbols, "", 0, - TRUE, s_fCloneSym )->pModuleSymbols; + return hb_vmRegisterSymbols( pSymbols, uiModuleSymbols, "", 0L, + TRUE, TRUE )->pModuleSymbols; } static void hb_vmReleaseLocalSymbols( void ) diff --git a/harbour/source/vm/maindllp.c b/harbour/source/vm/maindllp.c index 103ef3cd79..74e61e22aa 100644 --- a/harbour/source/vm/maindllp.c +++ b/harbour/source/vm/maindllp.c @@ -58,7 +58,6 @@ #define HB_OS_WIN_32_USED #include "hbtypes.h" -#include "hbapierr.h" #define HB_DLL_NAME "harbour.dll" #if defined( __BORLANDC__ ) @@ -92,10 +91,11 @@ static FARPROC hb_getProcAddress( LPCSTR szProcName ) pProcAddr = GetProcAddress( s_hModule, szProcName + 1 ); } + /* TODO: display error message, hb_errInternal() is not accessible here */ + /* if( pProcAddr == NULL ) - { - /* hb_errInternal( 9997, "Cannot find address for function %s", szProcName, NULL ); */ - } + hb_errInternal( 9997, "Cannot find address for function %s", szProcName, NULL ); + */ return pProcAddr; } @@ -121,7 +121,40 @@ HB_EXPORT BOOL WINAPI DllEntryPoint( HINSTANCE hInstance, DWORD fdwReason, PVOID return TRUE; } -/* module symbols initialization */ +/* module symbols initialization with extended information */ +PHB_SYMB hb_vmProcessSymbolsEx( PHB_SYMB pSymbols, USHORT uiSymbols, const char * szModuleName, ULONG ulID, USHORT uiPcodeVer ) +{ + static FARPROC s_pProcessSymbols = NULL; + + if( !s_pProcessSymbols ) + s_pProcessSymbols = hb_getProcAddress( "_hb_vmProcessDynLibSymbols" ); + + if( s_pProcessSymbols ) + return ( ( VM_PROCESS_SYMBOLS_EX ) s_pProcessSymbols ) + ( pSymbols, uiSymbols, szModuleName, ulID, uiPcodeVer ); + /* else + * may we issue an error ? */ + + return pSymbols; +} + +/* execute PCODE function */ +void hb_vmExecute( const BYTE * pCode, PHB_SYMB pSymbols ) +{ + static FARPROC s_pExecute = NULL; + + if( !s_pExecute ) + s_pExecute = hb_getProcAddress( "_hb_vmExecute" ); + + if( s_pExecute ) + ( ( VM_DLL_EXECUTE ) s_pExecute ) ( pCode, pSymbols ); + + /* else + * may we issue an error ? */ +} + + +/* module symbols initialization - old function do not use it */ PHB_SYMB hb_vmProcessSymbols( PHB_SYMB pSymbols, USHORT uiSymbols ) { /* notice hb_vmProcessDllSymbols() must be used, and not @@ -142,38 +175,6 @@ PHB_SYMB hb_vmProcessSymbols( PHB_SYMB pSymbols, USHORT uiSymbols ) return pSymbols; } -/* module symbols initialization with extended information */ -PHB_SYMB hb_vmProcessSymbolsEx( PHB_SYMB pSymbols, USHORT uiSymbols, const char * szModuleName, ULONG ulID, USHORT uiPcodeVer ) -{ - static FARPROC s_pProcessSymbols = NULL; - - if( !s_pProcessSymbols ) - s_pProcessSymbols = hb_getProcAddress( "_hb_vmProcessSymbolsEx" ); - - if( s_pProcessSymbols ) - return ( ( VM_PROCESS_SYMBOLS_EX ) s_pProcessSymbols ) - ( pSymbols, uiSymbols, szModuleName, ulID, uiPcodeVer ); - /* else - * may we issue an error ? */ - - return pSymbols; -} - -void hb_vmExecute( const BYTE * pCode, PHB_SYMB pSymbols ) -{ - static FARPROC s_pExecute = NULL; - - if( !s_pExecute ) - s_pExecute = hb_getProcAddress( "_hb_vmExecute" ); - - if( s_pExecute ) - ( ( VM_DLL_EXECUTE ) s_pExecute ) ( pCode, pSymbols ); - - /* else - * may we issue an error ? */ -} - - /* extend API implementation for pcode DLLs */ char * hb_parc( int iParam, ... ) diff --git a/harbour/source/vm/thread.c b/harbour/source/vm/thread.c index b27322002c..f291764b70 100644 --- a/harbour/source/vm/thread.c +++ b/harbour/source/vm/thread.c @@ -1330,6 +1330,14 @@ BOOL hb_threadMutexUnlock( PHB_ITEM pItem ) if( pMutex ) { +#if !defined( HB_MT_VM ) + if( HB_THREAD_EQUAL( pMutex->owner, HB_THREAD_SELF() ) ) + { + if( --pMutex->lock_count == 0 ) + pMutex->owner = ( HB_THREAD_ID ) 0; + fResult = TRUE; + } +#else HB_CRITICAL_LOCK( pMutex->mutex ); if( HB_THREAD_EQUAL( pMutex->owner, HB_THREAD_SELF() ) ) { @@ -1342,6 +1350,7 @@ BOOL hb_threadMutexUnlock( PHB_ITEM pItem ) fResult = TRUE; } HB_CRITICAL_UNLOCK( pMutex->mutex ); +#endif } return fResult; } @@ -1352,6 +1361,49 @@ void hb_threadMutexNotify( PHB_ITEM pItem, PHB_ITEM pNotifier, BOOL fWaiting ) if( pMutex ) { +#if !defined( HB_MT_VM ) + if( !fWaiting ) + { + if( !pMutex->events ) + { + pMutex->events = hb_itemArrayNew( 1 ); + if( pNotifier && !HB_IS_NIL( pNotifier ) ) + hb_arraySet( pMutex->events, 1, pNotifier ); + } + else if( pNotifier ) + hb_arrayAdd( pMutex->events, pNotifier ); + else + hb_arraySize( pMutex->events, hb_arrayLen( pMutex->events ) + 1 ); + } + else if( pMutex->waiters ) + { + int iCount = pMutex->waiters; + ULONG ulLen; + + if( pMutex->events ) + { + ulLen = hb_arrayLen( pMutex->events ); + iCount -= ulLen; + if( iCount > 0 ) + hb_arraySize( pMutex->events, ulLen + iCount ); + } + else + { + ulLen = 0; + pMutex->events = hb_itemArrayNew( iCount ); + } + if( iCount > 0 ) + { + if( pNotifier && !HB_IS_NIL( pNotifier ) ) + { + int iSet = iCount; + do + hb_arraySet( pMutex->events, ++ulLen, pNotifier ); + while( --iSet ); + } + } + } +#else HB_CRITICAL_LOCK( pMutex->mutex ); if( !fWaiting ) { @@ -1401,6 +1453,7 @@ void hb_threadMutexNotify( PHB_ITEM pItem, PHB_ITEM pNotifier, BOOL fWaiting ) } } HB_CRITICAL_UNLOCK( pMutex->mutex ); +#endif } }