提交 69352daf 编写于 作者: H Hongze Cheng

more TDB

上级 d907e448
......@@ -45,6 +45,8 @@ static void tdbPCachePinPage(SPage *pPage);
static void tdbPCacheRemovePageFromHash(SPage *pPage);
static void tdbPCacheAddPageToHash(SPage *pPage);
static void tdbPCacheUnpinPage(SPage *pPage);
static void *tdbOsMalloc(void *arg, size_t size);
static void tdbOsFree(void *arg, void *ptr);
int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) {
SPCache *pCache;
......@@ -235,6 +237,7 @@ static int tdbPCacheOpenImpl(SPCache *pCache) {
SPage *pPage;
u8 *pPtr;
int tsize;
int ret;
tdbPCacheInitLock(pCache);
......@@ -242,16 +245,12 @@ static int tdbPCacheOpenImpl(SPCache *pCache) {
pCache->nFree = 0;
pCache->pFree = NULL;
for (int i = 0; i < pCache->cacheSize; i++) {
tsize = pCache->pageSize + sizeof(SPage);
pPtr = (u8 *)calloc(1, tsize);
if (pPtr == NULL) {
// TODO
ret = tdbPageCreate(pCache->pageSize, &pPage, tdbOsMalloc, NULL);
if (ret < 0) {
// TODO: handle error
return -1;
}
pPage = (SPage *)(&(pPtr[pCache->pageSize]));
TDB_INIT_PAGE_LOCK(pPage);
pPage->pData = (void *)pPtr;
// pPage->pgid = 0;
pPage->isAnchor = 0;
pPage->isLocalPage = 1;
......@@ -285,4 +284,14 @@ static int tdbPCacheOpenImpl(SPCache *pCache) {
return 0;
}
int tdbPCacheGetPageSize(SPCache *pCache) { return pCache->pageSize; }
\ No newline at end of file
int tdbPCacheGetPageSize(SPCache *pCache) { return pCache->pageSize; }
static void *tdbOsMalloc(void *arg, size_t size) {
void *ptr;
ptr = malloc(size);
return ptr;
}
static void tdbOsFree(void *arg, void *ptr) { free(ptr); }
\ No newline at end of file
......@@ -41,11 +41,11 @@ int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t)
return 0;
}
int tdbPageDestroy(SPage *pPage, void (*xFree)(void *)) {
int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg) {
u8 *ptr;
ptr = pPage->pData;
(*xFree)(ptr);
(*xFree)(arg, ptr);
return 0;
}
......
......@@ -95,7 +95,7 @@ struct SPage {
// APIs
int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t), void *arg);
int tdbPageDestroy(SPage *pPage, void (*xFree)(void *));
int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg);
int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell);
int tdbPageDropCell(SPage *pPage, int idx);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册