diff options
author | 2021-02-11 08:17:03 +0200 | |
---|---|---|
committer | 2021-02-11 08:17:03 +0200 | |
commit | 4a14ab7ab48e3fd591dde33d59c6d29fc39f1c5d (patch) | |
tree | 8d4e527e4a8ad76819e3baa1b89441eeb1081f15 /src/cache.c | |
parent | 41efe7b8f9f67d5956ab677f3631478c48114ac1 (diff) | |
download | algos-ld1-4a14ab7ab48e3fd591dde33d59c6d29fc39f1c5d.tar.gz algos-ld1-4a14ab7ab48e3fd591dde33d59c6d29fc39f1c5d.tar.bz2 algos-ld1-4a14ab7ab48e3fd591dde33d59c6d29fc39f1c5d.zip |
continue the overhaul.
we can finally create a basic array input data file too!
Signed-off-by: Gediminas Jakutis <gediminas@varciai.lt>
Diffstat (limited to 'src/cache.c')
-rw-r--r-- | src/cache.c | 63 |
1 files changed, 26 insertions, 37 deletions
diff --git a/src/cache.c b/src/cache.c index 4fe0c46..bb41689 100644 --- a/src/cache.c +++ b/src/cache.c @@ -9,13 +9,13 @@ #include <rin/diagnostic.h> #include "defs.h" -int cache_create(struct stream * const in, const struct settings * const restrict s) +int cache_create(struct stream * const in) { int ret = 0; void *cache; - try(!in->cached, err, EINVAL, "cannot create cache: stream is uncached"); - try(!(cache = calloc(in->n, s->stride)), err, ENOMEM, "out of memory"); + try(in->settings->access != cached, err, EINVAL, "cannot create cache: stream is uncached"); + try(!(cache = calloc(in->n, in->settings->stride)), err, ENOMEM, "out of memory"); /* yeah... */ in->cache = cache; @@ -31,33 +31,22 @@ int cache_populate(struct stream * const in) size_t i; struct entry_l *tmp; - try(!in->cached, err, EINVAL, "cannot populate cache: stream is uncached"); - - for (i = 0; i < in->n && !ret; ++i) { - errno = 0; - tmp = in->get_next_element_direct(in); - if (tmp) { /* non-cache reads CAN fail */ - put(in, tmp); - } else { - ret = errno; - break; + try(in->settings->access != cached, err, EINVAL, "cannot populate cache: stream is uncached"); + + /* if reading a chardev, fall back to the one-element-at-a-time mode */ + if (in->type == stream_chardev) { + for (i = 0; i < in->n && !ret; ++i) { + errno = 0; + tmp = in->get_next_element_direct(in); + if (tmp) { /* non-cache reads CAN fail */ + put(in, tmp); + } else { + ret = errno; + break; + } } - } - -err: - return ret; -} - -int cache_flush(struct stream * const in) -{ - int ret = 0; - struct entry_l *tmp; - - try(!in->cached, err, EINVAL, "no cache to flush: stream is uncached"); - try(in->out != 1, err, EINVAL, "cannot flush a non-output cache"); - - while((tmp = get(in))) { - in->place_next_element_direct(in, tmp); + } else { + /* TODO */ } err: @@ -68,7 +57,7 @@ int cache_destroy(struct stream * const in) { int ret = 0; - try(!in->cached, err, EINVAL, "no cache to destroy: stream uncached"); + try(in->settings->access != cached, err, EINVAL, "cannot destroy cache: stream is uncached"); free(in->cache); in->cache_l = NULL; in->cache_a = NULL; @@ -81,7 +70,7 @@ int cache_transfer(struct stream * const src, struct stream * const dest) { int ret = 0; - try(!src->cached || !dest->cached, err, EINVAL, "cannot transfer caches of uncached streams"); + try(src->settings->access != cached || dest->settings->access != cached, err, EINVAL, "cannot transfer caches of uncached streams"); try(!src->cache, err, EINVAL, "no cache to transfer"); try(dest->cache, err, EINVAL, "cannot transfer cache: recipient cache already exists"); @@ -95,28 +84,28 @@ err: return ret; } -int cache_block_copy(struct stream const * const src, struct stream * const dest, const struct settings * const s) +int cache_block_copy(struct stream const * const src, struct stream * const dest) { int ret = 0; - try(!src->cached || !dest->cached, err, EINVAL, "cannot cache-copy between uncached streams"); + 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 < s->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 + s->ss, (s->to - s->ss) * s->stride); + memcpy(dest->cache, src->cache_a + dest->settings->ss, (dest->settings->to - dest->settings->ss) * dest->settings->stride); + dest->n = dest->settings->to - dest->settings->ss; err: return ret; } -int cache_list_copy(struct stream const * const src, struct stream * const dest, const struct settings * const s) +int cache_list_copy(struct stream const * const src, struct stream * const dest) { int ret = ENOSYS; (void) src; (void) dest; - (void) s; rin_warn("stub!"); |