/*-
* Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2008 Linpro AS
+ * Copyright (c) 2006-2009 Linpro AS
* All rights reserved.
*
* Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
#include "vcl.h"
#include "hash_slinger.h"
-static const char * const tmr_prefetch = "prefetch";
-static const char * const tmr_ttl = "ttl";
-
static pthread_t exp_thread;
static struct binheap *exp_heap;
static struct lock exp_mtx;
static VTAILQ_HEAD(,objcore) lru = VTAILQ_HEAD_INITIALIZER(lru);
+static const char *timer_what[] = {
+ [OC_T_TTL] = "TTL",
+ [OC_T_PREFETCH] = "Prefetch",
+};
+
/*
* This is a magic marker for the objects currently on the SIOP [look it up]
* so that other users of the object will not stumble trying to change the
{
struct objcore *oc;
double when;
- const char *what;
+ unsigned char what;
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
oc = o->objcore;
if (o->prefetch < 0.0) {
when = o->ttl + o->prefetch;
- what = tmr_prefetch;
+ what = OC_T_PREFETCH;
} else if (o->prefetch > 0.0) {
assert(o->prefetch <= o->ttl);
when = o->prefetch;
- what = tmr_prefetch;
+ what = OC_T_PREFETCH;
} else {
when = o->ttl + HSH_Grace(o->grace);
- what = tmr_ttl;
+ what = OC_T_TTL;
}
assert(!isnan(when));
oc->timer_what = what;
binheap_insert(exp_heap, oc);
assert(oc->timer_idx != BINHEAP_NOIDX);
VTAILQ_INSERT_TAIL(&lru, oc, lru_list);
- oc->on_lru = 1;
+ oc->flags |= OC_F_ONLRU;
Lck_Unlock(&exp_mtx);
}
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
if (Lck_Trylock(&exp_mtx))
return (retval);
- if (oc->on_lru) {
+ if (oc->flags & OC_F_ONLRU) {
VTAILQ_REMOVE(&lru, oc, lru_list);
VTAILQ_INSERT_TAIL(&lru, oc, lru_list);
VSL_stats->n_lru_moved++;
}
}
- assert(oc->on_lru);
+ assert(oc->flags & OC_F_ONLRU);
Lck_Unlock(&exp_mtx);
- WSL(&ww, SLT_ExpPick, 0, "%u %s", o->xid, oc->timer_what);
+ WSL(&ww, SLT_ExpPick, 0, "%u %s", o->xid,
+ timer_what[oc->timer_what]);
- if (oc->timer_what == tmr_prefetch) {
+ if (oc->timer_what == OC_T_PREFETCH) {
o->prefetch = 0.0;
sp->obj = o;
VCL_prefetch_method(sp);
assert(oc->timer_idx != BINHEAP_NOIDX);
Lck_Unlock(&exp_mtx);
} else {
- assert(oc->timer_what == tmr_ttl);
+ assert(oc->timer_what == OC_T_TTL);
sp->obj = o;
VCL_timeout_method(sp);
sp->obj = NULL;
Lck_Lock(&exp_mtx);
assert(oc->timer_idx == BINHEAP_NOIDX);
VTAILQ_REMOVE(&lru, o->objcore, lru_list);
- oc->on_lru = 0;
+ oc->flags &= ~OC_F_ONLRU;
VSL_stats->n_expired++;
Lck_Unlock(&exp_mtx);
HSH_Deref(&o);
* actions below.
*/
VTAILQ_REMOVE(&lru, oc, lru_list);
- oc->on_lru = 0;
+ oc->flags &= ~OC_F_ONLRU;
binheap_delete(exp_heap, oc->timer_idx);
assert(oc->timer_idx == BINHEAP_NOIDX);
VSL_stats->n_lru_nuked++;
binheap_insert(exp_heap, oc);
assert(oc->timer_idx != BINHEAP_NOIDX);
VTAILQ_INSERT_TAIL(&lru, oc, lru_list);
- oc->on_lru = 1;
+ oc->flags |= OC_F_ONLRU;
Lck_Unlock(&exp_mtx);
return (0);
}