diff --git a/include/nuttx/mm/iob.h b/include/nuttx/mm/iob.h index 86150e9cf8..e47f4b55d5 100644 --- a/include/nuttx/mm/iob.h +++ b/include/nuttx/mm/iob.h @@ -195,7 +195,17 @@ FAR struct iob_s *iob_tryalloc(bool throttled); * ****************************************************************************/ -int iob_navail(void); +int iob_navail(bool throttled); + +/**************************************************************************** + * Name: iob_quentry_navail + * + * Description: + * Return the number of available IOB chains. + * + ****************************************************************************/ + +int iob_quentry_navail(void); /**************************************************************************** * Name: iob_free diff --git a/mm/iob/iob_free.c b/mm/iob/iob_free.c index b422bdd0ed..b29dafe610 100644 --- a/mm/iob/iob_free.c +++ b/mm/iob/iob_free.c @@ -39,6 +39,7 @@ #include +#include #include #include #include @@ -148,7 +149,7 @@ FAR struct iob_s *iob_free(FAR struct iob_s *iob) * for an IOB. */ - if (iob_navail() > 0) + if (iob_navail(false) > 0) { /* Signal any threads that have requested a signal notification * when an IOB becomes available. diff --git a/mm/iob/iob_navail.c b/mm/iob/iob_navail.c index 7a14e5533f..4f41cadfe7 100644 --- a/mm/iob/iob_navail.c +++ b/mm/iob/iob_navail.c @@ -39,6 +39,8 @@ #include +#include + #include #include @@ -56,17 +58,62 @@ * ****************************************************************************/ -int iob_navail(void) +int iob_navail(bool throttled) { int navail = 0; int ret; -#if CONFIG_IOB_NCHAINS > 0 - ret = nxsem_getvalue(&g_qentry_sem, &navail); +#if CONFIG_IOB_NBUFFERS > 0 + /* Get the value of the IOB counting semaphores */ + + ret = nxsem_getvalue(&g_iob_sem, &navail); if (ret >= 0) { ret = navail; + +#if CONFIG_IOB_THROTTLE > 0 + /* Subtract the throttle value is so requested */ + + if (throttled) + { + ret -= CONFIG_IOB_THROTTLE; + if (ret < 0) + { + ret = 0; + } + } +#endif } + +#else + ret = navail; +#endif + + return ret; +} + +/**************************************************************************** + * Name: iob_quentry_navail + * + * Description: + * Return the number of available IOB chains. + * + ****************************************************************************/ + +int iob_quentry_navail(void) +{ + int navail = 0; + int ret; + +#if CONFIG_IOB_NCHAINS > 0 + /* Get the value of the IOB chain qentry counting semaphores */ + + ret = nxsem_getvalue(&g_qentry_sem, &navail); + if (ret >= 0) + { + ret = navail; + } + #else ret = navail; #endif diff --git a/mm/iob/iob_notifier.c b/mm/iob/iob_notifier.c index 397eb4f04e..c914a644f5 100644 --- a/mm/iob/iob_notifier.c +++ b/mm/iob/iob_notifier.c @@ -86,9 +86,11 @@ int iob_notifier_setup(int qid, worker_t worker, FAR void *arg) /* If there are already free IOBs, then return zero without setting up the * notification. + * + * REVISIT: The 'throttled' argument should not always be 'false'. */ - if (iob_navail() > 0) + if (iob_navail(false) > 0) { return 0; } diff --git a/net/tcp/tcp_recvwindow.c b/net/tcp/tcp_recvwindow.c index 4929e797ee..7123001c18 100644 --- a/net/tcp/tcp_recvwindow.c +++ b/net/tcp/tcp_recvwindow.c @@ -40,6 +40,7 @@ #include #include +#incldue #include #include @@ -109,7 +110,7 @@ uint16_t tcp_get_recvwindow(FAR struct net_driver_s *dev) * availability. */ - navail = iob_navail(); + navail = iob_navail(true); /* Are the read-ahead allocations throttled? If so, then not all of these * IOBs are available for read-ahead buffering.