This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 2c51c29768d395c3a1689b7d083c8beec8782a38
Author: chao.an <[email protected]>
AuthorDate: Tue Jun 8 23:38:26 2021 +0800

    mm/iob: add an interface to support dequeue an iob from the queue
    
    Signed-off-by: chao.an <[email protected]>
---
 Documentation/reference/os/iob.rst |  6 +++
 include/nuttx/mm/iob.h             | 14 ++++++
 mm/iob/Make.defs                   |  2 +-
 mm/iob/iob_free_queue_qentry.c     | 94 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 115 insertions(+), 1 deletion(-)

diff --git a/Documentation/reference/os/iob.rst 
b/Documentation/reference/os/iob.rst
index 01e74d2..b962c5c 100644
--- a/Documentation/reference/os/iob.rst
+++ b/Documentation/reference/os/iob.rst
@@ -164,6 +164,7 @@ Public Function Prototypes
   - :c:func:`iob_remove_queue()`
   - :c:func:`iob_peek_queue()`
   - :c:func:`iob_free_queue()`
+  - :c:func:`iob_free_queue_qentry()`
   - :c:func:`iob_copyin()`
   - :c:func:`iob_trycopyin()`
   - :c:func:`iob_copyout()`
@@ -238,6 +239,11 @@ Public Function Prototypes
 
   Free an entire queue of I/O buffer chains.
 
+.. c:function:: void iob_free_queue_qentry(FAR struct iob_s *iob, \
+                  FAR struct iob_queue_s *iobq);
+
+  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, \
                   unsigned int len, unsigned int offset, bool throttled);
 
diff --git a/include/nuttx/mm/iob.h b/include/nuttx/mm/iob.h
index f5f5c8c..5fcabb1 100644
--- a/include/nuttx/mm/iob.h
+++ b/include/nuttx/mm/iob.h
@@ -426,6 +426,20 @@ void iob_free_queue(FAR struct iob_queue_s *qhead,
 #endif /* CONFIG_IOB_NCHAINS > 0 */
 
 /****************************************************************************
+ * Name: iob_free_queue_qentry
+ *
+ * Description:
+ *   Free an iob entire queue of I/O buffer chains.
+ *
+ ****************************************************************************/
+
+#if CONFIG_IOB_NCHAINS > 0
+void iob_free_queue_qentry(FAR struct iob_s *iob,
+                           FAR struct iob_queue_s *iobq,
+                           enum iob_user_e producerid);
+#endif /* CONFIG_IOB_NCHAINS > 0 */
+
+/****************************************************************************
  * Name: iob_copyin
  *
  * Description:
diff --git a/mm/iob/Make.defs b/mm/iob/Make.defs
index 7bf53e7..e241204 100644
--- a/mm/iob/Make.defs
+++ b/mm/iob/Make.defs
@@ -27,7 +27,7 @@ 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_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
+CSRCS += iob_navail.c iob_free_queue_qentry.c
 
 ifeq ($(CONFIG_IOB_NOTIFIER),y)
   CSRCS += iob_notifier.c
diff --git a/mm/iob/iob_free_queue_qentry.c b/mm/iob/iob_free_queue_qentry.c
new file mode 100644
index 0000000..ef39084
--- /dev/null
+++ b/mm/iob/iob_free_queue_qentry.c
@@ -0,0 +1,94 @@
+/****************************************************************************
+ * mm/iob/iob_free_queue_qentry.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 <nuttx/config.h>
+#include <assert.h>
+#include <nuttx/mm/iob.h>
+
+#include "iob.h"
+
+#if CONFIG_IOB_NCHAINS > 0
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifndef NULL
+#  define NULL ((FAR void *)0)
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: iob_free_queue_qentry
+ *
+ * Description:
+ *   Free an iob entire queue of I/O buffer chains.
+ *
+ ****************************************************************************/
+
+void iob_free_queue_qentry(FAR struct iob_s *iob,
+                           FAR struct iob_queue_s *iobq,
+                           enum iob_user_e producerid)
+{
+  FAR struct iob_qentry_s *prev = NULL;
+  FAR struct iob_qentry_s *qentry;
+
+  for (qentry = iobq->qh_head; qentry != NULL;
+       prev = qentry, qentry = qentry->qe_flink)
+    {
+      /* Find head of the I/O buffer chain */
+
+      if (qentry->qe_head == iob)
+        {
+          if (prev == NULL)
+            {
+              iobq->qh_head = qentry->qe_flink;
+            }
+          else
+            {
+              prev->qe_flink = qentry->qe_flink;
+            }
+
+          if (iobq->qh_tail == qentry)
+            {
+              iobq->qh_tail = prev;
+            }
+
+          /* Remove the queue container */
+
+          iob_free_qentry(qentry);
+
+          /* Free the I/O chain */
+
+          iob_free_chain(iob, producerid);
+
+          break;
+        }
+    }
+}
+
+#endif /* CONFIG_IOB_NCHAINS > 0 */

Reply via email to