diff --git a/Documentation/reference/os/iob.rst b/Documentation/reference/os/iob.rst index 2a84af0756..79dc546042 100644 --- a/Documentation/reference/os/iob.rst +++ b/Documentation/reference/os/iob.rst @@ -177,6 +177,7 @@ Public Function Prototypes - :c:func:`iob_trimtail()` - :c:func:`iob_pack()` - :c:func:`iob_contig()` + - :c:func:`iob_count()` - :c:func:`iob_dump()` .. c:function:: void iob_initialize(void); @@ -324,6 +325,10 @@ Public Function Prototypes space at the beginning of the I/O buffer chain starting at ``iob``. +.. c:function:: int iob_count(FAR struct iob_s *iob); + + Get ``iob`` entries count in chain. + .. c:function:: void iob_dump(FAR const char *msg, FAR struct iob_s *iob, unsigned int len, \ unsigned int offset); diff --git a/include/nuttx/mm/iob.h b/include/nuttx/mm/iob.h index 0bc5fe3614..02accd257a 100644 --- a/include/nuttx/mm/iob.h +++ b/include/nuttx/mm/iob.h @@ -593,6 +593,16 @@ void iob_reserve(FAR struct iob_s *iob, unsigned int reserved); void iob_update_pktlen(FAR struct iob_s *iob, unsigned int pktlen); +/**************************************************************************** + * Name: iob_count + * + * Description: + * Get iob entries count in chain. + * + ****************************************************************************/ + +int iob_count(FAR struct iob_s *iob); + /**************************************************************************** * Name: iob_dump * diff --git a/mm/iob/Make.defs b/mm/iob/Make.defs index 0da2f76896..6359014e36 100644 --- a/mm/iob/Make.defs +++ b/mm/iob/Make.defs @@ -29,6 +29,7 @@ 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 iob_reserve.c iob_update_pktlen.c +CSRCS += iob_count.c ifeq ($(CONFIG_IOB_NOTIFIER),y) CSRCS += iob_notifier.c diff --git a/mm/iob/iob_count.c b/mm/iob/iob_count.c new file mode 100644 index 0000000000..9d185916de --- /dev/null +++ b/mm/iob/iob_count.c @@ -0,0 +1,49 @@ +/**************************************************************************** + * mm/iob/iob_count.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" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: iob_count + * + * Description: + * Get iob entries count in chain. + * + ****************************************************************************/ + +int iob_count(FAR struct iob_s *iob) +{ + int count; + + for (count = 0; iob != NULL; + iob = iob->io_flink, count++); + + return count; +}