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 "tvm.h"
#include "tmain.h" #include "tmain.h"
#define TBL_USER_INFO 20 #define TBL_USER_INFO 21
typedef struct __TBL_USER_INFO 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 <signal.h>
#include <stdarg.h> #include <stdarg.h>
#include <getopt.h> #include <getopt.h>
#include <unistd.h>
#include <math.h> #include <math.h>
#include <sys/prctl.h> #include <sys/prctl.h>
#include <sys/types.h> #include <sys/types.h>

View File

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

View File

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

View File

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