summaryrefslogtreecommitdiff
path: root/src/libdisfluid/disfluid-cache-group.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/libdisfluid/disfluid-cache-group.h')
-rw-r--r--src/libdisfluid/disfluid-cache-group.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/libdisfluid/disfluid-cache-group.h b/src/libdisfluid/disfluid-cache-group.h
index 6f6b386..b0a94af 100644
--- a/src/libdisfluid/disfluid-cache-group.h
+++ b/src/libdisfluid/disfluid-cache-group.h
@@ -13,6 +13,9 @@ MAYBE_UNUSED static int
ao_cache_group_push (int fd, size_t *offset,
size_t n_entries, const size_t *entry_offsets);
+MAYBE_UNUSED static int
+ao_cache_group_invalidate (int fd, size_t offset, size_t *invalidated_offset);
+
# include "disfluid-append-only-file.h"
# include "safe-alloc.h"
@@ -127,4 +130,48 @@ ao_cache_group_push (int fd,
return ao_file_push_data (fd, header_desc, offset);
}
+MAYBE_UNUSED static int
+ao_cache_group_invalidate (int fd, size_t offset, size_t *invalidated_offset)
+{
+ size_t n_entries = 42;
+ size_t *offsets = NULL;
+ int error = ao_cache_group_read (fd, offset, &n_entries, &offsets);
+ if (error != 0)
+ {
+ FREE (offsets);
+ return -1;
+ }
+ bool changed = false;
+ for (size_t i = 0; i < n_entries; i++)
+ {
+ size_t old_offset = offsets[i];
+ size_t new_offset = 42;
+ if (ao_cache_entry_invalidate (fd, old_offset, &new_offset) < 0)
+ {
+ FREE (offsets);
+ return -1;
+ }
+ if (old_offset != new_offset)
+ {
+ changed = true;
+ }
+ offsets[i] = new_offset;
+ }
+ if (changed)
+ {
+ if (ao_cache_group_push (fd, invalidated_offset, n_entries, offsets) <
+ 0)
+ {
+ FREE (offsets);
+ return -1;
+ }
+ }
+ else
+ {
+ *invalidated_offset = offset;
+ }
+ FREE (offsets);
+ return 0;
+}
+
#endif /* DISFLUID_DISFLUID_CACHE_GROUP_INCLUDED */