From 46fe44162be5f9b119cc82ed0d368ac181c99074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Czerpak?= Date: Wed, 9 Sep 2015 16:51:20 +0200 Subject: [PATCH] 2015-09-09 16:51 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * src/vm/estack.c ! protect access to HB_STACK_TLS_PRELOAD by hb_stack_ready() macro, it's necessary for MT builds which do not use direct TLS access but need TLS key initialization, i.e. OS2 * src/vm/hvm.c ! protect access to HB_STACK_TLS_PRELOAD by s_fHVMActive --- ChangeLog.txt | 9 +++ src/vm/estack.c | 17 +++++- src/vm/hvm.c | 151 ++++++++++++++++++++++++++---------------------- 3 files changed, 104 insertions(+), 73 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 4c1b760633..4b53aa2e39 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,15 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2015-09-09 16:51 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * src/vm/estack.c + ! protect access to HB_STACK_TLS_PRELOAD by hb_stack_ready() macro, + it's necessary for MT builds which do not use direct TLS access + but need TLS key initialization, i.e. OS2 + + * src/vm/hvm.c + ! protect access to HB_STACK_TLS_PRELOAD by s_fHVMActive + 2015-09-09 12:55 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * src/common/hbfsapi.c * pacified warnings OS2 warnings reported by David diff --git a/src/vm/estack.c b/src/vm/estack.c index 02dbae1f79..7096e2aa38 100644 --- a/src/vm/estack.c +++ b/src/vm/estack.c @@ -536,11 +536,22 @@ PHB_SET_STRUCT hb_stackSetStruct( void ) #undef hb_stackId void * hb_stackId( void ) { - HB_STACK_TLS_PRELOAD - HB_TRACE( HB_TR_DEBUG, ( "hb_stackId()" ) ); - return ( void * ) &hb_stack; +#if defined( HB_MT_VM ) + if( hb_stack_ready() ) + { + HB_STACK_TLS_PRELOAD + return ( void * ) &hb_stack; + } + else + return NULL; +#else + { + HB_STACK_TLS_PRELOAD + return ( void * ) &hb_stack; + } +#endif } #undef hb_stackPop diff --git a/src/vm/hvm.c b/src/vm/hvm.c index a3e6fa92d6..c79d01f499 100644 --- a/src/vm/hvm.c +++ b/src/vm/hvm.c @@ -500,60 +500,66 @@ static void hb_vmRequestTest( void ) /* unlock VM, allow GC and other exclusive single task code execution */ void hb_vmUnlock( void ) { - HB_STACK_TLS_PRELOAD - - if( hb_stackId() ) /* check if thread has associated HVM stack */ + if( s_fHVMActive ) { - if( hb_stackUnlock() == 1 ) - { - HB_VM_LOCK(); - s_iRunningCount--; - if( hb_vmThreadRequest ) - { - if( hb_vmThreadRequest & HB_THREQUEST_QUIT ) - { - if( ! hb_stackQuitState() ) - { - hb_stackSetQuitState( HB_TRUE ); - hb_stackSetActionRequest( HB_QUIT_REQUESTED ); - } - } - hb_threadCondBroadcast( &s_vmCond ); - } - HB_VM_UNLOCK(); - } - } + HB_STACK_TLS_PRELOAD - HB_TASK_SHEDULER(); + if( hb_stackId() ) /* check if thread has associated HVM stack */ + { + if( hb_stackUnlock() == 1 ) + { + HB_VM_LOCK(); + s_iRunningCount--; + if( hb_vmThreadRequest ) + { + if( hb_vmThreadRequest & HB_THREQUEST_QUIT ) + { + if( ! hb_stackQuitState() ) + { + hb_stackSetQuitState( HB_TRUE ); + hb_stackSetActionRequest( HB_QUIT_REQUESTED ); + } + } + hb_threadCondBroadcast( &s_vmCond ); + } + HB_VM_UNLOCK(); + } + } + + HB_TASK_SHEDULER(); + } } /* lock VM blocking GC and other exclusive single task code execution */ void hb_vmLock( void ) { - HB_STACK_TLS_PRELOAD - - if( hb_stackId() ) /* check if thread has associated HVM stack */ + if( s_fHVMActive ) { - if( hb_stackLock() == 0 ) + HB_STACK_TLS_PRELOAD + + if( hb_stackId() ) /* check if thread has associated HVM stack */ { - HB_VM_LOCK(); - for( ;; ) + if( hb_stackLock() == 0 ) { - if( hb_vmThreadRequest & HB_THREQUEST_QUIT ) + HB_VM_LOCK(); + for( ;; ) { - if( ! hb_stackQuitState() ) + if( hb_vmThreadRequest & HB_THREQUEST_QUIT ) { - hb_stackSetQuitState( HB_TRUE ); - hb_stackSetActionRequest( HB_QUIT_REQUESTED ); + if( ! hb_stackQuitState() ) + { + hb_stackSetQuitState( HB_TRUE ); + hb_stackSetActionRequest( HB_QUIT_REQUESTED ); + } } + if( hb_vmThreadRequest & HB_THREQUEST_STOP ) + hb_threadCondWait( &s_vmCond, &s_vmMtx ); + else + break; } - if( hb_vmThreadRequest & HB_THREQUEST_STOP ) - hb_threadCondWait( &s_vmCond, &s_vmMtx ); - else - break; + s_iRunningCount++; + HB_VM_UNLOCK(); } - s_iRunningCount++; - HB_VM_UNLOCK(); } } } @@ -8858,40 +8864,41 @@ HB_USHORT hb_vmRequestQuery( void ) HB_BOOL hb_vmRequestReenter( void ) { - HB_STACK_TLS_PRELOAD - PHB_ITEM pItem; - int iLocks = 0; - HB_TRACE( HB_TR_DEBUG, ( "hb_vmRequestReenter()" ) ); -#if defined( HB_MT_VM ) - if( ! s_fHVMActive || hb_stackId() == NULL ) - return HB_FALSE; - else + if( s_fHVMActive ) { - while( hb_stackLockCount() > 0 ) + HB_STACK_TLS_PRELOAD + PHB_ITEM pItem; + int iLocks = 0; + +#if defined( HB_MT_VM ) + if( hb_stackId() == NULL ) + return HB_FALSE; + else { - hb_vmLock(); - ++iLocks; + while( hb_stackLockCount() > 0 ) + { + hb_vmLock(); + ++iLocks; + } } - } -#else - if( ! s_fHVMActive ) - return HB_FALSE; #endif - hb_stackPushReturn(); + hb_stackPushReturn(); - pItem = hb_stackAllocItem(); - pItem->type = HB_IT_RECOVER; - pItem->item.asRecover.recover = NULL; - pItem->item.asRecover.base = iLocks; - pItem->item.asRecover.flags = 0; - pItem->item.asRecover.request = hb_stackGetActionRequest(); + pItem = hb_stackAllocItem(); + pItem->type = HB_IT_RECOVER; + pItem->item.asRecover.recover = NULL; + pItem->item.asRecover.base = iLocks; + pItem->item.asRecover.flags = 0; + pItem->item.asRecover.request = hb_stackGetActionRequest(); - hb_stackSetActionRequest( 0 ); + hb_stackSetActionRequest( 0 ); - return HB_TRUE; + return HB_TRUE; + } + return HB_FALSE; } void hb_vmRequestRestore( void ) @@ -8941,9 +8948,7 @@ HB_BOOL hb_vmRequestReenterExt( void ) { HB_TRACE( HB_TR_DEBUG, ( "hb_vmRequestReenterExt()" ) ); - if( ! s_fHVMActive ) - return HB_FALSE; - else + if( s_fHVMActive ) { HB_USHORT uiAction = 0; int iLocks = 0; @@ -8981,9 +8986,11 @@ HB_BOOL hb_vmRequestReenterExt( void ) pItem->item.asRecover.request = uiAction | hb_stackGetActionRequest(); hb_stackSetActionRequest( 0 ); + + return HB_TRUE; } - return HB_TRUE; + return HB_FALSE; } HB_BOOL hb_vmTryEval( PHB_ITEM * pResult, PHB_ITEM pItem, HB_ULONG ulPCount, ... ) @@ -9075,12 +9082,16 @@ HB_BOOL hb_vmIsActive( void ) HB_BOOL hb_vmIsReady( void ) { - HB_STACK_TLS_PRELOAD - HB_TRACE( HB_TR_DEBUG, ( "hb_vmIsReady()" ) ); #if defined( HB_MT_VM ) - return s_fHVMActive && hb_stackId(); + if( s_fHVMActive ) + { + HB_STACK_TLS_PRELOAD + return hb_stackId() != NULL; + } + else + return HB_FALSE; #else return s_fHVMActive; #endif