summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2002-06-29 21:19:55 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2002-06-29 21:19:55 +0000
commit2a73cec69bf7b372377f79ef561985816148b1af (patch)
treef53e50110ff9069c8c2ac4018e2fa4e1444c2c8e
parenteb102e1a239d75f4eaf34398c0dbb29c0bc50c84 (diff)
downloadrockbox-2a73cec69bf7b372377f79ef561985816148b1af.zip
rockbox-2a73cec69bf7b372377f79ef561985816148b1af.tar.gz
rockbox-2a73cec69bf7b372377f79ef561985816148b1af.tar.bz2
rockbox-2a73cec69bf7b372377f79ef561985816148b1af.tar.xz
Added queue_broadcast()
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1253 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/API5
-rw-r--r--firmware/kernel.c29
-rw-r--r--firmware/kernel.h7
3 files changed, 34 insertions, 7 deletions
diff --git a/firmware/API b/firmware/API
index c74aa20..05d7d20 100644
--- a/firmware/API
+++ b/firmware/API
@@ -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
diff --git a/firmware/kernel.c b/firmware/kernel.c
index 3e6f89b..02b76e1 100644
--- a/firmware/kernel.c
+++ b/firmware/kernel.c
@@ -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
diff --git a/firmware/kernel.h b/firmware/kernel.h
index ee9ded7..ef287e5 100644
--- a/firmware/kernel.h
+++ b/firmware/kernel.h
@@ -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);