Remove recursion from shrink_buffer()

There's no need for it any longer since the list is now doubly-
linked. As a bonus, stack limits pose no barrier to the length of
the list.

Change-Id: I41c567f946b640ef1e3c2d93da2f5aef9a763c66
This commit is contained in:
Michael Sevakis 2017-12-09 21:57:01 -05:00
parent 65515f32b6
commit 8be40746b8

View file

@ -132,6 +132,9 @@ static struct mutex llist_mutex SHAREDBSS_ATTR;
#define HLIST_LAST \
HLIST_HANDLE(handle_list.tail)
#define HLIST_PREV(h) \
HLIST_HANDLE((h)->hnode.prev)
#define HLIST_NEXT(h) \
HLIST_HANDLE((h)->hnode.next)
@ -1583,21 +1586,16 @@ size_t buf_get_watermark(void)
}
/** -- buffer thread helpers -- **/
static void shrink_buffer_inner(struct memory_handle *h)
{
if (h == NULL)
return;
shrink_buffer_inner(HLIST_NEXT(h));
shrink_handle(h);
}
static void shrink_buffer(void)
{
logf("shrink_buffer()");
mutex_lock(&llist_mutex);
shrink_buffer_inner(HLIST_FIRST);
for (struct memory_handle *h = HLIST_LAST; h; h = HLIST_PREV(h)) {
shrink_handle(h);
}
mutex_unlock(&llist_mutex);
}