1
0
Fork 0
forked from len0rd/rockbox

Make handle id semantics more like file id. This may need to be revisited if we ever start storing long lived things on the buffer (if an item lives through 32k other items coming and going, there will be an id collision and things will break)

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15437 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Brandon Low 2007-11-03 21:13:15 +00:00
parent 60d4e7c9c4
commit acb3e9af22
3 changed files with 38 additions and 56 deletions

View file

@ -105,7 +105,7 @@
/* assert(sizeof(struct memory_handle)%4==0) */
struct memory_handle {
unsigned int id; /* A unique ID for the handle */
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 unsigned int base_handle_id;
static 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 unsigned int cur_handle_id = 1;
static int cur_handle_id = 0;
size_t shift;
size_t new_widx;
size_t len;
@ -291,9 +291,7 @@ 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;
/* 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;
cur_handle_id = (cur_handle_id + 1) & BUF_HANDLE_ID_MASK;
new_handle->next = NULL;
num_handles++;
@ -358,9 +356,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 unsigned int handle_id)
static struct memory_handle *find_handle(const int handle_id)
{
if (handle_id <= 0)
if (handle_id < 0)
return NULL;
mutex_lock(&llist_mutex);
@ -550,7 +548,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 -1;
return false;
if (h->filerem == 0) {
/* nothing left to buffer */
@ -770,7 +768,7 @@ void update_data_counters(void)
{
struct memory_handle *m = find_handle(base_handle_id);
if (!m)
base_handle_id = 0;
base_handle_id = -1;
memset(&data_counters, 0, sizeof(data_counters));
@ -1310,7 +1308,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));