This is an automated email from the ASF dual-hosted git repository. pkarashchenko pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit a92d5f622e322230e71435431a23fc6f132b4b69 Author: chao.an <[email protected]> AuthorDate: Thu Feb 17 12:42:35 2022 +0800 net/ioballoc: add support of alloc with timeout net_iobtimedalloc() Signed-off-by: chao.an <[email protected]> --- include/nuttx/net/net.h | 34 ++++++++++++++++++++++++++++++++-- net/utils/net_lock.c | 45 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 71 insertions(+), 8 deletions(-) diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h index 0543dc0..8bdd503 100644 --- a/include/nuttx/net/net.h +++ b/include/nuttx/net/net.h @@ -460,6 +460,36 @@ int net_timedwait_uninterruptible(sem_t *sem, unsigned int timeout); int net_lockedwait_uninterruptible(sem_t *sem); +#ifdef CONFIG_MM_IOB + +/**************************************************************************** + * Name: net_iobtimedalloc + * + * Description: + * Allocate an IOB. If no IOBs are available, then atomically wait for + * for the IOB while temporarily releasing the lock on the network. + * This function is wrapped version of net_ioballoc(), this wait will + * be terminated when the specified timeout expires. + * + * Caution should be utilized. Because the network lock is relinquished + * during the wait, there could be changes in the network state that occur + * before the lock is recovered. Your design should account for this + * possibility. + * + * Input Parameters: + * throttled - An indication of the IOB allocation is "throttled" + * timeout - The relative time to wait until a timeout is declared. + * consumerid - id representing who is consuming the IOB + * + * Returned Value: + * A pointer to the newly allocated IOB is returned on success. NULL is + * returned on any allocation failure. + * + ****************************************************************************/ + +FAR struct iob_s *net_iobtimedalloc(bool throttled, unsigned int timeout, + enum iob_user_e consumerid); + /**************************************************************************** * Name: net_ioballoc * @@ -473,7 +503,8 @@ int net_lockedwait_uninterruptible(sem_t *sem); * possibility. * * Input Parameters: - * throttled - An indication of the IOB allocation is "throttled" + * throttled - An indication of the IOB allocation is "throttled" + * consumerid - id representing who is consuming the IOB * * Returned Value: * A pointer to the newly allocated IOB is returned on success. NULL is @@ -481,7 +512,6 @@ int net_lockedwait_uninterruptible(sem_t *sem); * ****************************************************************************/ -#ifdef CONFIG_MM_IOB FAR struct iob_s *net_ioballoc(bool throttled, enum iob_user_e consumerid); #endif diff --git a/net/utils/net_lock.c b/net/utils/net_lock.c index 94b3385..91666c5 100644 --- a/net/utils/net_lock.c +++ b/net/utils/net_lock.c @@ -451,12 +451,16 @@ int net_lockedwait_uninterruptible(sem_t *sem) return net_timedwait_uninterruptible(sem, UINT_MAX); } +#ifdef CONFIG_MM_IOB + /**************************************************************************** - * Name: net_ioballoc + * Name: net_timedalloc * * Description: * Allocate an IOB. If no IOBs are available, then atomically wait for * for the IOB while temporarily releasing the lock on the network. + * This function is wrapped version of nxsem_timedwait(), this wait will + * be terminated when the specified timeout expires. * * Caution should be utilized. Because the network lock is relinquished * during the wait, there could be changes in the network state that occur @@ -464,7 +468,9 @@ int net_lockedwait_uninterruptible(sem_t *sem) * possibility. * * Input Parameters: - * throttled - An indication of the IOB allocation is "throttled" + * throttled - An indication of the IOB allocation is "throttled" + * timeout - The relative time to wait until a timeout is declared. + * consumerid - id representing who is consuming the IOB * * Returned Value: * A pointer to the newly allocated IOB is returned on success. NULL is @@ -472,13 +478,13 @@ int net_lockedwait_uninterruptible(sem_t *sem) * ****************************************************************************/ -#ifdef CONFIG_MM_IOB -FAR struct iob_s *net_ioballoc(bool throttled, enum iob_user_e consumerid) +FAR struct iob_s *net_iobtimedalloc(bool throttled, unsigned int timeout, + enum iob_user_e consumerid) { FAR struct iob_s *iob; iob = iob_tryalloc(throttled, consumerid); - if (iob == NULL) + if (iob == NULL && timeout != 0) { unsigned int count; int blresult; @@ -488,7 +494,7 @@ FAR struct iob_s *net_ioballoc(bool throttled, enum iob_user_e consumerid) */ blresult = net_breaklock(&count); - iob = iob_alloc(throttled, consumerid); + iob = iob_timedalloc(throttled, timeout, consumerid); if (blresult >= 0) { net_restorelock(count); @@ -497,4 +503,31 @@ FAR struct iob_s *net_ioballoc(bool throttled, enum iob_user_e consumerid) return iob; } + +/**************************************************************************** + * Name: net_ioballoc + * + * Description: + * Allocate an IOB. If no IOBs are available, then atomically wait for + * for the IOB while temporarily releasing the lock on the network. + * + * Caution should be utilized. Because the network lock is relinquished + * during the wait, there could be changes in the network state that occur + * before the lock is recovered. Your design should account for this + * possibility. + * + * Input Parameters: + * throttled - An indication of the IOB allocation is "throttled" + * consumerid - id representing who is consuming the IOB + * + * Returned Value: + * A pointer to the newly allocated IOB is returned on success. NULL is + * returned on any allocation failure. + * + ****************************************************************************/ + +FAR struct iob_s *net_ioballoc(bool throttled, enum iob_user_e consumerid) +{ + return net_iobtimedalloc(throttled, UINT_MAX, consumerid); +} #endif
