diff options
author | Balint Dobszay <balint.dobszay@arm.com> | 2020-12-23 12:53:14 +0100 |
---|---|---|
committer | Jérôme Forissier <jerome@forissier.org> | 2021-01-05 17:56:19 +0100 |
commit | 988ea29c4666687dcc038a35efd6412567be57bf (patch) | |
tree | 1fa1a924d2ac99438c9ad3b9718266373afb7d0f | |
parent | 0a971fdb4eeaa9139755d12ba08aaad50ab0f884 (diff) |
core: add handle_db_is_empty() function
Implements a function that checks if a handle database is empty, i.e.
all pointers stored in the database are NULL.
Acked-by: Etienne Carriere <etienne.carriere@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Jerome Forissier <jerome@forissier.org>
Signed-off-by: Balint Dobszay <balint.dobszay@arm.com>
-rw-r--r-- | core/include/kernel/handle.h | 5 | ||||
-rw-r--r-- | core/kernel/handle.c | 14 |
2 files changed, 19 insertions, 0 deletions
diff --git a/core/include/kernel/handle.h b/core/include/kernel/handle.h index 6cca2dbf..eb4375dd 100644 --- a/core/include/kernel/handle.h +++ b/core/include/kernel/handle.h @@ -1,10 +1,12 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * Copyright (c) 2014, Linaro Limited + * Copyright (c) 2020, Arm Limited */ #ifndef KERNEL_HANDLE_H #define KERNEL_HANDLE_H +#include <stdbool.h> #include <stdint.h> struct handle_db { @@ -22,6 +24,9 @@ struct handle_db { */ void handle_db_destroy(struct handle_db *db, void (*ptr_destructor)(void *ptr)); +/* Checks if the associated pointers of all handles in the database are NULL. */ +bool handle_db_is_empty(struct handle_db *db); + /* * Allocates a new handle and assigns the supplied pointer to it, * ptr must not be NULL. diff --git a/core/kernel/handle.c b/core/kernel/handle.c index 131c7059..96f01cb3 100644 --- a/core/kernel/handle.c +++ b/core/kernel/handle.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: BSD-2-Clause /* * Copyright (c) 2014, Linaro Limited + * Copyright (c) 2020, Arm Limited */ #include <stdlib.h> #include <string.h> @@ -30,6 +31,19 @@ void handle_db_destroy(struct handle_db *db, void (*ptr_destructor)(void *ptr)) } } +bool handle_db_is_empty(struct handle_db *db) +{ + size_t n = 0; + + if (db) { + for (n = 0; n < db->max_ptrs; n++) { + if (db->ptrs[n]) + return false; + } + } + return true; +} + int handle_get(struct handle_db *db, void *ptr) { size_t n; |