Port for compatiblity with new API.

This commit is contained in:
Sears Russell 2007-03-13 08:31:15 +00:00
parent 00cf6b8a49
commit 11da78e46b

View file

@ -16,6 +16,9 @@ typedef struct lru {
uint64_t now; uint64_t now;
struct LH_ENTRY(table) * hash; struct LH_ENTRY(table) * hash;
struct RB_ENTRY(tree) * lru; struct RB_ENTRY(tree) * lru;
void * (*getNode)(void * page, void * conf);
void (*setNode)(void * page, void * n, void * conf);
void * conf;
} lru; } lru;
int cmp(const void * ap, const void * bp, const void * ignored) { int cmp(const void * ap, const void * bp, const void * ignored) {
@ -39,9 +42,9 @@ static void lruDeinit(replacementPolicy* r) {
/** @todo handle clock wraps properly! */ /** @todo handle clock wraps properly! */
static void lruHit(replacementPolicy* r, int id) { static void lruHit(replacementPolicy* r, void * p) {
lru * l = r->impl; lru * l = r->impl;
entry * e = LH_ENTRY(find)(l->hash, &id, sizeof(int)); entry * e = l->getNode(p, l->conf);
assert(e); assert(e);
entry * old = (entry * ) RB_ENTRY(delete)(e, l->lru); entry * old = (entry * ) RB_ENTRY(delete)(e, l->lru);
assert(e == old); assert(e == old);
@ -55,9 +58,9 @@ static void * lruGetStale(replacementPolicy* r) {
entry * e = (entry * ) RB_ENTRY(min)(l->lru); entry * e = (entry * ) RB_ENTRY(min)(l->lru);
return e ? e->value : 0; return e ? e->value : 0;
} }
static void* lruRemove(replacementPolicy* r, int id) { static void* lruRemove(replacementPolicy* r, void * p) {
lru * l = r->impl; lru * l = r->impl;
entry * e = LH_ENTRY(remove)(l->hash, &id, sizeof(int)); entry * e = l->getNode(p, l->conf);
assert(e); assert(e);
entry * old = (entry *) RB_ENTRY(delete)(e, l->lru); entry * old = (entry *) RB_ENTRY(delete)(e, l->lru);
assert(old == e); assert(old == e);
@ -65,15 +68,13 @@ static void* lruRemove(replacementPolicy* r, int id) {
free(e); free(e);
return ret; return ret;
} }
static void lruInsert(replacementPolicy* r, int id, void * p) { static void lruInsert(replacementPolicy* r, void * p) {
lru * l = r->impl; lru * l = r->impl;
entry * e = LH_ENTRY(find)(l->hash, &id, sizeof(int)); entry * e = malloc(sizeof(entry));
assert(!e);
e = malloc(sizeof(entry));
e->value = p; e->value = p;
e->clock = l->now; e->clock = l->now;
l->now++; l->now++;
LH_ENTRY(insert)(l->hash, &id, sizeof(int), e); l->setNode(p, l->conf, e);
entry * old = (entry *) RB_ENTRY(search)(e, l->lru); entry * old = (entry *) RB_ENTRY(search)(e, l->lru);
assert(e == old); assert(e == old);
} }