This commit is contained in:
Hongze Cheng 2021-12-13 20:41:03 +08:00
parent 0eff683d18
commit 04c83f497d
4 changed files with 26 additions and 30 deletions

View File

@ -66,8 +66,6 @@ extern "C" {
(l)->neles_ += 1; (l)->neles_ += 1;
#define tlistPop(l, n) \ #define tlistPop(l, n) \
({ \
if ((n)) { \
if ((l)->head_ == (n)) { \ if ((l)->head_ == (n)) { \
(l)->head_ = (n)->next_; \ (l)->head_ = (n)->next_; \
} \ } \
@ -81,14 +79,7 @@ extern "C" {
(n)->next_->prev_ = (n)->prev_; \ (n)->next_->prev_ = (n)->prev_; \
} \ } \
(l)->neles_ -= 1; \ (l)->neles_ -= 1; \
(n)->prev_ = (n)->next_ = NULL; \ (n)->prev_ = (n)->next_ = NULL;
} \
(n); \
})
#define tlistPopHead(l) tlistPop(l, (l)->head_)
#define tlistPopTail(l) tlistPop(l, (l)->tail_)
// List iterator // List iterator
#define TD_LIST_FITER 0 #define TD_LIST_FITER 0

View File

@ -43,9 +43,10 @@ SVMemAllocator *vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize) {
void vmaDestroy(SVMemAllocator *pVMA) { void vmaDestroy(SVMemAllocator *pVMA) {
if (pVMA) { if (pVMA) {
while (true) { while (true) {
SVArenaNode *pNode = tlistPopTail(&(pVMA->nlist)); SVArenaNode *pNode = tlistTail(&(pVMA->nlist));
if (pNode) { if (pNode) {
tlistPop(&(pVMA->nlist), pNode);
vArenaNodeFree(pNode); vArenaNodeFree(pNode);
} else { } else {
break; break;
@ -58,7 +59,8 @@ void vmaDestroy(SVMemAllocator *pVMA) {
void vmaReset(SVMemAllocator *pVMA) { void vmaReset(SVMemAllocator *pVMA) {
while (tlistNEles(&(pVMA->nlist)) > 1) { while (tlistNEles(&(pVMA->nlist)) > 1) {
SVArenaNode *pNode = tlistPopTail(&(pVMA->nlist)); SVArenaNode *pNode = tlistTail(&(pVMA->nlist));
tlistPop(&(pVMA->nlist), pNode);
vArenaNodeFree(pNode); vArenaNodeFree(pNode);
} }

View File

@ -61,14 +61,16 @@ void vnodeCloseBufPool(SVnode *pVnode) {
vmaDestroy(pVnode->pBufPool->inuse); vmaDestroy(pVnode->pBufPool->inuse);
while (true) { while (true) {
SVMemAllocator *pVMA = tlistPopHead(&(pVnode->pBufPool->incycle)); SVMemAllocator *pVMA = tlistHead(&(pVnode->pBufPool->incycle));
if (pVMA == NULL) break; if (pVMA == NULL) break;
tlistPop(&(pVnode->pBufPool->incycle), pVMA);
vmaDestroy(pVMA); vmaDestroy(pVMA);
} }
while (true) { while (true) {
SVMemAllocator *pVMA = tlistPopHead(&(pVnode->pBufPool->free)); SVMemAllocator *pVMA = tlistHead(&(pVnode->pBufPool->free));
if (pVMA == NULL) break; if (pVMA == NULL) break;
tlistPop(&(pVnode->pBufPool->free), pVMA);
vmaDestroy(pVMA); vmaDestroy(pVMA);
} }
@ -83,8 +85,9 @@ void *vnodeMalloc(SVnode *pVnode, uint64_t size) {
if (pBufPool->inuse == NULL) { if (pBufPool->inuse == NULL) {
while (true) { while (true) {
// TODO: add sem_wait and sem_post // TODO: add sem_wait and sem_post
pBufPool->inuse = tlistPopHead(&(pBufPool->free)); pBufPool->inuse = tlistHead(&(pBufPool->free));
if (pBufPool->inuse) { if (pBufPool->inuse) {
tlistPop(&(pBufPool->free), pBufPool->inuse);
break; break;
} }
} }

View File

@ -131,7 +131,7 @@ TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) {
{ {
// Create some child tables // Create some child tables
int ntables = 1000000; int ntables = 1000;
int batch = 10; int batch = 10;
for (int i = 0; i < ntables / batch; i++) { for (int i = 0; i < ntables / batch; i++) {
SArray *pMsgs = (SArray *)taosArrayInit(batch, sizeof(SRpcMsg *)); SArray *pMsgs = (SArray *)taosArrayInit(batch, sizeof(SRpcMsg *));