summaryrefslogtreecommitdiffstats
path: root/apps/buffering.c
diff options
context:
space:
mode:
authorBrandon Low <lostlogic@rockbox.org>2007-11-04 19:01:02 +0000
committerBrandon Low <lostlogic@rockbox.org>2007-11-04 19:01:02 +0000
commit31c1164c49c88b32a5d0243c8ed32b01376772f2 (patch)
treecc5d38aa996f87fc97f9c4ae9f20715bc68bf493 /apps/buffering.c
parent66f0cb2f6096e31de09b154e2bc11a9cb4d9df73 (diff)
downloadrockbox-31c1164c49c88b32a5d0243c8ed32b01376772f2.tar.gz
rockbox-31c1164c49c88b32a5d0243c8ed32b01376772f2.zip
make handle_id of zero valid, stop using memsets to clear tracks, should be no functional changes
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15462 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/buffering.c')
-rw-r--r--apps/buffering.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/apps/buffering.c b/apps/buffering.c
index b35206766b..9c8d107a86 100644
--- a/apps/buffering.c
+++ b/apps/buffering.c
@@ -91,6 +91,8 @@
/* point at which the file buffer will fight for CPU time */
#define BUFFERING_CRITICAL_LEVEL (1024*128)
+#define BUF_HANDLE_MASK 0x7FFFFFFF
+
/* Ring buffer helper macros */
/* Buffer pointer (p) plus value (v), wrapped if necessary */
@@ -224,7 +226,7 @@ static struct memory_handle *add_handle(size_t data_size, const bool can_wrap,
const bool alloc_all)
{
/* gives each handle a unique id */
- static int cur_handle_id = 1;
+ static int cur_handle_id = 0;
size_t shift;
size_t new_widx;
size_t len;
@@ -292,7 +294,7 @@ static struct memory_handle *add_handle(size_t data_size, const bool can_wrap,
new_handle->id = cur_handle_id;
/* Wrap signed int is safe and 0 doesn't happen */
- if (++cur_handle_id < 1) cur_handle_id = 1;
+ cur_handle_id = (cur_handle_id + 1) & BUF_HANDLE_MASK;
new_handle->next = NULL;
num_handles++;
@@ -314,7 +316,7 @@ static struct memory_handle *add_handle(size_t data_size, const bool can_wrap,
static bool rm_handle(const struct memory_handle *h)
{
if (h == NULL)
- return false;
+ return true;
mutex_lock(&llist_mutex);
@@ -359,7 +361,7 @@ static bool rm_handle(const struct memory_handle *h)
NULL if the handle wasn't found */
static struct memory_handle *find_handle(const int handle_id)
{
- if (handle_id <= 0)
+ if (handle_id < 0)
return NULL;
mutex_lock(&llist_mutex);
@@ -664,16 +666,18 @@ static void rebuffer_handle(int handle_id, size_t newpos)
static bool close_handle(int handle_id)
{
struct memory_handle *h = find_handle(handle_id);
+
+ /* If the handle is not found, it is closed */
if (!h)
- return false;
+ return true;
if (h->fd >= 0) {
close(h->fd);
h->fd = -1;
}
- rm_handle(h);
- return true;
+ /* rm_handle returns true unless the handle somehow persists after exit */
+ return rm_handle(h);
}
/* Free buffer space by moving the handle struct right before the useful
@@ -1327,7 +1331,7 @@ bool buffering_reset(char *buf, size_t buflen)
cur_handle = NULL;
cached_handle = NULL;
num_handles = 0;
- base_handle_id = 0;
+ base_handle_id = -1;
buffer_callback_count = 0;
memset(buffer_low_callback_funcs, 0, sizeof(buffer_low_callback_funcs));