2014-05-06 17:32 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)

* src/rtl/cdpapi.c
  * src/rtl/iousr.c
  * src/rtl/hbjson.c
  * src/rtl/gtcrs/gtcrs.c
  * src/rtl/gtsln/gtsln.c
  * src/rtl/gttrm/gttrm.c
  * src/rtl/gtxwc/gtxwc.c
  * src/rdd/workarea.c
  * src/rdd/hbsix/sxcompr.c
  * contrib/hbct/token2.c
  * contrib/hbsqlit3/core.c
    * pacified some of -Wshadow warnings

  * include/hbapicdp.h
    ! typo in comment: bytes -> bits

  * src/vm/garbage.c
  * src/vm/thread.c
    * disabled some code with spinlocks when HB_HELGRIND_FRIENDLY macro
      is defined. It causes that final MT HVM code is slower using native
      platform mutexes but only such ones helgrind can recognize so the
      new macro can be useful for people who want to make some tests with
      helgrind. In such case they should rebuild Harbour with
         HB_USER_CFLAGS=HB_HELGRIND_FRIENDLY
      We use spinlocks and atomic integer operations also in few other
      places so it's possible that deeper tests can exploit them and
      we will have to cover them by HB_HELGRIND_FRIENDLY too just to
      easy detect real problems.
This commit is contained in:
Przemysław Czerpak
2014-05-06 17:32:45 +02:00
parent 7a211d052e
commit da82de17b1
15 changed files with 120 additions and 79 deletions

View File

@@ -300,9 +300,9 @@ static HB_BOOL hb_LZSSxDecode( PHB_LZSSX_COMPR pCompr )
{
HB_BOOL fResult = HB_TRUE;
HB_USHORT itemMask;
int offset, length, index, c, h;
int offset, length, rbufidx, c, h;
index = RBUFLENGTH - MAXLENGTH;
rbufidx = RBUFLENGTH - MAXLENGTH;
itemMask = 0;
do
@@ -326,8 +326,8 @@ static HB_BOOL hb_LZSSxDecode( PHB_LZSSX_COMPR pCompr )
fResult = HB_FALSE;
break;
}
pCompr->ring_buffer[ index ] = ( HB_UCHAR ) c;
index = RBUFINDEX( index + 1 );
pCompr->ring_buffer[ rbufidx ] = ( HB_UCHAR ) c;
rbufidx = RBUFINDEX( rbufidx + 1 );
}
else /* we have an item pair (ring buffer offset : match length) */
{
@@ -349,9 +349,9 @@ static HB_BOOL hb_LZSSxDecode( PHB_LZSSX_COMPR pCompr )
/* SIX does not use additional buffers and dynamically
overwrite the ring buffer - we have to make exactly
the same or our results will be differ when
abs( offset - index ) < length */
pCompr->ring_buffer[ index ] = ( HB_UCHAR ) c;
index = RBUFINDEX( index + 1 );
abs( offset - rbufidx ) < length */
pCompr->ring_buffer[ rbufidx ] = ( HB_UCHAR ) c;
rbufidx = RBUFINDEX( rbufidx + 1 );
}
}
}

View File

@@ -822,12 +822,12 @@ static HB_ERRCODE hb_waInfo( AREAP pArea, HB_USHORT uiIndex, PHB_ITEM pItem )
* Retrieve information about the current order that SELF could not.
* Called by SELF_ORDINFO if uiIndex is not supported.
*/
static HB_ERRCODE hb_waOrderInfo( AREAP pArea, HB_USHORT index, LPDBORDERINFO pInfo )
static HB_ERRCODE hb_waOrderInfo( AREAP pArea, HB_USHORT uiIndex, LPDBORDERINFO pInfo )
{
HB_TRACE( HB_TR_DEBUG, ( "hb_waOrderInfo(%p, %hu, %p)", pArea, index, pInfo ) );
HB_TRACE( HB_TR_DEBUG, ( "hb_waOrderInfo(%p, %hu, %p)", pArea, uiIndex, pInfo ) );
HB_SYMBOL_UNUSED( pArea );
HB_SYMBOL_UNUSED( index );
HB_SYMBOL_UNUSED( uiIndex );
if( pInfo->itmResult )
hb_itemClear( pInfo->itmResult );

View File

@@ -1294,10 +1294,10 @@ HB_BOOL hb_cdpGetFromUTF8( PHB_CODEPAGE cdp, HB_UCHAR ch,
{
if( HB_CDPCHAR_LEN( cdp, *pwc ) == 1 )
{
HB_SIZE n = 0;
HB_SIZE nS = 0;
char c;
if( HB_CDPCHAR_PUT( cdp, &c, 1, &n, *pwc ) )
if( HB_CDPCHAR_PUT( cdp, &c, 1, &nS, *pwc ) )
*pwc = ( HB_UCHAR ) c;
}
}

View File

@@ -395,9 +395,9 @@ static void sig_handler( int signo )
{
case SIGCHLD:
{
int stat;
int status;
pid_t pid;
while( ( pid = waitpid( -1, &stat, WNOHANG ) ) > 0 ) ;
while( ( pid = waitpid( -1, &status, WNOHANG ) ) > 0 ) ;
break;
}
case SIGWINCH:
@@ -447,10 +447,10 @@ static void sig_handler( int signo )
{
case SIGCHLD:
{
int stat;
int status;
pid_t pid;
pszSig = "SIGCHLD";
while( ( pid = waitpid( -1, &stat, WNOHANG ) ) > 0 ) ;
while( ( pid = waitpid( -1, &status, WNOHANG ) ) > 0 ) ;
break;
}
case SIGWINCH:
@@ -1864,7 +1864,7 @@ static void setKeyTrans( InOutBase * ioBase, PHB_CODEPAGE cdpTerm, PHB_CODEPAGE
}
}
static void setDispTrans( InOutBase * ioBase, PHB_CODEPAGE cdpHost, PHB_CODEPAGE cdpTerm, int box )
static void setDispTrans( InOutBase * ioBase, PHB_CODEPAGE cdpHost, PHB_CODEPAGE cdpTerm, int transBox )
{
int i, aSet;
chtype ch;
@@ -1923,7 +1923,7 @@ static void setDispTrans( InOutBase * ioBase, PHB_CODEPAGE cdpHost, PHB_CODEPAGE
hb_cdpTranslateDispChar( i, cdpHost, cdpTerm );
ioBase->std_chmap[ i ] = uc | A_NORMAL;
if( box )
if( transBox )
ioBase->box_chmap[ i ] = uc | A_NORMAL;
if( i != ( int ) uc )
{

View File

@@ -488,7 +488,7 @@ static int hb_sln_isUTF8( int iStdOut, int iStdIn )
{
char rdbuf[ 64 ];
int i, j, n, d, y, x;
HB_MAXUINT end_timer, time;
HB_MAXUINT end_timer, cur_time;
n = j = x = y = 0;
/* wait up to 2 seconds for answer */
@@ -527,8 +527,8 @@ static int hb_sln_isUTF8( int iStdOut, int iStdIn )
}
if( n == sizeof( rdbuf ) )
break;
time = hb_dateMilliSeconds();
if( time > end_timer )
cur_time = hb_dateMilliSeconds();
if( cur_time > end_timer )
break;
else
{
@@ -538,7 +538,7 @@ static int hb_sln_isUTF8( int iStdOut, int iStdIn )
FD_ZERO( &rdfds );
FD_SET( iStdIn, &rdfds );
iMilliSec = ( int ) ( end_timer - time );
iMilliSec = ( int ) ( end_timer - cur_time );
tv.tv_sec = iMilliSec / 1000;
tv.tv_usec = ( iMilliSec % 1000 ) * 1000;

View File

@@ -458,13 +458,13 @@ static int getClipKey( int nKey )
static void sig_handler( int iSigNo )
{
int e = errno, stat;
int e = errno, status;
pid_t pid;
switch( iSigNo )
{
case SIGCHLD:
while( ( pid = waitpid( -1, &stat, WNOHANG ) ) > 0 )
while( ( pid = waitpid( -1, &status, WNOHANG ) ) > 0 )
;
break;
case SIGWINCH:
@@ -1799,7 +1799,7 @@ static HB_BOOL hb_gt_trm_AnsiGetCursorPos( PHB_GTTRM pTerm, int * iRow, int * iC
{
char rdbuf[ 64 ];
int i, j, n, d, y, x;
HB_MAXUINT end_timer, time;
HB_MAXUINT end_timer, cur_time;
hb_gt_trm_termOut( pTerm, "\x1B[6n", 4 );
if( szPost )
@@ -1858,8 +1858,8 @@ static HB_BOOL hb_gt_trm_AnsiGetCursorPos( PHB_GTTRM pTerm, int * iRow, int * iC
}
if( n == sizeof( rdbuf ) )
break;
time = hb_dateMilliSeconds();
if( time > end_timer )
cur_time = hb_dateMilliSeconds();
if( cur_time > end_timer )
break;
else
{
@@ -1870,7 +1870,7 @@ static HB_BOOL hb_gt_trm_AnsiGetCursorPos( PHB_GTTRM pTerm, int * iRow, int * iC
FD_ZERO( &rdfds );
FD_SET( pTerm->hFilenoStdin, &rdfds );
iMilliSec = ( int ) ( end_timer - time );
iMilliSec = ( int ) ( end_timer - cur_time );
tv.tv_sec = iMilliSec / 1000;
tv.tv_usec = ( iMilliSec % 1000 ) * 1000;

View File

@@ -2418,12 +2418,12 @@ static void hb_gt_xwc_AddCharToInputQueue( PXWND_DEF wnd, int keyCode )
{
if( wnd->keyBuffNO > 0 && HB_INKEY_ISMOUSEPOS( keyCode ) )
{
int index = wnd->keyBuffPointer - 1;
if( index < 0 )
index += XWC_CHAR_QUEUE_SIZE;
if( HB_INKEY_ISMOUSEPOS( wnd->KeyBuff[ index ] ) )
int keyBuffPtr = wnd->keyBuffPointer - 1;
if( keyBuffPtr < 0 )
keyBuffPtr += XWC_CHAR_QUEUE_SIZE;
if( HB_INKEY_ISMOUSEPOS( wnd->KeyBuff[ keyBuffPtr ] ) )
{
wnd->KeyBuff[ index ] = keyCode;
wnd->KeyBuff[ keyBuffPtr ] = keyCode;
return;
}
}
@@ -2444,10 +2444,10 @@ static HB_BOOL hb_gt_xwc_GetCharFromInputQueue( PXWND_DEF wnd, int * keyCode )
*keyCode = 0;
if( wnd->keyBuffNO > 0 )
{
int index = wnd->keyBuffPointer - wnd->keyBuffNO;
if( index < 0 )
index += XWC_CHAR_QUEUE_SIZE;
*keyCode = wnd->KeyBuff[ index ];
int keyBuffPtr = wnd->keyBuffPointer - wnd->keyBuffNO;
if( keyBuffPtr < 0 )
keyBuffPtr += XWC_CHAR_QUEUE_SIZE;
*keyCode = wnd->KeyBuff[ keyBuffPtr ];
wnd->keyBuffNO--;
return HB_TRUE;
}
@@ -3650,7 +3650,7 @@ static HB_U32 hb_gt_xwc_HashCurrChar( HB_BYTE attr, HB_BYTE color, HB_USHORT chr
static void hb_gt_xwc_RepaintChar( PXWND_DEF wnd, int colStart, int rowStart, int colStop, int rowStop )
{
HB_USHORT irow, icol, index, startCol = 0, len, basex, basey, nsize;
HB_USHORT irow, icol, scridx, startCol = 0, len, basex, basey, nsize;
HB_BYTE oldColor = 0, color, attr;
HB_USHORT usCh16, usChBuf[ XWC_MAX_COLS ];
HB_U32 u32Curr = 0xFFFFFFFF;
@@ -3673,7 +3673,7 @@ static void hb_gt_xwc_RepaintChar( PXWND_DEF wnd, int colStart, int rowStart, in
for( irow = rowStart; irow <= rowStop; irow++ )
{
icol = colStart;
index = icol + irow * wnd->cols;
scridx = icol + irow * wnd->cols;
len = 0;
/* attribute may change mid line...
* so buffer up text with same attrib, and output it
@@ -3704,12 +3704,12 @@ static void hb_gt_xwc_RepaintChar( PXWND_DEF wnd, int colStart, int rowStart, in
color = ( color << 4 ) | ( color >> 4 );
}
if( len > 0 && ( chTrans->type != CH_CHAR ||
color != oldColor || u32Curr == wnd->pCurrScr[ index ] ) )
color != oldColor || u32Curr == wnd->pCurrScr[ scridx ] ) )
{
hb_gt_xwc_DrawString( wnd, startCol, irow, oldColor, usChBuf, len );
len = 0;
}
if( wnd->pCurrScr[ index ] != u32Curr )
if( wnd->pCurrScr[ scridx ] != u32Curr )
{
switch( chTrans->type )
{
@@ -3834,10 +3834,10 @@ static void hb_gt_xwc_RepaintChar( PXWND_DEF wnd, int colStart, int rowStart, in
break;
}
wnd->pCurrScr[ index ] = u32Curr;
wnd->pCurrScr[ scridx ] = u32Curr;
}
icol++;
index++;
scridx++;
}
if( len > 0 )
{

View File

@@ -334,7 +334,6 @@ static void _hb_jsonEncode( PHB_ITEM pValue, PHB_JSON_ENCODE_CTX pCtx,
if( HB_IS_STRING( pKey ) )
{
PHB_ITEM pItem = hb_hashGetValueAt( pValue, nIndex );
HB_BOOL fEOL = HB_FALSE;
if( nIndex > 1 )
_hb_jsonCtxAdd( pCtx, ",", 1 );
@@ -352,7 +351,10 @@ static void _hb_jsonEncode( PHB_ITEM pValue, PHB_JSON_ENCODE_CTX pCtx,
fEOL = ( HB_IS_ARRAY( pItem ) || HB_IS_HASH( pItem ) ) && hb_itemSize( pItem ) > 0;
}
else
{
_hb_jsonCtxAdd( pCtx, ":", 1 );
fEOL = HB_FALSE;
}
_hb_jsonEncode( pItem, pCtx, nLevel + 1, fEOL );
}

View File

@@ -758,10 +758,10 @@ HB_FUNC( IOUSR_SETERROR )
if( HB_ISNUM( 1 ) )
{
HB_ERRCODE errCode = ( HB_ERRCODE ) hb_parni( 1 );
if( errCode != 0 )
errCode += ( HB_ERRCODE ) hb_parni( 2 );
hb_fsSetError( errCode );
HB_ERRCODE errCodeNew = ( HB_ERRCODE ) hb_parni( 1 );
if( errCodeNew != 0 )
errCodeNew += ( HB_ERRCODE ) hb_parni( 2 );
hb_fsSetError( errCodeNew );
}
hb_retni( errCode );

View File

@@ -69,7 +69,7 @@
/* Use spinlock instead of mutex */
# if defined( HB_SPINLOCK_INIT ) && 1
# if defined( HB_SPINLOCK_INIT ) && ! defined( HB_HELGRIND_FRIENDLY )
HB_SPINLOCK_T s_gcSpinLock = HB_SPINLOCK_INIT;
# define HB_GC_LOCK() HB_SPINLOCK_ACQUIRE( &s_gcSpinLock )

View File

@@ -2053,34 +2053,43 @@ HB_BOOL hb_threadMutexLock( PHB_ITEM pItem )
pMutex->owner = ( HB_THREAD_ID ) 1;
fResult = HB_TRUE;
#else
# if ! defined( HB_HELGRIND_FRIENDLY )
if( HB_THREAD_EQUAL( pMutex->owner, HB_THREAD_SELF() ) )
{
pMutex->lock_count++;
fResult = HB_TRUE;
}
else
#endif
{
hb_vmUnlock();
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 );
# if defined( HB_HELGRIND_FRIENDLY )
if( HB_THREAD_EQUAL( pMutex->owner, HB_THREAD_SELF() ) )
pMutex->lock_count++;
else
# endif
pMutex->lockers--;
{
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 = 1;
pMutex->owner = HB_THREAD_SELF();
}
pMutex->lock_count = 1;
pMutex->owner = HB_THREAD_SELF();
HB_CRITICAL_UNLOCK( pMutex->mutex );
fResult = HB_TRUE;