From 4721381d1cacd206d6474aba2983bba5006c5737 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sat, 26 Jan 2019 09:24:12 -0600 Subject: [PATCH] mm/iob/iob_alloc.c: iob_allocwait should decrease semcount manually. --- mm/iob/iob_alloc.c | 25 +++++++++++++++---------- mm/iob/iob_free.c | 3 --- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/mm/iob/iob_alloc.c b/mm/iob/iob_alloc.c index d380d093a1..b662bb41f0 100644 --- a/mm/iob/iob_alloc.c +++ b/mm/iob/iob_alloc.c @@ -162,21 +162,13 @@ static FAR struct iob_s *iob_allocwait(bool throttled) else { /* When we wake up from wait successfully, an I/O buffer was - * freed and we hold a count for one IOB. Unless somehting - * failed, we should have an IOB waiting for us in the - * committed list. + * freed and we hold a count for one IOB. */ iob = iob_alloc_committed(); - DEBUGASSERT(iob != NULL); - if (iob == NULL) { - /* This should not fail, but we allow for that possibility to - * handle any potential, non-obvious race condition. Perhaps - * the free IOB ended up in the g_iob_free list? - * - * We need release our count so that it is available to + /* We need release our count so that it is available to * iob_tryalloc(), perhaps allowing another thread to take our * count. In that event, iob_tryalloc() will fail above and * we will have to wait again. @@ -185,6 +177,19 @@ static FAR struct iob_s *iob_allocwait(bool throttled) nxsem_post(sem); iob = iob_tryalloc(throttled); } +#if CONFIG_IOB_THROTTLE > 0 + else + { + if (throttled) + { + g_iob_sem.semcount--; + } + else + { + g_throttle_sem.semcount--; + } + } +#endif } } diff --git a/mm/iob/iob_free.c b/mm/iob/iob_free.c index 980f43df4a..c92a746568 100644 --- a/mm/iob/iob_free.c +++ b/mm/iob/iob_free.c @@ -163,11 +163,8 @@ FAR struct iob_s *iob_free(FAR struct iob_s *iob) #if CONFIG_IOB_THROTTLE > 0 nxsem_post(&g_throttle_sem); - -#if 0 /* REVISIT: This assertion fires! */ DEBUGASSERT(g_throttle_sem.semcount <= (CONFIG_IOB_NBUFFERS - CONFIG_IOB_THROTTLE)); #endif -#endif #ifdef CONFIG_IOB_NOTIFIER /* Check if the IOB was claimed by a thread that is blocked waiting