aboutsummaryrefslogtreecommitdiff
path: root/src/core/idhash.h
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2025-08-25 06:56:09 -0700
committerGarrett D'Amore <garrett@damore.org>2025-08-25 10:03:03 -0700
commitc17d1cfebc016ed790df74f0eeb539a4a71fadda (patch)
tree4b5eeee07ae35c1d25adc2bb8575c115b92f05ec /src/core/idhash.h
parentb1ece6af107958d9d3935586778184763a44f5ee (diff)
downloadnng-c17d1cfebc016ed790df74f0eeb539a4a71fadda.tar.gz
nng-c17d1cfebc016ed790df74f0eeb539a4a71fadda.tar.bz2
nng-c17d1cfebc016ed790df74f0eeb539a4a71fadda.zip
fixes #2148 Old id_reg_map seems not be freed
This simplifies the code to just use a precompiled static list. This should be lighter weight, and provably free from leaks.
Diffstat (limited to 'src/core/idhash.h')
-rw-r--r--src/core/idhash.h19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/core/idhash.h b/src/core/idhash.h
index b07404aa..1d0c9b0e 100644
--- a/src/core/idhash.h
+++ b/src/core/idhash.h
@@ -1,5 +1,5 @@
//
-// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
@@ -11,7 +11,7 @@
#ifndef CORE_IDHASH_H
#define CORE_IDHASH_H
-#include "core/defs.h"
+#include "defs.h"
// We find that we often want to have a list of things listed by a
// numeric ID, which is generally monotonically increasing. This is
@@ -30,12 +30,14 @@ typedef struct nni_id_entry nni_id_entry;
// They are provided here to facilitate inlining in structures.
// We can support at most 2^32 ~ 4 billion ~ entries.
struct nni_id_map {
- uint32_t id_flags;
uint32_t id_cap;
uint32_t id_count;
uint32_t id_load;
uint32_t id_min_load; // considers placeholders
uint32_t id_max_load;
+ bool id_static;
+ bool id_registered;
+ bool id_random;
uint64_t id_min_val;
uint64_t id_max_val;
uint64_t id_dyn_val;
@@ -57,10 +59,13 @@ extern void nni_id_map_sys_fini(void);
extern bool nni_id_visit(nni_id_map *, uint64_t *, void **, uint32_t *);
extern uint32_t nni_id_count(const nni_id_map *);
-#define NNI_ID_MAP_INITIALIZER(min, max, flags) \
- { \
- .id_min_val = (min), .id_max_val = (max), \
- .id_flags = ((flags) | NNI_ID_FLAG_STATIC) \
+#define NNI_ID_MAP_INITIALIZER(min, max, random) \
+ { \
+ .id_min_val = (min), \
+ .id_max_val = (max), \
+ .id_static = true, \
+ .id_registered = false, \
+ .id_random = random, \
}
#endif // CORE_IDHASH_H