]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib/cache/top.h: avoid issues with inclusion in C++
authorVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 5 Aug 2025 08:59:57 +0000 (10:59 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Wed, 13 Aug 2025 11:42:29 +0000 (13:42 +0200)
kru.h would be a bit complicated to adapt, so let's avoid it.
I don't think uint32_t as return price will be an issue,
though we might... e.g. add a static_assert() into top.c

lib/cache/top.h
utils/cache_gc/categories.c

index 9917d9fc5b3feedf761f8206202ef9c22ac95418..91e2d6dc03b6dd130c2556f70d942e1a5503f549 100644 (file)
@@ -18,8 +18,8 @@
 /// but there was no need to remove the (possibly expired) entry from the cache.
 
 #pragma once
+#include <stdalign.h>
 #include "lib/mmapped.h"
-#include "lib/kru.h"
 
 /// Data related to open cache.
 struct kr_cache_top {
@@ -33,7 +33,7 @@ struct top_data {
        uint32_t version;
        uint32_t base_price_norm;
        uint32_t max_decay;
-       _Alignas(64) uint8_t kru[];
+       alignas(64) uint8_t kru[];
 };
 
 /// Part of kr_request to avoid counting repeated cache accesses multiple times during single request.
@@ -49,7 +49,7 @@ static inline size_t kr_cache_top_entry_size(size_t key_len, size_t data_size) {
 }
 
 /// Price of a cache entry access in KRU based on the entry size.
-static inline kru_price_t kr_cache_top_entry_price(struct kr_cache_top *top, size_t size) {
+static inline uint32_t kr_cache_top_entry_price(struct kr_cache_top *top, size_t size) {
        return top->data->base_price_norm / size;
 }
 
index f8946df5d5c00a1ae89c260ba88b1a824d6bacf5..3e0c134ad11c253a284b032f1b91122b21602497 100644 (file)
@@ -4,6 +4,7 @@
 #include <libknot/libknot.h>
 #include "lib/utils.h"
 #include "lib/cache/top.h"
+#include "lib/kru.h"
 #include "utils/cache_gc/db.h"
 
 static inline int load2cat(uint16_t load)  // -> 0..64, reversed