mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-13 18:17:39 -04:00
Use a recursive depth-first shrinkage function, limit handles accordingly
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15414 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
9a114614d5
commit
a042c720c3
2 changed files with 16 additions and 17 deletions
|
@ -230,6 +230,9 @@ static struct memory_handle *add_handle(size_t data_size, const bool can_wrap,
|
||||||
size_t len;
|
size_t len;
|
||||||
int overlap;
|
int overlap;
|
||||||
|
|
||||||
|
if (num_handles >= BUF_MAX_HANDLES)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
mutex_lock(&llist_mutex);
|
mutex_lock(&llist_mutex);
|
||||||
|
|
||||||
if (cur_handle && cur_handle->filerem > 0) {
|
if (cur_handle && cur_handle->filerem > 0) {
|
||||||
|
@ -508,7 +511,6 @@ reset_handle : Reset writing position and data buffer of a handle to its
|
||||||
rebuffer_handle : Seek to a nonbuffered part of a handle by rebuffering the data
|
rebuffer_handle : Seek to a nonbuffered part of a handle by rebuffering the data
|
||||||
shrink_handle : Free buffer space by moving a handle
|
shrink_handle : Free buffer space by moving a handle
|
||||||
fill_buffer : Call buffer_handle for all handles that have data to buffer
|
fill_buffer : Call buffer_handle for all handles that have data to buffer
|
||||||
can_add_handle : Indicate whether it's safe to add a handle
|
|
||||||
|
|
||||||
These functions are used by the buffering thread to manage buffer space.
|
These functions are used by the buffering thread to manage buffer space.
|
||||||
*/
|
*/
|
||||||
|
@ -684,10 +686,9 @@ static bool close_handle(int handle_id)
|
||||||
|
|
||||||
/* Free buffer space by moving the handle struct right before the useful
|
/* Free buffer space by moving the handle struct right before the useful
|
||||||
part of its data buffer or by moving all the data. */
|
part of its data buffer or by moving all the data. */
|
||||||
static void shrink_handle(int handle_id)
|
static void shrink_handle(struct memory_handle *h)
|
||||||
{
|
{
|
||||||
size_t delta;
|
size_t delta;
|
||||||
struct memory_handle *h = find_handle(handle_id);
|
|
||||||
|
|
||||||
if (!h)
|
if (!h)
|
||||||
return;
|
return;
|
||||||
|
@ -1152,15 +1153,14 @@ static void call_buffer_low_callbacks(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void shrink_buffer(bool audio, bool other) {
|
static void shrink_buffer(struct memory_handle *h) {
|
||||||
/* shrink selected buffers */
|
|
||||||
struct memory_handle *m = first_handle;
|
if (h == NULL)
|
||||||
while (m) {
|
return;
|
||||||
if ((m->type==TYPE_PACKET_AUDIO && audio) ||
|
|
||||||
(m->type!=TYPE_PACKET_AUDIO && other))
|
shrink_buffer(h->next);
|
||||||
shrink_handle(m->id);
|
|
||||||
m = m->next;
|
shrink_handle(h);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void buffering_thread(void)
|
void buffering_thread(void)
|
||||||
|
@ -1255,12 +1255,9 @@ void buffering_thread(void)
|
||||||
if (data_counters.remaining > 0 &&
|
if (data_counters.remaining > 0 &&
|
||||||
data_counters.useful < conf_watermark)
|
data_counters.useful < conf_watermark)
|
||||||
{
|
{
|
||||||
/* First work forward, shrinking any unmoveable handles */
|
/* Recursively shrink the buffer, depth first */
|
||||||
shrink_buffer(true,false);
|
shrink_buffer(first_handle);
|
||||||
/* Then work forward following those up with moveable handles */
|
|
||||||
shrink_buffer(false,true);
|
|
||||||
fill_buffer();
|
fill_buffer();
|
||||||
update_data_counters();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,8 @@ bool buffering_reset(char *buf, size_t buflen);
|
||||||
* amount of data is ready (unless EOF is reached).
|
* amount of data is ready (unless EOF is reached).
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#define BUF_MAX_HANDLES 256
|
||||||
|
|
||||||
int bufopen(const char *file, size_t offset, enum data_type type);
|
int bufopen(const char *file, size_t offset, enum data_type type);
|
||||||
int bufalloc(const void *src, size_t size, enum data_type type);
|
int bufalloc(const void *src, size_t size, enum data_type type);
|
||||||
bool bufclose(int handle_id);
|
bool bufclose(int handle_id);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue