From 2fd5872449a797cfcbbdabdeb103fe61b143a4f4 Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Tue, 13 Apr 2021 20:50:38 +0800 Subject: [PATCH] mm/iob: add iob_get_queue_size() helper Change-Id: I117530f364cbef1e011638ff6d14087b7447bde7 Signed-off-by: chao.an --- include/nuttx/mm/iob.h | 12 ++++++++ mm/iob/Make.defs | 2 +- mm/iob/iob_get_queue_size.c | 60 +++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 mm/iob/iob_get_queue_size.c diff --git a/include/nuttx/mm/iob.h b/include/nuttx/mm/iob.h index a5d817eb42e..9bf291f39b8 100644 --- a/include/nuttx/mm/iob.h +++ b/include/nuttx/mm/iob.h @@ -457,6 +457,18 @@ void iob_destroy_queue(FAR struct iob_queue_s *qhead, int iob_get_queue_count(FAR struct iob_queue_s *queue); #endif /* CONFIG_IOB_NCHAINS > 0 */ +/**************************************************************************** + * Name: iob_get_queue_size + * + * Description: + * Queue helper for get the iob entry size. + * + ****************************************************************************/ + +#if CONFIG_IOB_NCHAINS > 0 +size_t iob_get_queue_size(FAR struct iob_queue_s *queue); +#endif /* CONFIG_IOB_NCHAINS > 0 */ + /**************************************************************************** * Name: iob_copyin * diff --git a/mm/iob/Make.defs b/mm/iob/Make.defs index f5d0b8c6c99..50a7adf57b7 100644 --- a/mm/iob/Make.defs +++ b/mm/iob/Make.defs @@ -25,7 +25,7 @@ ifeq ($(CONFIG_MM_IOB),y) CSRCS += iob_add_queue.c iob_alloc.c iob_alloc_qentry.c iob_clone.c CSRCS += iob_concat.c iob_copyin.c iob_copyout.c iob_contig.c iob_free.c CSRCS += iob_free_chain.c iob_free_qentry.c iob_destroy_queue.c -CSRCS += iob_free_queue.c iob_get_queue_count.c +CSRCS += iob_free_queue.c iob_get_queue_count.c iob_get_queue_size.c CSRCS += iob_initialize.c iob_pack.c iob_peek_queue.c iob_remove_queue.c CSRCS += iob_statistics.c iob_trimhead.c iob_trimhead_queue.c iob_trimtail.c CSRCS += iob_navail.c diff --git a/mm/iob/iob_get_queue_size.c b/mm/iob/iob_get_queue_size.c new file mode 100644 index 00000000000..46deb2b76f1 --- /dev/null +++ b/mm/iob/iob_get_queue_size.c @@ -0,0 +1,60 @@ +/**************************************************************************** + * mm/iob/iob_get_queue_size.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include "iob.h" + +#if CONFIG_IOB_NCHAINS > 0 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: iob_get_queue_size + * + * Description: + * Queue helper for get the iob entry count. + * + ****************************************************************************/ + +size_t iob_get_queue_size(FAR struct iob_queue_s *queue) +{ + FAR struct iob_qentry_s *iobq; + FAR struct iob_s *iob; + size_t total = 0; + + for (iobq = queue->qh_head; iobq != NULL; iobq = iobq->qe_flink) + { + for (iob = iobq->qe_head; iob; iob = iob->io_flink) + { + total += iob->io_len; + } + } + + return total; +} + +#endif /* CONFIG_IOB_NCHAINS > 0 */