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

more

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