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

more TDB

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