From 286b4185111c73c8248d521ee33cce2e7239e2a5 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Mon, 9 Nov 2009 15:26:57 +0000 Subject: [PATCH] 2009-11-09 16:26 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/config/win/bcc.mk * increased library page size for 64 to 96 * harbour/src/vm/thread.c * harbour/include/hbthread.h % removed 'BOOL fSync' parameter from hb_threadMutexCreate(). This parameter was added in the past to emulate xbase++ behavior when oSignal:wait() is called from SYNC method but real life tests shows that such feature works in xbase++ in different way then it was initially described and Harbour code was updated to use different solution making above parameter unusable. * harbour/src/vm/hvm.c * harbour/src/vm/thread.c * harbour/src/vm/classes.c * harbour/src/rtl/hbgtcore.c * harbour/contrib/hbnetio/netiocli.c * harbour/contrib/hbqt/hbqt_slots.cpp * updated to use hb_threadMutexCreate() without parameters --- harbour/ChangeLog | 21 ++++++ harbour/config/win/bcc.mk | 2 +- harbour/contrib/hbnetio/netiocli.c | 2 +- harbour/contrib/hbqt/hbqt_slots.cpp | 2 +- harbour/include/hbthread.h | 2 +- harbour/src/rtl/hbgtcore.c | 2 +- harbour/src/vm/classes.c | 10 +-- harbour/src/vm/hvm.c | 2 +- harbour/src/vm/thread.c | 106 ++++------------------------ 9 files changed, 45 insertions(+), 104 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 9e2f56f8e6..92cc731fa3 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,27 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-11-09 16:26 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/config/win/bcc.mk + * increased library page size for 64 to 96 + + * harbour/src/vm/thread.c + * harbour/include/hbthread.h + % removed 'BOOL fSync' parameter from hb_threadMutexCreate(). + This parameter was added in the past to emulate xbase++ behavior + when oSignal:wait() is called from SYNC method but real life tests + shows that such feature works in xbase++ in different way then + it was initially described and Harbour code was updated to use + different solution making above parameter unusable. + + * harbour/src/vm/hvm.c + * harbour/src/vm/thread.c + * harbour/src/vm/classes.c + * harbour/src/rtl/hbgtcore.c + * harbour/contrib/hbnetio/netiocli.c + * harbour/contrib/hbqt/hbqt_slots.cpp + * updated to use hb_threadMutexCreate() without parameters + 2009-11-09 13:23 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/src/rtl/cdpapi.c ! fixed very bad typo in new CDP API code - hb_cdpnDup2() was not updating diff --git a/harbour/config/win/bcc.mk b/harbour/config/win/bcc.mk index 6296b58436..f0ec526e0a 100644 --- a/harbour/config/win/bcc.mk +++ b/harbour/config/win/bcc.mk @@ -59,7 +59,7 @@ LDLIBS += $(foreach lib,$(SYSLIBS),$(lib)$(LIB_EXT)) LDFLAGS += $(LIBPATHS) AR := tlib.exe -ARFLAGS := /P64 +ARFLAGS := /P96 AR_RULE = $(AR) $(ARFLAGS) $(HB_USER_AFLAGS) "$(subst /,\,$(LIB_DIR)/$@)" $(foreach file,$(?F),-+$(file)) ifneq ($(HB_SHELL),sh) diff --git a/harbour/contrib/hbnetio/netiocli.c b/harbour/contrib/hbnetio/netiocli.c index a182267ecb..b9cc4ca425 100644 --- a/harbour/contrib/hbnetio/netiocli.c +++ b/harbour/contrib/hbnetio/netiocli.c @@ -209,7 +209,7 @@ static PHB_CONCLI s_fileConNew( HB_SOCKET sd, const char * pszServer, iLen = ( int ) strlen( pszServer ); conn = ( PHB_CONCLI ) hb_xgrab( sizeof( HB_CONCLI ) + iLen ); hb_atomic_set( &conn->used, 1 ); - conn->mutex = hb_threadMutexCreate( FALSE ); + conn->mutex = hb_threadMutexCreate(); conn->sd = sd; conn->next = NULL; conn->timeout = iTimeOut; diff --git a/harbour/contrib/hbqt/hbqt_slots.cpp b/harbour/contrib/hbqt/hbqt_slots.cpp index 0b7e859ecc..f006e18c02 100644 --- a/harbour/contrib/hbqt/hbqt_slots.cpp +++ b/harbour/contrib/hbqt/hbqt_slots.cpp @@ -2461,7 +2461,7 @@ HB_FUNC( QT_MUTEXCREATE ) { if( s_mutex == NULL ) { - s_mutex = hb_threadMutexCreate( FALSE ); + s_mutex = hb_threadMutexCreate(); } } diff --git a/harbour/include/hbthread.h b/harbour/include/hbthread.h index 5e4f0bb0e3..80e2b9a970 100644 --- a/harbour/include/hbthread.h +++ b/harbour/include/hbthread.h @@ -413,7 +413,7 @@ extern BOOL hb_threadJoin( HB_THREAD_HANDLE th_h ); extern BOOL hb_threadDetach( HB_THREAD_HANDLE th_h ); /* used by .prg code */ -extern PHB_ITEM hb_threadMutexCreate( BOOL fSync ); +extern PHB_ITEM hb_threadMutexCreate( void ); extern BOOL hb_threadMutexLock( PHB_ITEM pItem ); extern BOOL hb_threadMutexTimedLock( PHB_ITEM pItem, ULONG ulMilliSec ); extern BOOL hb_threadMutexUnlock( PHB_ITEM pItem ); diff --git a/harbour/src/rtl/hbgtcore.c b/harbour/src/rtl/hbgtcore.c index dce7f8658c..72afb00bbb 100644 --- a/harbour/src/rtl/hbgtcore.c +++ b/harbour/src/rtl/hbgtcore.c @@ -109,7 +109,7 @@ static void hb_gt_def_BaseInit( PHB_GT_BASE pGT ) pGT->inkeyBuffer = pGT->defaultKeyBuffer; pGT->inkeyBufferSize = HB_DEFAULT_INKEY_BUFSIZE; - pGT->pMutex = hb_threadMutexCreate( TRUE ); + pGT->pMutex = hb_threadMutexCreate(); if( pGT->pMutex ) hb_gcUnlock( pGT->pMutex ); } diff --git a/harbour/src/vm/classes.c b/harbour/src/vm/classes.c index 1695b7c6e5..e7cdb61373 100644 --- a/harbour/src/vm/classes.c +++ b/harbour/src/vm/classes.c @@ -926,7 +926,7 @@ static void hb_clsCopyClass( PCLASS pClsDst, PCLASS pClsSrc ) pClsDst->uiMutexOffset = pClsSrc->uiMutexOffset; pClsDst->ulOpFlags = pClsSrc->ulOpFlags; if( pClsSrc->pMutex ) - pClsDst->pMutex = hb_threadMutexCreate( FALSE ); + pClsDst->pMutex = hb_threadMutexCreate(); if( pClsSrc->uiInitDatas ) { @@ -1056,7 +1056,7 @@ void hb_clsInit( void ) s_pClasses[ 0 ] = NULL; #if defined( HB_MT_VM ) - s_pClassMtx = hb_threadMutexCreate( FALSE ); + s_pClassMtx = hb_threadMutexCreate(); #endif } @@ -2990,7 +2990,7 @@ static BOOL hb_clsAddMsg( USHORT uiClass, const char * szMessage, if( uiScope & HB_OO_CLSTP_CLASS ) { if( !pClass->pMutex ) - pClass->pMutex = hb_threadMutexCreate( FALSE ); + pClass->pMutex = hb_threadMutexCreate(); pNewMeth->pFuncSym = &s___msgSyncClass; } else @@ -3352,7 +3352,7 @@ static USHORT hb_clsNew( const char * szClassName, USHORT uiDatas, if( pNewCls->uiMutexOffset ) pNewCls->uiMutexOffset = pNewCls->uiDatas + 1; if( fClsMutex && !pNewCls->pMutex ) - pNewCls->pMutex = hb_threadMutexCreate( FALSE ); + pNewCls->pMutex = hb_threadMutexCreate(); return s_uiClasses; } @@ -3478,7 +3478,7 @@ static PHB_ITEM hb_clsInst( USHORT uiClass ) if( pClass->uiMutexOffset ) { - PHB_ITEM pMutex = hb_threadMutexCreate( FALSE ); + PHB_ITEM pMutex = hb_threadMutexCreate(); hb_arraySet( pSelf, pClass->uiMutexOffset, pMutex ); hb_itemRelease( pMutex ); } diff --git a/harbour/src/vm/hvm.c b/harbour/src/vm/hvm.c index 158e01f2d9..167b51861f 100644 --- a/harbour/src/vm/hvm.c +++ b/harbour/src/vm/hvm.c @@ -914,7 +914,7 @@ void hb_vmInit( BOOL bStartMainProc ) #if defined( HB_MT_VM ) hb_threadInit(); hb_vmStackInit( hb_threadStateNew() ); /* initialize HVM thread stack */ - s_pSymbolsMtx = hb_threadMutexCreate( FALSE ); + s_pSymbolsMtx = hb_threadMutexCreate(); #else hb_stackInit(); /* initialize HVM stack */ #endif /* HB_MT_VM */ diff --git a/harbour/src/vm/thread.c b/harbour/src/vm/thread.c index c2ab0570ae..a7c114e3bf 100644 --- a/harbour/src/vm/thread.c +++ b/harbour/src/vm/thread.c @@ -1464,7 +1464,7 @@ HB_FUNC( HB_THREADONCE ) hb_threadInit(); HB_CRITICAL_LOCK( s_once_mtx ); if( !s_pOnceMutex ) - s_pOnceMutex = hb_threadMutexCreate( FALSE ); + s_pOnceMutex = hb_threadMutexCreate(); HB_CRITICAL_UNLOCK( s_once_mtx ); } if( hb_threadMutexLock( s_pOnceMutex ) ) @@ -1498,7 +1498,6 @@ HB_FUNC( HB_THREADONCE ) typedef struct _HB_MUTEX { - BOOL fSync; int lock_count; int lockers; int waiters; @@ -1512,15 +1511,6 @@ typedef struct _HB_MUTEX } HB_MUTEX, * PHB_MUTEX; -typedef struct _HB_MTXLST -{ - int lock_count; - PHB_MUTEX pMutex; - struct _HB_MTXLST * pNext; -} -HB_MTXLST, * PHB_MTXLST; - -static PHB_MUTEX s_pSyncList = NULL; static PHB_MUTEX s_pMutexList = NULL; static void hb_mutexLink( PHB_MUTEX *pList, PHB_MUTEX pItem ) @@ -1551,12 +1541,12 @@ static void hb_mutexUnlink( PHB_MUTEX *pList, PHB_MUTEX pItem ) } #if defined( HB_MT_VM ) -static void hb_mutexListUnlock( PHB_MUTEX * pList, PHB_MTXLST * pStore ) +void hb_threadMutexUnlockAll( void ) { HB_CRITICAL_LOCK( s_mutexlst_mtx ); - if( *pList ) + if( s_pMutexList ) { - PHB_MUTEX pMutex = *pList; + PHB_MUTEX pMutex = s_pMutexList; do { if( HB_THREAD_EQUAL( pMutex->owner, HB_THREAD_SELF() ) ) @@ -1564,14 +1554,6 @@ static void hb_mutexListUnlock( PHB_MUTEX * pList, PHB_MTXLST * pStore ) HB_CRITICAL_LOCK( pMutex->mutex ); if( HB_THREAD_EQUAL( pMutex->owner, HB_THREAD_SELF() ) ) { - if( pStore ) - { - *pStore = ( PHB_MTXLST ) hb_xgrab( sizeof( HB_MTXLST ) ); - (*pStore)->lock_count = pMutex->lock_count; - (*pStore)->pMutex = pMutex; - pStore = &(*pStore)->pNext; - *pStore = NULL; - } pMutex->lock_count = 0; pMutex->owner = ( HB_THREAD_ID ) 0; if( pMutex->lockers ) @@ -1581,51 +1563,11 @@ static void hb_mutexListUnlock( PHB_MUTEX * pList, PHB_MTXLST * pStore ) } pMutex = pMutex->pNext; } - while( pMutex != *pList ); + while( pMutex != s_pMutexList ); } HB_CRITICAL_UNLOCK( s_mutexlst_mtx ); } -static void hb_mutexListLock( PHB_MTXLST pList ) -{ - while( pList ) - { - PHB_MUTEX pMutex = pList->pMutex; - - HB_CRITICAL_LOCK( pMutex->mutex ); - while( pMutex->lock_count != 0 ) - { - pMutex->lockers++; -#if defined( HB_PTHREAD_API ) - pthread_cond_wait( &pMutex->cond_l, &pMutex->mutex ); -#elif defined( HB_TASK_THREAD ) - hb_taskWait( &pMutex->cond_l, &pMutex->mutex, HB_TASK_INFINITE_WAIT ); -#elif defined( HB_COND_HARBOUR_SUPPORT ) - _hb_thread_cond_wait( &pMutex->cond_l, &pMutex->mutex, HB_THREAD_INFINITE_WAIT ); -#else - HB_CRITICAL_UNLOCK( pMutex->mutex ); - ( void ) HB_COND_WAIT( pMutex->cond_l ); - HB_CRITICAL_LOCK( pMutex->mutex ); -#endif - pMutex->lockers--; - } - pMutex->lock_count = pList->lock_count; - pMutex->owner = HB_THREAD_SELF(); - HB_CRITICAL_UNLOCK( pMutex->mutex ); - { - PHB_MTXLST pFree = pList; - pList = pList->pNext; - hb_xfree( pFree ); - } - } -} - -void hb_threadMutexUnlockAll( void ) -{ - hb_mutexListUnlock( &s_pMutexList, NULL ); - hb_mutexListUnlock( &s_pSyncList, NULL ); -} - #endif static HB_GARBAGE_FUNC( hb_mutexDestructor ) @@ -1634,10 +1576,10 @@ static HB_GARBAGE_FUNC( hb_mutexDestructor ) #if defined( HB_MT_VM ) HB_CRITICAL_LOCK( s_mutexlst_mtx ); - hb_mutexUnlink( pMutex->fSync ? &s_pSyncList : &s_pMutexList, pMutex ); + hb_mutexUnlink( &s_pMutexList, pMutex ); HB_CRITICAL_UNLOCK( s_mutexlst_mtx ); #else - hb_mutexUnlink( pMutex->fSync ? &s_pSyncList : &s_pMutexList, pMutex ); + hb_mutexUnlink( &s_pMutexList, pMutex ); #endif if( pMutex->events ) @@ -1684,7 +1626,7 @@ static PHB_ITEM hb_mutexParam( int iParam ) return NULL; } -PHB_ITEM hb_threadMutexCreate( BOOL fSync ) +PHB_ITEM hb_threadMutexCreate( void ) { PHB_MUTEX pMutex; PHB_ITEM pItem; @@ -1704,13 +1646,12 @@ PHB_ITEM hb_threadMutexCreate( BOOL fSync ) # endif #endif - pMutex->fSync = fSync; #if defined( HB_MT_VM ) HB_CRITICAL_LOCK( s_mutexlst_mtx ); - hb_mutexLink( fSync ? &s_pSyncList : &s_pMutexList, pMutex ); + hb_mutexLink( &s_pMutexList, pMutex ); HB_CRITICAL_UNLOCK( s_mutexlst_mtx ); #else - hb_mutexLink( fSync ? &s_pSyncList : &s_pMutexList, pMutex ); + hb_mutexLink( &s_pMutexList, pMutex ); #endif return pItem; @@ -1782,7 +1723,7 @@ BOOL hb_threadMutexSyncWait( PHB_ITEM pItemMtx, ULONG ulMilliSec, if( ulMilliSec && !( pMutex->events && hb_arrayLen( pMutex->events ) > 0 ) ) { - /* release own locks from sync mutex */ + /* release own lock from sync mutex */ if( pSyncMutex && HB_THREAD_EQUAL( pSyncMutex->owner, HB_THREAD_SELF() ) ) { HB_CRITICAL_LOCK( pSyncMutex->mutex ); @@ -1856,7 +1797,7 @@ BOOL hb_threadMutexSyncWait( PHB_ITEM pItemMtx, ULONG ulMilliSec, HB_CRITICAL_UNLOCK( pMutex->mutex ); - /* restore the own locks on sync mutex if necessary */ + /* restore the own lock on sync mutex if necessary */ if( lock_count ) { HB_CRITICAL_LOCK( pSyncMutex->mutex ); @@ -2179,8 +2120,6 @@ PHB_ITEM hb_threadMutexSubscribe( PHB_ITEM pItem, BOOL fClear ) } } #else - PHB_MTXLST pSyncList = NULL; - BOOL fSync = TRUE; int lock_count = 0; hb_vmUnlock(); @@ -2202,15 +2141,6 @@ PHB_ITEM hb_threadMutexSubscribe( PHB_ITEM pItem, BOOL fClear ) while( !pMutex->events || hb_arrayLen( pMutex->events ) == 0 ) { - if( fSync ) - { - /* SYNC method mutexes cannot be used for subscribe so it's safe - * to unlock them when THIS mutex is internally locked - */ - hb_mutexListUnlock( &s_pSyncList, &pSyncList ); - fSync = FALSE; - } - pMutex->waiters++; # if defined( HB_PTHREAD_API ) pthread_cond_wait( &pMutex->cond_w, &pMutex->mutex ); @@ -2262,8 +2192,6 @@ PHB_ITEM hb_threadMutexSubscribe( PHB_ITEM pItem, BOOL fClear ) HB_CRITICAL_UNLOCK( pMutex->mutex ); - hb_mutexListLock( pSyncList ); - hb_vmLock(); #endif } @@ -2293,7 +2221,6 @@ PHB_ITEM hb_threadMutexTimedSubscribe( PHB_ITEM pItem, ULONG ulMilliSec, BOOL fC } } #else - PHB_MTXLST pSyncList = NULL; int lock_count = 0; hb_vmUnlock(); @@ -2315,11 +2242,6 @@ PHB_ITEM hb_threadMutexTimedSubscribe( PHB_ITEM pItem, ULONG ulMilliSec, BOOL fC HB_COND_SIGNAL( pMutex->cond_l ); } - /* SYNC method mutexes cannot be used for subscribe so it's safe - * to unlock them when THIS mutex is internally locked - */ - hb_mutexListUnlock( &s_pSyncList, &pSyncList ); - pMutex->waiters++; # if defined( HB_PTHREAD_API ) { @@ -2388,8 +2310,6 @@ PHB_ITEM hb_threadMutexTimedSubscribe( PHB_ITEM pItem, ULONG ulMilliSec, BOOL fC HB_CRITICAL_UNLOCK( pMutex->mutex ); - hb_mutexListLock( pSyncList ); - hb_vmLock(); #endif } @@ -2398,7 +2318,7 @@ PHB_ITEM hb_threadMutexTimedSubscribe( PHB_ITEM pItem, ULONG ulMilliSec, BOOL fC HB_FUNC( HB_MUTEXCREATE ) { - hb_itemReturnRelease( hb_threadMutexCreate( FALSE ) ); + hb_itemReturnRelease( hb_threadMutexCreate() ); } HB_FUNC( HB_MUTEXLOCK )