diff options
Diffstat (limited to 'src/cache.c')
-rw-r--r-- | src/cache.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/cache.c b/src/cache.c index f8a2026..19c5a92 100644 --- a/src/cache.c +++ b/src/cache.c @@ -8,8 +8,8 @@ #include <rin/definitions.h> #include <rin/diagnostic.h> #include "defs.h" - -static int cache_rewind(struct stream * const in); +#include "stream.h" +#include "cache.h" int cache_create(struct stream * const in) { @@ -34,6 +34,7 @@ int cache_populate(struct stream * const in) struct entry_l *tmp; try(in->settings->access != cached, err, EINVAL, "cannot populate cache: stream is uncached"); + try(!in->cache, err, EINVAL, "stream has no cache allocated"); /* if reading a a randstream, fall back to the one-element-at-a-time mode */ if (in->type == stream_randread) { @@ -48,7 +49,7 @@ int cache_populate(struct stream * const in) } } } else if (in->type == stream_in) { - try(1, err, ENOSYS, "populating cache from file is a TODO"); + try_s((ret == stream_readfile(in)), err); } else { try(1, err, EINVAL, "cannot populate a non-reading stream cache"); } @@ -94,7 +95,7 @@ int cache_block_copy(struct stream const * const src, struct stream * const dest try(src->settings->access != cached || dest->settings->access != cached, err, EINVAL, "cannot cache-copy between uncached streams"); try(!src->cache, err, EINVAL, "no cache to transfer"); - try(src->n > dest->settings->to, err, EINVAL, "invalid copy size"); + try(src->n < dest->settings->to, err, EINVAL, "invalid copy size"); try(!dest->cache, err, EINVAL, "no cache to transfer to"); memcpy(dest->cache, src->cache_a + dest->settings->ss, (dest->settings->to - dest->settings->ss) * dest->settings->stride); @@ -135,13 +136,13 @@ int cache_block_split(struct stream * const src, struct stream * const A, struct A->n = src->n / 2; B->n = src->n / 2 + (src->n & 1ul); A->index = B->index = 0; - A->parentid = B->parentid = random(); /* generate random parent ID that needs to match between children */ - A->type = B->type = stream_invalid; /* disallow any stream operations other than split/merge on children */ + A->type = B->type = stream_cache; /* disallow any stream operations other than split/merge on children */ A->fd = B->fd = -1; /* if we're splitting, these are for holding cache only */ /* we only care about these three functions for these temporary streams */ A->get_next_element_cache = B->get_next_element_cache = src->get_next_element_cache; A->place_next_element_cache = B->place_next_element_cache = src->place_next_element_cache; A->split = B->split = src->split; + A->rewind = B->rewind = src->rewind; tmp_settings = *src->settings; A->settings = B->settings = &tmp_settings; @@ -158,7 +159,7 @@ int cache_block_split(struct stream * const src, struct stream * const A, struct try_s((ret = cache_create(B)), err); try_s((ret = cache_block_copy(src, B)), err); - A->settings = B->settings = &tmp_settings; + A->settings = B->settings = src->settings; err: return ret; |