diff --git a/include/util/tdlist.h b/include/util/tdlist.h index 757b404ad6..0f341801e0 100644 --- a/include/util/tdlist.h +++ b/include/util/tdlist.h @@ -65,30 +65,21 @@ extern "C" { } \ (l)->neles_ += 1; -#define tlistPop(l, n) \ - ({ \ - if ((n)) { \ - if ((l)->head_ == (n)) { \ - (l)->head_ = (n)->next_; \ - } \ - if ((l)->tail_ == (n)) { \ - (l)->tail_ = (n)->prev_; \ - } \ - if ((n)->prev_ != NULL) { \ - (n)->prev_->next_ = (n)->next_; \ - } \ - if ((n)->next_ != NULL) { \ - (n)->next_->prev_ = (n)->prev_; \ - } \ - (l)->neles_ -= 1; \ - (n)->prev_ = (n)->next_ = NULL; \ - } \ - (n); \ - }) - -#define tlistPopHead(l) tlistPop(l, (l)->head_) - -#define tlistPopTail(l) tlistPop(l, (l)->tail_) +#define tlistPop(l, n) \ + if ((l)->head_ == (n)) { \ + (l)->head_ = (n)->next_; \ + } \ + if ((l)->tail_ == (n)) { \ + (l)->tail_ = (n)->prev_; \ + } \ + if ((n)->prev_ != NULL) { \ + (n)->prev_->next_ = (n)->next_; \ + } \ + if ((n)->next_ != NULL) { \ + (n)->next_->prev_ = (n)->prev_; \ + } \ + (l)->neles_ -= 1; \ + (n)->prev_ = (n)->next_ = NULL; // List iterator #define TD_LIST_FITER 0 diff --git a/source/dnode/vnode/impl/src/vnodeArenaMAImpl.c b/source/dnode/vnode/impl/src/vnodeArenaMAImpl.c index 532c2dad8e..748808a9fd 100644 --- a/source/dnode/vnode/impl/src/vnodeArenaMAImpl.c +++ b/source/dnode/vnode/impl/src/vnodeArenaMAImpl.c @@ -43,9 +43,10 @@ SVMemAllocator *vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize) { void vmaDestroy(SVMemAllocator *pVMA) { if (pVMA) { while (true) { - SVArenaNode *pNode = tlistPopTail(&(pVMA->nlist)); + SVArenaNode *pNode = tlistTail(&(pVMA->nlist)); if (pNode) { + tlistPop(&(pVMA->nlist), pNode); vArenaNodeFree(pNode); } else { break; @@ -58,7 +59,8 @@ void vmaDestroy(SVMemAllocator *pVMA) { void vmaReset(SVMemAllocator *pVMA) { while (tlistNEles(&(pVMA->nlist)) > 1) { - SVArenaNode *pNode = tlistPopTail(&(pVMA->nlist)); + SVArenaNode *pNode = tlistTail(&(pVMA->nlist)); + tlistPop(&(pVMA->nlist), pNode); vArenaNodeFree(pNode); } diff --git a/source/dnode/vnode/impl/src/vnodeBufferPool.c b/source/dnode/vnode/impl/src/vnodeBufferPool.c index fe15e9ebff..d5fcdf91e3 100644 --- a/source/dnode/vnode/impl/src/vnodeBufferPool.c +++ b/source/dnode/vnode/impl/src/vnodeBufferPool.c @@ -61,14 +61,16 @@ void vnodeCloseBufPool(SVnode *pVnode) { vmaDestroy(pVnode->pBufPool->inuse); while (true) { - SVMemAllocator *pVMA = tlistPopHead(&(pVnode->pBufPool->incycle)); + SVMemAllocator *pVMA = tlistHead(&(pVnode->pBufPool->incycle)); if (pVMA == NULL) break; + tlistPop(&(pVnode->pBufPool->incycle), pVMA); vmaDestroy(pVMA); } while (true) { - SVMemAllocator *pVMA = tlistPopHead(&(pVnode->pBufPool->free)); + SVMemAllocator *pVMA = tlistHead(&(pVnode->pBufPool->free)); if (pVMA == NULL) break; + tlistPop(&(pVnode->pBufPool->free), pVMA); vmaDestroy(pVMA); } @@ -83,8 +85,9 @@ void *vnodeMalloc(SVnode *pVnode, uint64_t size) { if (pBufPool->inuse == NULL) { while (true) { // TODO: add sem_wait and sem_post - pBufPool->inuse = tlistPopHead(&(pBufPool->free)); + pBufPool->inuse = tlistHead(&(pBufPool->free)); if (pBufPool->inuse) { + tlistPop(&(pBufPool->free), pBufPool->inuse); break; } } diff --git a/source/dnode/vnode/impl/test/vnodeApiTests.cpp b/source/dnode/vnode/impl/test/vnodeApiTests.cpp index ac2ccbc132..ec7e40dc0d 100644 --- a/source/dnode/vnode/impl/test/vnodeApiTests.cpp +++ b/source/dnode/vnode/impl/test/vnodeApiTests.cpp @@ -131,7 +131,7 @@ TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) { { // Create some child tables - int ntables = 1000000; + int ntables = 1000; int batch = 10; for (int i = 0; i < ntables / batch; i++) { SArray *pMsgs = (SArray *)taosArrayInit(batch, sizeof(SRpcMsg *));