1
0
Fork 0
forked from len0rd/rockbox

Added queue_broadcast()

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1253 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Linus Nielsen Feltzing 2002-06-29 21:19:55 +00:00
parent eb102e1a23
commit 2a73cec69b
3 changed files with 34 additions and 7 deletions

View file

@ -238,6 +238,11 @@ Various
Returns true if the queue is empty.
int queue_broadcast(int id, void *data)
Posts an event in all queues that has been initiated with queue_init().
Returns the number of queues that were posted to.
int tick_add_task(void (*f)(void))
Add a task to the tick task queue. The argument is a pointer to a

View file

@ -29,21 +29,22 @@ void (*tick_funcs[MAX_NUM_TICK_TASKS])(void);
static void tick_start(unsigned int interval_in_ms);
/* This array holds all queues that are initiated. It is used for broadcast. */
static struct event_queue *all_queues[32];
static int num_queues;
/****************************************************************************
* Standard kernel stuff
****************************************************************************/
void kernel_init(void)
{
int i;
/* Init the threading API */
init_threads();
/* Clear the tick task array */
for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
{
tick_funcs[i] = NULL;
}
memset(tick_funcs, 0, sizeof(tick_funcs));
num_queues = 0;
memset(all_queues, 0, sizeof(all_queues));
tick_start(1000/HZ);
}
@ -82,6 +83,9 @@ void queue_init(struct event_queue *q)
{
q->read = 0;
q->write = 0;
/* Add it to the all_queues array */
all_queues[num_queues++] = q;
}
void queue_wait(struct event_queue *q, struct event *ev)
@ -112,6 +116,17 @@ bool queue_empty(struct event_queue* q)
return ( q->read == q->write );
}
int queue_broadcast(int id, void *data)
{
int i;
for(i = 0;i < num_queues;i++)
{
queue_post(all_queues[i], id, data);
}
return num_queues;
}
/****************************************************************************
* Timer tick

View file

@ -32,6 +32,12 @@
#define QUEUE_LENGTH 16 /* MUST be a power of 2 */
#define QUEUE_LENGTH_MASK (QUEUE_LENGTH - 1)
/* System defined message ID's */
#define SYS_USB_CONNECTED -1
#define SYS_USB_CONNECTED_ACK -2
#define SYS_USB_DISCONNECTED -3
#define SYS_USB_DISCONNECTED_ACK -4
struct event
{
int id;
@ -65,6 +71,7 @@ extern void queue_init(struct event_queue *q);
extern void queue_wait(struct event_queue *q, struct event *ev);
extern void queue_post(struct event_queue *q, int id, void *data);
extern bool queue_empty(struct event_queue* q);
extern int queue_broadcast(int id, void *data);
extern void mutex_init(struct mutex *m);
extern void mutex_lock(struct mutex *m);