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

more

上级 8d7e5385
...@@ -45,6 +45,7 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, bool alcNe ...@@ -45,6 +45,7 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, bool alcNe
static void tdbPCachePinPage(SPage *pPage); 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);
int tdbPCacheOpen(int pageSize, int cacheSize, int extraSize, SPCache **ppCache) { int tdbPCacheOpen(int pageSize, int cacheSize, int extraSize, SPCache **ppCache) {
SPCache *pCache; SPCache *pCache;
...@@ -89,8 +90,16 @@ void tdbPCacheFetchFinish(SPCache *pCache, SPage *pPage) { ...@@ -89,8 +90,16 @@ void tdbPCacheFetchFinish(SPCache *pCache, SPage *pPage) {
pPage->nRef++; // TODO: do we need atomic operation??? pPage->nRef++; // TODO: do we need atomic operation???
} }
void tdbPCacheRelease(SPage *pHdr) { void tdbPCacheRelease(SPage *pPage) {
// TODO pPage->nRef--;
if (pPage->nRef == 0) {
if (1 /*TODO: page still clean*/) {
tdbPCacheUnpinPage(pPage);
} else {
// TODO
ASSERT(0);
}
}
} }
static void tdbPCacheInitLock(SPCache *pCache) { pthread_mutex_init(&(pCache->mutex), NULL); } static void tdbPCacheInitLock(SPCache *pCache) { pthread_mutex_init(&(pCache->mutex), NULL); }
...@@ -167,6 +176,18 @@ static void tdbPCachePinPage(SPage *pPage) { ...@@ -167,6 +176,18 @@ static void tdbPCachePinPage(SPage *pPage) {
} }
} }
static void tdbPCacheUnpinPage(SPage *pPage) {
// Add current page to the LRU list
SPCache *pCache;
pPage->pLruPrev = &(pCache->lru);
pPage->pLruNext = pCache->lru.pLruNext;
pCache->lru.pLruNext->pLruPrev = pPage;
pCache->lru.pLruNext = pPage;
pCache->nRecyclable++;
}
static void tdbPCacheRemovePageFromHash(SPage *pPage) { static void tdbPCacheRemovePageFromHash(SPage *pPage) {
SPCache *pCache; SPCache *pCache;
SPage ** ppPage; SPage ** ppPage;
......
...@@ -44,7 +44,7 @@ int tdbPCacheOpen(int pageSize, int cacheSize, int extraSize, SPCache **ppCac ...@@ -44,7 +44,7 @@ int tdbPCacheOpen(int pageSize, int cacheSize, int extraSize, SPCache **ppCac
int tdbPCacheClose(SPCache *pCache); int tdbPCacheClose(SPCache *pCache);
SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, bool alcNewPage); SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, bool alcNewPage);
void tdbPCacheFetchFinish(SPCache *pCache, SPage *pPage); void tdbPCacheFetchFinish(SPCache *pCache, SPage *pPage);
void tdbPCacheRelease(SPage *pHdr); void tdbPCacheRelease(SPage *pPage);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册