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

refact

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