diff --git a/Documentation/reference/os/iob.rst b/Documentation/reference/os/iob.rst index b962c5c8e4..287aa3d743 100644 --- a/Documentation/reference/os/iob.rst +++ b/Documentation/reference/os/iob.rst @@ -165,6 +165,7 @@ Public Function Prototypes - :c:func:`iob_peek_queue()` - :c:func:`iob_free_queue()` - :c:func:`iob_free_queue_qentry()` + - :c:func:`iob_get_queue_size()` - :c:func:`iob_copyin()` - :c:func:`iob_trycopyin()` - :c:func:`iob_copyout()` @@ -242,6 +243,10 @@ Public Function Prototypes .. c:function:: void iob_free_queue_qentry(FAR struct iob_s *iob, \ FAR struct iob_queue_s *iobq); + Queue helper for get the iob queue buffer size. + +.. c:function:: unsigned int iob_get_queue_size(FAR struct iob_queue_s *queue); + Free an iob entire queue of I/O buffer chains. .. c:function:: int iob_copyin(FAR struct iob_s *iob, FAR const uint8_t *src, \ diff --git a/include/nuttx/mm/iob.h b/include/nuttx/mm/iob.h index abdce41431..5aa9980f48 100644 --- a/include/nuttx/mm/iob.h +++ b/include/nuttx/mm/iob.h @@ -439,6 +439,18 @@ void iob_free_queue_qentry(FAR struct iob_s *iob, enum iob_user_e producerid); #endif /* CONFIG_IOB_NCHAINS > 0 */ +/**************************************************************************** + * Name: iob_get_queue_size + * + * Description: + * Queue helper for get the iob queue buffer size. + * + ****************************************************************************/ + +#if CONFIG_IOB_NCHAINS > 0 +unsigned int 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 4ae751a2c5..b69a2a0481 100644 --- a/mm/iob/Make.defs +++ b/mm/iob/Make.defs @@ -28,6 +28,7 @@ CSRCS += iob_free_chain.c iob_free_qentry.c iob_free_queue.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 iob_free_queue_qentry.c iob_tailroom.c +CSRCS += iob_get_queue_size.c ifeq ($(CONFIG_IOB_NOTIFIER),y) CSRCS += iob_notifier.c diff --git a/mm/iob/iob_get_queue_size.c b/mm/iob/iob_get_queue_size.c new file mode 100644 index 0000000000..26146c2fa1 --- /dev/null +++ b/mm/iob/iob_get_queue_size.c @@ -0,0 +1,58 @@ +/**************************************************************************** + * 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 queue buffer size. + * + ****************************************************************************/ + +unsigned int iob_get_queue_size(FAR struct iob_queue_s *queue) +{ + FAR struct iob_qentry_s *iobq; + unsigned int total = 0; + FAR struct iob_s *iob; + + for (iobq = queue->qh_head; iobq != NULL; iobq = iobq->qe_flink) + { + iob = iobq->qe_head; + total += iob->io_pktlen; + } + + return total; +} + +#endif /* CONFIG_IOB_NCHAINS > 0 */