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