From d6d56c3372c2818b89927d20f25852b9c8b6d197 Mon Sep 17 00:00:00 2001 From: chao an Date: Tue, 13 Dec 2022 16:08:27 +0800 Subject: [PATCH] mm/iob: add support of nonblock iob_clone Signed-off-by: chao an --- Documentation/reference/os/iob.rst | 3 ++- include/nuttx/mm/iob.h | 4 ++-- mm/iob/iob_clone.c | 13 +++++++++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Documentation/reference/os/iob.rst b/Documentation/reference/os/iob.rst index ecb925dc9f..5249139a87 100644 --- a/Documentation/reference/os/iob.rst +++ b/Documentation/reference/os/iob.rst @@ -267,7 +267,8 @@ Public Function Prototypes buffer starting at ``offset`` in the I/O buffer, returning that actual number of bytes copied out. -.. c:function:: int iob_clone(FAR struct iob_s *iob1, FAR struct iob_s *iob2, bool throttled) +.. c:function:: int iob_clone(FAR struct iob_s *iob1, FAR struct iob_s *iob2, \ + bool throttled, bool block); Duplicate (and pack) the data in ``iob1`` in ``iob2``. ``iob2`` must be empty. diff --git a/include/nuttx/mm/iob.h b/include/nuttx/mm/iob.h index fa672d0cd5..7ced19a487 100644 --- a/include/nuttx/mm/iob.h +++ b/include/nuttx/mm/iob.h @@ -464,8 +464,8 @@ unsigned int iob_tailroom(FAR struct iob_s *iob); * ****************************************************************************/ -int iob_clone(FAR struct iob_s *iob1, - FAR struct iob_s *iob2, bool throttled); +int iob_clone(FAR struct iob_s *iob1, FAR struct iob_s *iob2, + bool throttled, bool block); /**************************************************************************** * Name: iob_concat diff --git a/mm/iob/iob_clone.c b/mm/iob/iob_clone.c index 1a149bd059..8184d3b3d4 100644 --- a/mm/iob/iob_clone.c +++ b/mm/iob/iob_clone.c @@ -53,7 +53,8 @@ * ****************************************************************************/ -int iob_clone(FAR struct iob_s *iob1, FAR struct iob_s *iob2, bool throttled) +int iob_clone(FAR struct iob_s *iob1, FAR struct iob_s *iob2, + bool throttled, bool block) { FAR uint8_t *src; FAR uint8_t *dest; @@ -145,7 +146,15 @@ int iob_clone(FAR struct iob_s *iob1, FAR struct iob_s *iob2, bool throttled) * destination I/O buffer chain. */ - next = iob_alloc(throttled); + if (block) + { + next = iob_alloc(throttled); + } + else + { + next = iob_tryalloc(throttled); + } + if (!next) { ioberr("ERROR: Failed to allocate an I/O buffer\n");