This commit is contained in:
hzcheng 2020-03-24 11:01:04 +08:00
parent 1b601eee75
commit eed1d76b3f
1 changed files with 12 additions and 7 deletions

View File

@ -17,8 +17,9 @@
#include "tsdb.h" #include "tsdb.h"
#include "tsdbCache.h" #include "tsdbCache.h"
static int tsdbAllocBlockFromPool(STsdbCache *pCache); static int tsdbAllocBlockFromPool(STsdbCache *pCache);
static void tsdbFreeBlockList(SCacheMem *mem); static void tsdbFreeBlockList(SList *list);
static void tsdbFreeCacheMem(SCacheMem *mem);
STsdbCache *tsdbInitCache(int maxBytes, int cacheBlockSize, tsdb_repo_t *pRepo) { STsdbCache *tsdbInitCache(int maxBytes, int cacheBlockSize, tsdb_repo_t *pRepo) {
STsdbCache *pCache = (STsdbCache *)calloc(1, sizeof(STsdbCache)); STsdbCache *pCache = (STsdbCache *)calloc(1, sizeof(STsdbCache));
@ -60,8 +61,8 @@ _err:
} }
void tsdbFreeCache(STsdbCache *pCache) { void tsdbFreeCache(STsdbCache *pCache) {
tsdbFreeBlockList(pCache->imem); tsdbFreeCacheMem(pCache->imem);
tsdbFreeBlockList(pCache->mem); tsdbFreeCacheMem(pCache->mem);
tsdbFreeBlockList(pCache->pool.memPool); tsdbFreeBlockList(pCache->pool.memPool);
free(pCache); free(pCache);
} }
@ -90,9 +91,7 @@ void *tsdbAllocFromCache(STsdbCache *pCache, int bytes, TSKEY key) {
return ptr; return ptr;
} }
static void tsdbFreeBlockList(SCacheMem *mem) { static void tsdbFreeBlockList(SList *list) {
if (mem == NULL) return;
SList * list = mem->list;
SListNode * node = NULL; SListNode * node = NULL;
STsdbCacheBlock *pBlock = NULL; STsdbCacheBlock *pBlock = NULL;
while ((node = tdListPopHead(list)) != NULL) { while ((node = tdListPopHead(list)) != NULL) {
@ -101,6 +100,12 @@ static void tsdbFreeBlockList(SCacheMem *mem) {
listNodeFree(node); listNodeFree(node);
} }
tdListFree(list); tdListFree(list);
}
static void tsdbFreeCacheMem(SCacheMem *mem) {
if (mem == NULL) return;
SList *list = mem->list;
tsdbFreeBlockList(list);
free(mem); free(mem);
} }