fix thread safe

pull/1/head
deffpuzzl 2018-06-07 21:37:33 +08:00
parent 7332f1593e
commit af3ee67ffa
16 changed files with 59 additions and 31 deletions

Binary file not shown.

Binary file not shown.

BIN
demo/drop

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,7 +1,7 @@
#include "tvm.h"
#include "tmain.h"
#define TBL_USER_INFO 20
#define TBL_USER_INFO 21
typedef struct __TBL_USER_INFO
{

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -30,7 +30,6 @@
#include <signal.h>
#include <stdarg.h>
#include <getopt.h>
#include <unistd.h>
#include <math.h>
#include <sys/prctl.h>
#include <sys/types.h>

View File

@ -54,7 +54,6 @@ typedef long CREATE;
#define QUE_NOWAIT 1
#define QUE_NORMAL 0
// execution plan
#define EXE_PLAN_ALL 0
#define EXE_PLAN_IDX 1

View File

@ -80,21 +80,30 @@ long _lPush(SATvm *pstSavm, void *pvAddr)
RC_SUCC --success
RC_FAIL --failure
*************************************************************************************************/
long _lPopup(SATvm *pstSavm, void *pvAddr, void *pvOut, Timesp *tm)
long _lPop(SATvm *pstSavm, void *pvAddr, void *pvOut, Timesp *tm)
{
int nPos, lRet;
int nPos;
SHTruck *ps = NULL;
extern int errno;
TblDef *pv = (TblDef *)pvAddr;
errno = 0;
while(1)
{
Futex(&pv->m_lValid, FUTEX_WAIT, 0, tm);
if(EWOULDBLOCK != errno && 0 != errno)
if(0 != Futex(&pv->m_lValid, FUTEX_WAIT, 0, tm))
{
if(ETIMEDOUT == errno) // timeout
{
pstSavm->m_lErrno = NO_DATA_FOUND;
return RC_FAIL;
}
else if(EWOULDBLOCK != errno)
{
pstSavm->m_lErrno = MQUE_WAIT_ERR;
return RC_FAIL;
}
else // EWOULDBLOCK
;
}
if(0 == pv->m_lValid)
continue;
@ -146,6 +155,7 @@ long _lPops(SATvm *pstSavm, void *pvAddr, size_t lExpect, Timesp *tm, size_t
{
int nPos;
SHTruck *ps = NULL;
extern int errno;
TblDef *pv = (TblDef *)pvAddr;
if(NULL == (*ppsvOut = (char *)malloc(lExpect * pv->m_lReSize)))
@ -154,25 +164,29 @@ long _lPops(SATvm *pstSavm, void *pvAddr, size_t lExpect, Timesp *tm, size_t
return RC_FAIL;
}
for (*plOut = 0; 0 < lExpect; --lExpect)
for (*plOut = 0; *plOut < lExpect; )
{
if(0 != Futex(&pv->m_lValid, FUTEX_WAIT, 0, tm))
{
if(EWOULDBLOCK == errno)
if(ETIMEDOUT == errno)
{
if(0 == *plOut)
{
pstSavm->m_lErrno = NO_DATA_FOUND;
TFree(*ppsvOut);
pstSavm->m_lErrno = NO_DATA_FOUND;
}
else
pstSavm->m_lErrno = MQUE_WAIT_TMO;
return RC_SUCC;
return RC_FAIL;
}
else if(EWOULDBLOCK != errno)
{
pstSavm->m_lErrno = MQUE_WAIT_ERR;
return RC_FAIL;
}
else // EWOULDBLOCK
;
}
if(0 == pv->m_lValid)
continue;
@ -246,9 +260,9 @@ long lPop(SATvm *pstSavm, void *pvOut, Uenum eWait)
}
if(QUE_NOWAIT == eWait)
lRet = _lPopup(pstSavm, pstRun->m_pvAddr, pvOut, &tm);
lRet = _lPop(pstSavm, pstRun->m_pvAddr, pvOut, &tm);
else
lRet = _lPopup(pstSavm, pstRun->m_pvAddr, pvOut, NULL);
lRet = _lPop(pstSavm, pstRun->m_pvAddr, pvOut, NULL);
vTblDisconnect(pstSavm, pstSavm->tblName);
return lRet;
}

View File

@ -5116,6 +5116,21 @@ long lTruncate(SATvm *pstSavm, TABLE t)
return RC_FAIL;
}
if(TYPE_MQUEUE == pstRun->m_lType)
{
pstSavm->m_lEffect = ((TblDef *)pstRun->m_pvAddr)->m_lValid;
pvData = (void *)pGetNode(pstRun->m_pvAddr, lGetTblData(t));
memset(pvData, 0, lGetTableSize(t) - lGetTblData(t));
((TblDef *)pstRun->m_pvAddr)->m_lGroup = 0;
((TblDef *)pstRun->m_pvAddr)->m_lValid = 0;
((TblDef *)pstRun->m_pvAddr)->m_lListPos = 0;
((TblDef *)pstRun->m_pvAddr)->m_lListOfs = 0;
pthread_rwlock_unlock(prwLock);
vTblDisconnect(pstSavm, t);
return RC_SUCC;
}
if(RC_SUCC != lInitailTree(pstSavm, (void *)pGetNode(pstRun->m_pvAddr, lGetIdxPos(t)), t))
{
pthread_rwlock_unlock(prwLock);
@ -9129,7 +9144,6 @@ long lImportFile(TABLE t, char *pszFile, char *pszFlag)
memcpy(pvData, szLine, lGetRowSize(t));
else
_lImportContext(szLine, lGetFldNum(t), pGetTblKey(t), pvData, pszFlag);
if(RC_SUCC != __lInsert(pstSavm, pstRun, pstSavm->tblName, 0))
break;
@ -9478,9 +9492,6 @@ long lRenameTable(SATvm *pstSavm, TABLE to, TABLE tn)
vTblDisconnect(pstSavm, pstSavm->tblName);
memset((void *)pGetRunTime(pstSavm, to), 0, sizeof(RunTime));
if(TYPE_MQUEUE == pstRun->m_lType)
return RC_SUCC;
if(RC_SUCC != lInitSATvm(pstSavm, SYS_TVM_FIELD))
return RC_FAIL;
@ -9488,7 +9499,13 @@ long lRenameTable(SATvm *pstSavm, TABLE to, TABLE tn)
conditinit(pstSavm, stField, SYS_TVM_FIELD);
conditnum(pstSavm, stField, m_table, to);
updatenum(pstSavm, stNFld, m_table, tn);
return lUpdate(pstSavm, &stNFld);
if(RC_SUCC != lUpdate(pstSavm, &stNFld))
{
if(NO_DATA_FOUND != pstSavm->m_lErrno)
return RC_FAIL;
}
return RC_SUCC;
}
/*************************************************************************************************
@ -11040,7 +11057,6 @@ long lMountTable(SATvm *pstSavm, char *pszFile)
}
lEffect ++;
if(RC_SUCC != __lInsert(pstSavm, pstRun, pstSavm->tblName, uTimes))
{
fprintf(stderr, "=>警告, 导入表:%s 第(%ld)条记录错误, %s, 跳过..\n",