From 49f80b7cf1523a7a2f824a5513b1baedf254f8a5 Mon Sep 17 00:00:00 2001 From: Martine Lenders <mail@martine-lenders.eu> Date: Thu, 22 Feb 2018 20:28:32 +0100 Subject: [PATCH] Revert "gnrc/netreg: remove gnrc_netreg_num" This reverts commit c178ea879829ac2ea2252bd73312edbda19ea0bd. --- sys/include/net/gnrc/netreg.h | 13 +++++++++++++ sys/net/gnrc/netreg/gnrc_netreg.c | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/sys/include/net/gnrc/netreg.h b/sys/include/net/gnrc/netreg.h index 11455c703a..cea7d13635 100644 --- a/sys/include/net/gnrc/netreg.h +++ b/sys/include/net/gnrc/netreg.h @@ -333,6 +333,19 @@ void gnrc_netreg_unregister(gnrc_nettype_t type, gnrc_netreg_entry_t *entry); */ gnrc_netreg_entry_t *gnrc_netreg_lookup(gnrc_nettype_t type, uint32_t demux_ctx); +/** + * @brief Returns number of entries with the same gnrc_netreg_entry_t::type and + * gnrc_netreg_entry_t::demux_ctx. + * + * @param[in] type Type of the protocol. + * @param[in] demux_ctx The demultiplexing context for the registered thread. + * See gnrc_netreg_entry_t::demux_ctx. + * + * @return Number of entries with the same gnrc_netreg_entry_t::type and + * gnrc_netreg_entry_t::demux_ctx as the given parameters. + */ +int gnrc_netreg_num(gnrc_nettype_t type, uint32_t demux_ctx); + /** * @brief Returns the next entry after @p entry with the same * gnrc_netreg_entry_t::type and gnrc_netreg_entry_t::demux_ctx as the diff --git a/sys/net/gnrc/netreg/gnrc_netreg.c b/sys/net/gnrc/netreg/gnrc_netreg.c index 8d8ef83462..c531ff9971 100644 --- a/sys/net/gnrc/netreg/gnrc_netreg.c +++ b/sys/net/gnrc/netreg/gnrc_netreg.c @@ -96,6 +96,28 @@ gnrc_netreg_entry_t *gnrc_netreg_lookup(gnrc_nettype_t type, uint32_t demux_ctx) return _netreg_lookup(NULL, type, demux_ctx); } +int gnrc_netreg_num(gnrc_nettype_t type, uint32_t demux_ctx) +{ + int num = 0; + gnrc_netreg_entry_t *entry; + + if (_INVALID_TYPE(type)) { + return 0; + } + + entry = netreg[type]; + + while (entry != NULL) { + if (entry->demux_ctx == demux_ctx) { + num++; + } + + entry = entry->next; + } + + return num; +} + gnrc_netreg_entry_t *gnrc_netreg_getnext(gnrc_netreg_entry_t *entry) { return (entry ? _netreg_lookup(entry, 0, entry->demux_ctx) : NULL); -- GitLab