提交 5651bde6 编写于 作者: C Cary Xu

enh: use lock in buf pool only for rsma vnode

上级 13680e2e
......@@ -65,6 +65,7 @@ struct SVBufPool {
SVnode* pVnode;
volatile int32_t nRef;
TdThreadSpinlock lock;
bool isLock;
int64_t size;
uint8_t* ptr;
SVBufPoolNode* pTail;
......
......@@ -27,10 +27,15 @@ static int vnodeBufPoolCreate(SVnode *pVnode, int64_t size, SVBufPool **ppPool)
return -1;
}
if (taosThreadSpinInit(&pPool->lock, 0) != 0) {
taosMemoryFree(pPool);
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
if (VND_IS_RSMA(pVnode)) {
if (taosThreadSpinInit(&pPool->lock, 0) != 0) {
taosMemoryFree(pPool);
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
}
pPool->isLock = true;
} else {
pPool->isLock = false;
}
pPool->next = NULL;
......@@ -49,7 +54,9 @@ static int vnodeBufPoolCreate(SVnode *pVnode, int64_t size, SVBufPool **ppPool)
static int vnodeBufPoolDestroy(SVBufPool *pPool) {
vnodeBufPoolReset(pPool);
taosThreadSpinDestroy(&pPool->lock);
if (pPool->isLock) {
taosThreadSpinDestroy(&pPool->lock);
}
taosMemoryFree(pPool);
return 0;
}
......@@ -114,7 +121,10 @@ void *vnodeBufPoolMalloc(SVBufPool *pPool, int size) {
void *p = NULL;
ASSERT(pPool != NULL);
taosThreadSpinLock(&pPool->lock);
if (pPool->isLock) {
taosThreadSpinLock(&pPool->lock);
}
if (pPool->node.size >= pPool->ptr - pPool->node.data + size) {
// allocate from the anchor node
p = pPool->ptr;
......@@ -125,7 +135,9 @@ void *vnodeBufPoolMalloc(SVBufPool *pPool, int size) {
pNode = taosMemoryMalloc(sizeof(*pNode) + size);
if (pNode == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
taosThreadSpinUnlock(&pPool->lock);
if (pPool->isLock) {
taosThreadSpinUnlock(&pPool->lock);
}
return NULL;
}
......@@ -138,7 +150,9 @@ void *vnodeBufPoolMalloc(SVBufPool *pPool, int size) {
pPool->size = pPool->size + sizeof(*pNode) + size;
}
taosThreadSpinUnlock(&pPool->lock);
if (pPool->isLock) {
taosThreadSpinUnlock(&pPool->lock);
}
return p;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册