From 4d41f0d5e871b86b8f56339a99cfb1b80fbb420c Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sun, 12 Feb 2023 01:36:13 +0000 Subject: Deglobalize s6-ps Signed-off-by: Laurent Bercot --- src/libs6ps/s6ps_cache.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/libs6ps/s6ps_cache.c (limited to 'src/libs6ps/s6ps_cache.c') diff --git a/src/libs6ps/s6ps_cache.c b/src/libs6ps/s6ps_cache.c new file mode 100644 index 0000000..0ef438a --- /dev/null +++ b/src/libs6ps/s6ps_cache.c @@ -0,0 +1,34 @@ +/* ISC license. */ + +#include + +#include +#include + +#include "s6ps.h" +#include "s6ps-internal.h" + +static void *left_dtok (unsigned int d, void *x) +{ + return (void *)&genalloc_s(dius_t, (genalloc *)x)[d].left ; +} + +int s6ps_uint32_cmp (void const *a, void const *b, void *x) +{ + uint32_t aa = *(uint32_t *)a ; + uint32_t bb = *(uint32_t *)b ; + (void)x ; + return (aa < bb) ? -1 : (aa > bb) ; +} + +int s6ps_cache_init (s6ps_cache_t *cache) +{ + avltree_init(&cache->tree, 5, 3, 8, &left_dtok, &s6ps_uint32_cmp, &cache->index) ; + return 1 ; +} + +void s6ps_cache_finish (s6ps_cache_t *cache) +{ + avltree_free(&cache->tree) ; + genalloc_free(dius_t, &cache->index) ; +} -- cgit 1.4.1