diff options
| author | Brandon Low <lostlogic@rockbox.org> | 2007-11-03 21:48:08 +0000 |
|---|---|---|
| committer | Brandon Low <lostlogic@rockbox.org> | 2007-11-03 21:48:08 +0000 |
| commit | c2e1cc1e392e819747d1a2ea171937bb530693ea (patch) | |
| tree | 3152814f32da2257374dd5ed7aecc1c7c04b54a5 /apps/buffering.c | |
| parent | 19eae2bd9b38bd42fd3a98da5d4d670d1c0a1694 (diff) | |
| download | rockbox-c2e1cc1e392e819747d1a2ea171937bb530693ea.zip rockbox-c2e1cc1e392e819747d1a2ea171937bb530693ea.tar.gz rockbox-c2e1cc1e392e819747d1a2ea171937bb530693ea.tar.bz2 rockbox-c2e1cc1e392e819747d1a2ea171937bb530693ea.tar.xz | |
Revert recent changes that are broken
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15439 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/buffering.c')
| -rw-r--r-- | apps/buffering.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/apps/buffering.c b/apps/buffering.c index 96c9d61..b92b5d1 100644 --- a/apps/buffering.c +++ b/apps/buffering.c @@ -105,7 +105,7 @@ /* assert(sizeof(struct memory_handle)%4==0) */ struct memory_handle { - int id; /* A unique ID for the handle */ + unsigned int id; /* A unique ID for the handle */ enum data_type type; /* Type of data buffered with this handle */ char path[MAX_PATH]; /* Path if data originated in a file */ int fd; /* File descriptor to path (-1 if closed) */ @@ -146,7 +146,7 @@ static struct memory_handle *first_handle; static int num_handles; /* number of handles in the list */ -static int base_handle_id; +static unsigned int base_handle_id; static struct mutex llist_mutex; @@ -224,7 +224,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, unsigned to handle wraps gracefully */ - static int cur_handle_id = 0; + static unsigned int cur_handle_id = 1; size_t shift; size_t new_widx; size_t len; @@ -291,7 +291,9 @@ static struct memory_handle *add_handle(size_t data_size, const bool can_wrap, buf_widx = RINGBUF_ADD(buf_widx, sizeof(struct memory_handle)); new_handle->id = cur_handle_id; - cur_handle_id = (cur_handle_id + 1) & BUF_HANDLE_ID_MASK; + /* Use += 2 instead of ++ to guarantee that the low bit is always high and + * prevent the assignment of a zero id when wrapping. */ + cur_handle_id += 2; new_handle->next = NULL; num_handles++; @@ -356,9 +358,9 @@ static bool rm_handle(const struct memory_handle *h) /* Return a pointer to the memory handle of given ID. NULL if the handle wasn't found */ -static struct memory_handle *find_handle(const int handle_id) +static struct memory_handle *find_handle(const unsigned int handle_id) { - if (handle_id < 0) + if (handle_id <= 0) return NULL; mutex_lock(&llist_mutex); @@ -548,7 +550,7 @@ static bool buffer_handle(int handle_id) logf("buffer_handle(%d)", handle_id); struct memory_handle *h = find_handle(handle_id); if (!h) - return false; + return -1; if (h->filerem == 0) { /* nothing left to buffer */ @@ -768,7 +770,7 @@ void update_data_counters(void) { struct memory_handle *m = find_handle(base_handle_id); if (!m) - base_handle_id = -1; + base_handle_id = 0; memset(&data_counters, 0, sizeof(data_counters)); @@ -1308,7 +1310,7 @@ bool buffering_reset(char *buf, size_t buflen) cur_handle = NULL; cached_handle = NULL; num_handles = 0; - base_handle_id = -1; + base_handle_id = 0; buffer_callback_count = 0; memset(buffer_low_callback_funcs, 0, sizeof(buffer_low_callback_funcs)); |