From b452e2fddf1b6c3c0424eb8be5c338271c3ca6a9 Mon Sep 17 00:00:00 2001 From: chao an Date: Mon, 28 Nov 2022 13:36:47 +0800 Subject: [PATCH] mm/iob: new function iob_reserve() to adjust headroom offset Signed-off-by: chao an --- include/nuttx/mm/iob.h | 10 ++++++ mm/iob/Make.defs | 2 +- mm/iob/iob_reserve.c | 82 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 mm/iob/iob_reserve.c diff --git a/include/nuttx/mm/iob.h b/include/nuttx/mm/iob.h index 0b4cc80631..990dd94e1d 100644 --- a/include/nuttx/mm/iob.h +++ b/include/nuttx/mm/iob.h @@ -544,6 +544,16 @@ FAR struct iob_s *iob_pack(FAR struct iob_s *iob); int iob_contig(FAR struct iob_s *iob, unsigned int len); +/**************************************************************************** + * Name: iob_reserve + * + * Description: + * Adjust headroom offset of iobs by reducing the tail room. + * + ****************************************************************************/ + +void iob_reserve(FAR struct iob_s *iob, unsigned int reserved); + /**************************************************************************** * Name: iob_dump * diff --git a/mm/iob/Make.defs b/mm/iob/Make.defs index f80edfc8a4..9900ff2137 100644 --- a/mm/iob/Make.defs +++ b/mm/iob/Make.defs @@ -28,7 +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 +CSRCS += iob_get_queue_size.c iob_reserve.c ifeq ($(CONFIG_IOB_NOTIFIER),y) CSRCS += iob_notifier.c diff --git a/mm/iob/iob_reserve.c b/mm/iob/iob_reserve.c new file mode 100644 index 0000000000..7181c6674b --- /dev/null +++ b/mm/iob/iob_reserve.c @@ -0,0 +1,82 @@ +/**************************************************************************** + * mm/iob/iob_reserve.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_reserve + * + * Description: + * Adjust headroom offset of iobs by reducing the tail room. + * + ****************************************************************************/ + +void iob_reserve(FAR struct iob_s *iob, unsigned int reserved) +{ + unsigned int offset; + + /* Empty iob buffer is allowed, update packet length. */ + + if (iob->io_pktlen > reserved) + { + iob->io_pktlen -= reserved; + } + else + { + iob->io_pktlen = 0; + } + + /* Update offset and reducing the tail room */ + + while (iob != NULL && reserved > 0) + { + if (reserved > CONFIG_IOB_BUFSIZE) + { + offset = CONFIG_IOB_BUFSIZE; + } + else + { + offset = reserved; + } + + if (iob->io_len > offset) + { + iob->io_len -= offset; + } + else + { + iob->io_len = 0; + } + + iob->io_offset = offset; + iob = iob->io_flink; + } +}