Rockbox.org home
release
dev builds
extras
themes manual
wiki
device status forums
mailing lists
IRC bugs
patches
dev guide
translations



Rockbox mail archive

Subject: peeking at the keys

peeking at the keys

From: TP Diffenbach <rockbox_at_diffenbach.org>
Date: Sun, 27 Jul 2003 19:12:30 -0400

I want to peek at the keys, without actually using up a keypress. get_button is
written in terms of queue_wait, which advances the queue->read pointer:

button.c, line 168:
int button_get(bool block)
{
    struct event ev;

    if ( block || !queue_empty(&button_queue) ) {
        queue_wait(&button_queue, &ev);
        return ev.id;
    }
    return BUTTON_NONE;
}

kernal.c, line 97:
void queue_wait(struct event_queue *q, struct event *ev)
{
    while(q->read == q->write)
    {
        sleep_thread();
    }
    wake_up_thread();

    *ev = q->events[(q->read++) & QUEUE_LENGTH_MASK];
}

I've written a version of queue_wait that does everything queue_wait does EXCEPT
increment read, and that seems to work.

But if queue_wait can stand the time overhead of a function call, it might make
sense to implement queue_read in terms of queue_read_peek:

void queue_wait(struct event_queue *q, struct event *ev)
{
  queue_wait_peek( q, ve ) ;
  ++q->read ;
}

or (with the overhead of an extra operation) implement queue_wait_peek in terms of
queue_wait:
void queue_wait_peek(struct event_queue *q, struct event *ev)
{
  queue_wait( q, ve ) ;
  --q->read ;
}

Since queue_wait is called more often, it seems better to implement _peek in terms
of queue_wait, but I await your advice.

-- 
Archos FM has a Rockbox!
Received on 2003-07-28

Page template was last modified "Tue Sep 7 00:00:02 2021" The Rockbox Crew -- Privacy Policy