提交 ed06d822 编写于 作者: H Hongze Cheng

refact

上级 a00243ca
......@@ -18,7 +18,7 @@
int tdbMPoolOpen(TDB_MPOOL **mpp, uint64_t cachesize, pgsize_t pgsize) {
TDB_MPOOL *mp;
size_t tsize;
MP_PAGE * pagep;
pg_t * pagep;
// check parameters
if (!TDB_IS_PGSIZE_VLD(pgsize)) {
......@@ -37,7 +37,7 @@ int tdbMPoolOpen(TDB_MPOOL **mpp, uint64_t cachesize, pgsize_t pgsize) {
mp->cachesize = cachesize;
mp->pgsize = pgsize;
mp->npages = cachesize / pgsize;
mp->pages = (MP_PAGE *)calloc(mp->npages, MP_PAGE_SIZE(pgsize));
mp->pages = (pg_t *)calloc(mp->npages, MP_PAGE_SIZE(pgsize));
if (mp->pages == NULL) {
tdbError("failed to malloc memory pool pages");
free(mp);
......@@ -47,7 +47,7 @@ int tdbMPoolOpen(TDB_MPOOL **mpp, uint64_t cachesize, pgsize_t pgsize) {
TD_DLIST_INIT(&(mp->freeList));
mp->nbucket = mp->npages;
mp->hashtab = (MP_PAGE_LIST *)calloc(mp->nbucket, sizeof(MP_PAGE_LIST));
mp->hashtab = (pg_list_t *)calloc(mp->nbucket, sizeof(pg_list_t));
if (mp->hashtab == NULL) {
tdbError("failed to malloc memory pool hash table");
free(mp->pages);
......@@ -56,7 +56,7 @@ int tdbMPoolOpen(TDB_MPOOL **mpp, uint64_t cachesize, pgsize_t pgsize) {
}
for (int i = 0; i < mp->npages; i++) {
pagep = (MP_PAGE *)MP_PAGE_AT(mp, i);
pagep = (pg_t *)MP_PAGE_AT(mp, i);
TD_DLIST_APPEND(&mp->freeList, pagep);
}
......
......@@ -18,6 +18,7 @@
#include "os.h"
#include "tlist.h"
#include "tlockfree.h"
#ifdef __cplusplus
extern "C" {
......
......@@ -26,28 +26,27 @@ extern "C" {
typedef struct TDB_MPOOL TDB_MPOOL;
typedef struct TDB_MPFILE TDB_MPFILE;
typedef struct MP_PAGE {
// SRWLatch rwLatch;
pgid_t mpgid;
uint8_t dirty;
uint8_t fileid[TDB_FILE_UID_LEN];
int32_t pinRef;
TD_DLIST_NODE(MP_PAGE);
typedef struct pg_t {
SRWLatch rwLatch;
pgid_t mpgid;
uint8_t dirty;
int32_t pinRef;
TD_DLIST_NODE(pg_t);
char *page[];
} MP_PAGE;
} pg_t;
#define MP_PAGE_SIZE(pgsize) (sizeof(MP_PAGE) + (pgsize))
#define MP_PAGE_SIZE(pgsize) (sizeof(pg_t) + (pgsize))
typedef TD_DLIST(MP_PAGE) MP_PAGE_LIST;
typedef TD_DLIST(pg_t) pg_list_t;
struct TDB_MPOOL {
int64_t cachesize;
pgsize_t pgsize;
int32_t npages;
MP_PAGE * pages;
MP_PAGE_LIST freeList;
int64_t cachesize;
pgsize_t pgsize;
int32_t npages;
pg_t * pages;
pg_list_t freeList;
// Hash<pgid_t, frame_id_t>
int32_t nbucket;
MP_PAGE_LIST *hashtab;
int32_t nbucket;
pg_list_t *hashtab;
// TODO: TD_DLIST(TD_MPFILE) mpfList; // MPFILE registered on this memory pool
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册