From a8aac5cae59af5799cb98c4e7891b16d529782ad Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Mon, 22 Sep 2008 00:34:52 +0000 Subject: [PATCH] 2008-09-22 02:34 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbvm.h * harbour/source/vm/hvm.c * harbour/source/vm/thread.c + added .prg function hb_threadSelf() -> | NIL It returns thread ID pointer variable or NIL when thread was registered without it (main thread and some 3-rd party threads created by C API) * harbour/source/vm/hvm.c * protect s_InitFunctions and s_ExitFunctions by mutex * harbour/source/common/hbverdsp.c * use hb_verBuildDate() instead of __DATE__ and __TIME__ in hb_verBuildInfo() function to report the same time in both cases. --- harbour/ChangeLog | 17 +++++++++++++++++ harbour/include/hbvm.h | 1 + harbour/source/common/hbverdsp.c | 30 +++++++++++++----------------- harbour/source/vm/hvm.c | 18 ++++++++++++++++++ harbour/source/vm/thread.c | 8 ++++++++ 5 files changed, 57 insertions(+), 17 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 3fc3ab3016..9a80a74302 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,23 @@ 2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2008-09-22 02:34 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/hbvm.h + * harbour/source/vm/hvm.c + * harbour/source/vm/thread.c + + added .prg function hb_threadSelf() -> | NIL + It returns thread ID pointer variable or NIL when thread was + registered without it (main thread and some 3-rd party threads + created by C API) + + * harbour/source/vm/hvm.c + * protect s_InitFunctions and s_ExitFunctions by mutex + + * harbour/source/common/hbverdsp.c + * use hb_verBuildDate() instead of __DATE__ and __TIME__ in + hb_verBuildInfo() function to report the same time in both + cases. + 2008-09-21 23:03 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbapi.h * harbour/source/vm/arrays.c diff --git a/harbour/include/hbvm.h b/harbour/include/hbvm.h index 11fedbdd0c..5f3bbadfb6 100644 --- a/harbour/include/hbvm.h +++ b/harbour/include/hbvm.h @@ -164,6 +164,7 @@ extern HB_EXPORT void hb_vmThreadQuit( void ); /* destroy local thread HVM s extern HB_EXPORT void hb_vmThreadQuitRequest( void * ); /* send QUIT request to given thread */ extern HB_EXPORT void hb_vmWaitForThreads( void ); /* wait for all threads to terminate can be called only by main HVM thread */ extern HB_EXPORT void hb_vmTerminateThreads( void ); /* send QUIT request to all threads except current one and wait for their termination, should be called only by main HVM thread */ +extern HB_EXPORT void * hb_vmThreadState( void ); /* various flags for supported features */ #define HB_VMFLAG_HARBOUR 1 /* enable Harbour extension */ diff --git a/harbour/source/common/hbverdsp.c b/harbour/source/common/hbverdsp.c index b9368c9a19..ed9f997738 100644 --- a/harbour/source/common/hbverdsp.c +++ b/harbour/source/common/hbverdsp.c @@ -93,25 +93,21 @@ void hb_verBuildInfo( void ) hb_conOutErr( hb_conNewLine(), 0 ); - hb_conOutErr( "Built on: ", 0 ); - hb_conOutErr( __DATE__, 0 ); - hb_conOutErr( " ", 0 ); - hb_conOutErr( __TIME__, 0 ); + { + char * pszBuildDate = hb_verBuildDate(); + hb_conOutErr( "Built on: ", 0 ); + hb_conOutErr( pszBuildDate, 0 ); + hb_conOutErr( hb_conNewLine(), 0 ); + hb_xfree( pszBuildDate ); + } + + hb_conOutErr( "Last ChangeLog entry: ", 0 ); + hb_conOutErr( hb_verSvnLastEntry(), 0 ); hb_conOutErr( hb_conNewLine(), 0 ); - { - const char * pszLastEntry = hb_verSvnLastEntry(); - hb_conOutErr( "Last ChangeLog entry: ", 0 ); - hb_conOutErr( pszLastEntry, 0 ); - hb_conOutErr( hb_conNewLine(), 0 ); - } - - { - const char * pszLogID = hb_verSvnChangeLogID(); - hb_conOutErr( "ChangeLog SVN version: ", 0 ); - hb_conOutErr( pszLogID, 0 ); - hb_conOutErr( hb_conNewLine(), 0 ); - } + hb_conOutErr( "ChangeLog SVN version: ", 0 ); + hb_conOutErr( hb_verSvnChangeLogID(), 0 ); + hb_conOutErr( hb_conNewLine(), 0 ); { const char * pszFlags = hb_verFlagsPRG(); diff --git a/harbour/source/vm/hvm.c b/harbour/source/vm/hvm.c index 4d8e7b4ada..13bc3bdea9 100644 --- a/harbour/source/vm/hvm.c +++ b/harbour/source/vm/hvm.c @@ -221,6 +221,13 @@ static void hb_vmMsgIndexReference( PHB_ITEM pRefer, PHB_ITEM pObject, PHB_IT #if defined( HB_MT_VM ) static int volatile hb_vmThreadRequest = 0; static void hb_vmRequestTest( void ); + +static HB_CRITICAL_NEW( s_atInitMtx ); +# define HB_ATINIT_LOCK hb_threadEnterCriticalSection( &s_atInitMtx ); +# define HB_ATINIT_UNLOCK hb_threadLeaveCriticalSection( &s_atInitMtx ); +#else +# define HB_ATINIT_LOCK +# define HB_ATINIT_UNLOCK #endif #ifndef HB_NO_PROFILER @@ -290,8 +297,10 @@ HB_EXPORT void hb_vmAtInit( HB_INIT_FUNC pFunc, void * cargo ) pLst->pFunc = pFunc; pLst->cargo = cargo; + HB_ATINIT_LOCK pLst->pNext = s_InitFunctions; s_InitFunctions = pLst; + HB_ATINIT_UNLOCK } HB_EXPORT void hb_vmAtExit( HB_INIT_FUNC pFunc, void * cargo ) @@ -300,8 +309,10 @@ HB_EXPORT void hb_vmAtExit( HB_INIT_FUNC pFunc, void * cargo ) pLst->pFunc = pFunc; pLst->cargo = cargo; + HB_ATINIT_LOCK pLst->pNext = s_ExitFunctions; s_ExitFunctions = pLst; + HB_ATINIT_UNLOCK } static void hb_vmCleanModuleFunctions( void ) @@ -560,6 +571,13 @@ void hb_vmWaitForThreads( void ) } } +void * hb_vmThreadState( void ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_vmThreadState()")); + + return ( void * ) ( ( PHB_VM_STACKLST ) hb_stackList() )->pState; +} + static void hb_vmStackAdd( PHB_THREADSTATE pState ) { PHB_VM_STACKLST pStack; diff --git a/harbour/source/vm/thread.c b/harbour/source/vm/thread.c index 7a63c17e2b..c10d5a18be 100644 --- a/harbour/source/vm/thread.c +++ b/harbour/source/vm/thread.c @@ -639,6 +639,14 @@ HB_FUNC( HB_THREADSTART ) } } +HB_FUNC( HB_THREADSELF ) +{ +#if defined( HB_MT_VM ) + PHB_THREADSTATE pThread = ( PHB_THREADSTATE ) hb_vmThreadState(); + hb_itemReturn( pThread->pThItm ); +#endif +} + HB_FUNC( HB_THREADJOIN ) { PHB_THREADSTATE pThread = hb_thParam( 1 );