]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Rewrite function for allocating bucket IDs
authorIgor Putovny <igor.putovny@nic.cz>
Fri, 29 Nov 2024 14:00:35 +0000 (15:00 +0100)
committerIgor Putovny <igor.putovny@nic.cz>
Fri, 29 Nov 2024 14:01:14 +0000 (15:01 +0100)
proto/aggregator/aggregator.c

index ae35b3f58192ad20f308606cfc3aa680fdb0f808..c8f33ea706eab13bb23644e0c035a15214f05335 100644 (file)
@@ -170,6 +170,17 @@ get_bucket_ptr(const struct aggregator_proto *p, u32 id)
   return p->bucket_list[id];
 }
 
+/*
+ * Allocate unique ID for bucket
+ */
+static inline u32
+get_new_bucket_id(struct aggregator_proto *p)
+{
+  u32 id = hmap_first_zero(&p->bucket_id_map);
+  hmap_set(&p->bucket_id_map, id);
+  return id;
+}
+
 static inline int
 popcount32(u32 x)
 {
@@ -359,20 +370,6 @@ trie_insert_prefix_ip6(struct trie_node * const root, const struct net_addr_ip6
   return node;
 }
 
-/*
- * Assign unique ID to @bucket
- */
-static void
-assign_bucket_id(struct aggregator_proto *p, struct aggregator_bucket *bucket)
-{
-  assert(p != NULL);
-  assert(bucket != NULL);
-  assert(bucket->id == 0);
-
-  bucket->id = hmap_first_zero(&p->bucket_id_map);
-  hmap_set(&p->bucket_id_map, bucket->id);
-}
-
 static void
 before_check(const struct trie_node *node)
 {
@@ -1665,7 +1662,7 @@ aggregator_rt_notify(struct proto *P, struct channel *src_ch, net *net, rte *new
       memcpy(new_bucket, tmp_bucket, sizeof(*new_bucket) + sizeof(new_bucket->aggr_data[0]) * p->aggr_on_count);
       HASH_INSERT2(p->buckets, AGGR_BUCK, p->p.pool, new_bucket);
 
-      assign_bucket_id(p, new_bucket);
+      new_bucket->id = get_new_bucket_id(p);
       proto_insert_bucket(p, new_bucket);
     }
 
@@ -1833,7 +1830,7 @@ trie_init(struct aggregator_proto *p)
   new_bucket->hash = mem_hash_value(&haux);
 
   /* Assign ID to root node */
-  assign_bucket_id(p, new_bucket);
+  new_bucket->id = get_new_bucket_id(p);
   proto_insert_bucket(p, new_bucket);
   assert(get_bucket_ptr(p, new_bucket->id) == new_bucket);