提交 5eb04e9f 编写于 作者: H Hongze Cheng

more TDB

上级 0dcb97fd
......@@ -39,8 +39,10 @@ int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t)
pPage->pageSize = pageSize;
if (pageSize < 65536) {
pPage->szOffset = 2;
pPage->szPageHdr = sizeof(SPageHdr);
} else {
pPage->szOffset = 3;
pPage->szPageHdr = sizeof(SLPageHdr);
}
TDB_INIT_PAGE_LOCK(pPage);
......@@ -97,6 +99,7 @@ static int tdbPageAllocate(SPage *pPage, int size, SCell **ppCell) {
} else {
}
*ppCell = pCell;
return 0;
}
......
......@@ -22,7 +22,7 @@ extern "C" {
typedef u8 SCell;
// Page header
// Page header (pageSize < 65536 (64K))
typedef struct __attribute__((__packed__)) {
u16 flags;
u16 nCells;
......@@ -49,6 +49,7 @@ struct SPage {
u8 *pData;
int pageSize;
u8 szOffset;
u8 szPageHdr;
pthread_spinlock_t lock;
// Fields below used by pager and am
SPageHdr *pPageHdr;
......@@ -69,6 +70,11 @@ struct SPage {
};
// Macros
/* For small page */
/* For large page */
/* For page */
#define TDB_PAGE_CELL_OFFSET_AT(pPage, idx) \
(((pPage)->szOffset == 2) ? ((u16 *)((pPage)->aCellIdx))[idx] \
: ((pPage)->aCellIdx[idx * 3] * 65536 + *(u16 *)((pPage)->aCellIdx + idx * 3 + 1)))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册