From 07b77a8234b76a92b7404063a4b4a9d94e233edf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20D=C3=B6ring?= Date: Sat, 2 Nov 2024 15:53:01 +0100 Subject: [PATCH] Addressed comments from @merlinND --- include/drjit-core/jit.h | 5 +++-- src/api.cpp | 4 ++-- src/registry.cpp | 18 +++++++++--------- src/registry.h | 5 +++-- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/include/drjit-core/jit.h b/include/drjit-core/jit.h index 426113b0..e7514444 100644 --- a/include/drjit-core/jit.h +++ b/include/drjit-core/jit.h @@ -494,13 +494,14 @@ extern JIT_EXPORT void jit_registry_remove(const void *ptr); extern JIT_EXPORT uint32_t jit_registry_id(const void *ptr); /// Return the largest instance ID for the given domain -/// If the \c domain is a nullptr, it returns the largest instance ID for the given backend +/// If the \c domain is a nullptr, it returns the number of active entries in +/// all domains for the given backend extern JIT_EXPORT uint32_t jit_registry_id_bound(JitBackend backend, const char *domain); /// Fills the \c dest pointer array with all pointers registered in the registry /// \c dest has to point to an array with \c jit_registry_id_bound(backend, nullptr) entries -extern JIT_EXPORT void jit_registry_fill_ptrs(JitBackend backend, void **dest); +extern JIT_EXPORT void jit_registry_get_pointers(JitBackend backend, void **dest); /// Return the pointer value associated with a given instance ID extern JIT_EXPORT void *jit_registry_ptr(JitBackend backend, diff --git a/src/api.cpp b/src/api.cpp index 00de624c..d38c71b7 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -983,9 +983,9 @@ uint32_t jit_registry_id_bound(JitBackend backend, const char *domain) { return jitc_registry_id_bound(backend, domain); } -void jit_registry_fill_ptrs(JitBackend backend, void **dest) { +void jit_registry_get_pointers(JitBackend backend, void **dest) { lock_guard guard(state.lock); - return jitc_registry_fill_ptrs(backend, dest); + return jitc_registry_get_pointers(backend, dest); } void *jit_registry_ptr(JitBackend backend, const char *domain, uint32_t id) { diff --git a/src/registry.cpp b/src/registry.cpp index 141c7197..540d6f83 100644 --- a/src/registry.cpp +++ b/src/registry.cpp @@ -152,14 +152,14 @@ uint32_t jitc_registry_id(const void *ptr) { uint32_t jitc_registry_id_bound(JitBackend backend, const char *domain) { Registry &r = registry; if (!domain) { - uint32_t i = 0; + uint32_t n = 0; for (Domain &domain : r.domains) { if (domain.backend == backend) for (auto ptr : domain.fwd_map) if (ptr.active) - i++; + n++; } - return i; + return n; } auto it = r.domain_ids.find(DomainKey{ backend, domain }); if (it == r.domain_ids.end()) @@ -168,16 +168,16 @@ uint32_t jitc_registry_id_bound(JitBackend backend, const char *domain) { return r.domains[it->second].id_bound; } -void jitc_registry_fill_ptrs(JitBackend backend, void **dest) { - Registry &r = registry; +void jitc_registry_get_pointers(JitBackend backend, void **dest) { + const Registry &r = registry; - uint32_t i = 0; - for (Domain &domain : r.domains) { + uint32_t n = 0; + for (const Domain &domain : r.domains) { if (domain.backend == backend) for (auto ptr : domain.fwd_map) { if (ptr.active) { - dest[i] = ptr.ptr; - i++; + dest[n] = ptr.ptr; + n++; } } } diff --git a/src/registry.h b/src/registry.h index e486b42b..befb2025 100644 --- a/src/registry.h +++ b/src/registry.h @@ -22,12 +22,13 @@ extern void jitc_registry_remove(const void *ptr); extern uint32_t jitc_registry_id(const void *ptr); /// Return the largest instance ID for the given domain -/// If the \c domain is a nullptr, it returns the largest instance ID for the given backend +/// If the \c domain is a nullptr, it returns the number of active entries in +/// all domains for the given backend extern uint32_t jitc_registry_id_bound(JitBackend backend, const char *domain); /// Fills the \c dest pointer array with all pointers registered in the registry /// \c dest has to point to an array with \c jit_registry_id_bound(backend, nullptr) entries -void extern jitc_registry_fill_ptrs(JitBackend backend, void **dest); +void extern jitc_registry_get_pointers(JitBackend backend, void **dest); /// Return the pointer value associated with a given instance ID extern void *jitc_registry_ptr(JitBackend backend, const char *domain, uint32_t id);