my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
#include "cache.h"
#include "common.h"
struct cache_op {
u_int8_t key[CACHE_KEY];
struct cache_nest *nest;
u_int8_t obj_nest;
u_int32_t obj_offset;
u_int16_t obj_length:
void *mmap_addr;
// for linked lists
struct cache_op *next;
};
int _cache_op_get (struct cache_op **op_info, struct cache *cache_info, u_int8_t key[CACHE_KEY_SIZE]) {
struct cache_op *op;
// first, search the read queue
for (op = cache_info->rop_list; op; op = op->next) {
if (memcmp(op->key, key, CACHE_KEY_SIZE))
break;
}
if (!op) {
// look for in-progress write ops
for (int i = 0; i < CACHE_NEST_COUNT; i++) {
op = ctx->nests[i].op;
if (op && memcmp(op->key, key, CACHE_KEY_SIZE))
break;
}
if (!op) {
// look for queued write ops
for (op = cache_info->wop_list; op; op = op->next) {
if (memcmp(op->key, key, CACHE_KEY_SIZE))
break;
}
}
if (!op) {
// alloc a new op struct
op = calloc(1, sizeof(*op));
// look it up in the index
if (_cache_index_find(cache_info->index, key, &op->nest, &op->obj_offset, &op->obj_length) == 0) {
// found it in some nest
// XXX: enter read list and start read
} else {
// not in the cache, try and find an unused nest to write it
if (_cache_nest_assign_op(cache_info, op, &op->nest) == 0) {
// excellent, we can start writing directly
// XXX: start writing
} else {
// enter the wait queue...
// XXX: enter write queue
}
}
} else {
// XXX: start reading
}
}