summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2017-12-09 21:57:01 -0500
committerMichael Sevakis <jethead71@rockbox.org>2017-12-09 21:57:01 -0500
commit8be40746b81c4fde8f990c13f1359ebbc88d048f (patch)
tree203ec54aef35ad0aa78990c25c7263b1bfc5b3b6
parent65515f32b6c1b5e32061676683549c1028e03bff (diff)
downloadrockbox-8be4074.tar.gz
rockbox-8be4074.tar.bz2
rockbox-8be4074.zip
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
-rw-r--r--apps/buffering.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/apps/buffering.c b/apps/buffering.c
index 9bc7d730c5..4b6a9d7f73 100644
--- a/apps/buffering.c
+++ b/apps/buffering.c
@@ -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);
}