Add queue_peek to the kernel (written by Mike Sevakis), and use it to improve upon my previous commit.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15336 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Nicolas Pennequin 2007-10-27 18:08:18 +00:00
parent 41add08c5e
commit 1839edf64a
4 changed files with 52 additions and 3 deletions

View file

@ -2569,6 +2569,7 @@ static void low_buffer_callback(void)
static void audio_fill_file_buffer(bool start_play, size_t offset)
{
struct queue_event ev;
bool had_next_track = audio_next_track() != NULL;
bool continue_buffering;
@ -2591,9 +2592,14 @@ static void audio_fill_file_buffer(bool start_play, size_t offset)
start_play = false;
offset = 0;
sleep(1);
if (!queue_empty(&audio_queue)) {
if (queue_peek(&audio_queue, &ev)) {
if (ev.id != Q_AUDIO_FILL_BUFFER)
{
/* There's a message in the queue. break the loop to treat it,
and go back to filling after that. */
LOGFQUEUE("buffering > audio Q_AUDIO_FILL_BUFFER");
queue_post(&audio_queue, Q_AUDIO_FILL_BUFFER, 0);
}
break;
}
} while (continue_buffering);

View file

@ -219,6 +219,7 @@ extern void queue_reply(struct event_queue *q, intptr_t retval);
extern bool queue_in_queue_send(struct event_queue *q);
#endif /* HAVE_EXTENDED_MESSAGING_AND_NAME */
extern bool queue_empty(const struct event_queue* q);
extern bool queue_peek(struct event_queue *q, struct queue_event *ev);
extern void queue_clear(struct event_queue* q);
extern void queue_remove_from_head(struct event_queue *q, long id);
extern int queue_count(const struct event_queue *q);

View file

@ -537,6 +537,28 @@ bool queue_empty(const struct event_queue* q)
return ( q->read == q->write );
}
bool queue_peek(struct event_queue *q, struct queue_event *ev)
{
if (q->read == q->write)
return false;
bool have_msg = false;
int oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL);
corelock_lock(&q->cl);
if (q->read != q->write)
{
*ev = q->events[q->read & QUEUE_LENGTH_MASK];
have_msg = true;
}
corelock_unlock(&q->cl);
set_irq_level(oldlevel);
return have_msg;
}
void queue_clear(struct event_queue* q)
{
int oldlevel;

View file

@ -405,6 +405,26 @@ bool queue_empty(const struct event_queue* q)
return ( q->read == q->write );
}
bool queue_peek(struct event_queue *q, struct queue_event *ev)
{
if (q->read == q->write)
return false;
bool have_msg = false;
int oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL);
if (q->read != q->write)
{
*ev = q->events[q->read & QUEUE_LENGTH_MASK];
have_msg = true;
}
set_irq_level(oldlevel);
return have_msg;
}
void queue_clear(struct event_queue* q)
{
int oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL);