summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2002-06-07 14:56:10 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2002-06-07 14:56:10 +0000
commit9430a0b7d6beeab9c5c5f223ccb4b6d5d2a2ea66 (patch)
tree3b2d166b5b9383e99ca2ab72b1c706f70b91c874 /firmware
parent999c255599d4bf45990a71973770647afc168d4a (diff)
downloadrockbox-9430a0b7d6beeab9c5c5f223ccb4b6d5d2a2ea66.tar.gz
rockbox-9430a0b7d6beeab9c5c5f223ccb4b6d5d2a2ea66.zip
Added init_threads function
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@920 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/kernel.c3
-rw-r--r--firmware/thread.c18
-rw-r--r--firmware/thread.h1
3 files changed, 15 insertions, 7 deletions
diff --git a/firmware/kernel.c b/firmware/kernel.c
index be30d8e56b..3e6f89bc7e 100644
--- a/firmware/kernel.c
+++ b/firmware/kernel.c
@@ -36,6 +36,9 @@ 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++)
{
diff --git a/firmware/thread.c b/firmware/thread.c
index b6e978f743..4da6d9aaf2 100644
--- a/firmware/thread.c
+++ b/firmware/thread.c
@@ -29,12 +29,11 @@ typedef union
unsigned int sr; /* Status register */
void* pr; /* Procedure register */
} regs;
- unsigned int mem[12];
} ctx_t;
typedef struct
{
- int created;
+ int num_threads;
int current;
ctx_t ctx[MAXTHREADS];
} thread_t;
@@ -88,15 +87,14 @@ static inline void ldctx(void* addr)
* Switch thread in round robin fashion.
*---------------------------------------------------------------------------
*/
-void
-switch_thread(void)
+void switch_thread(void)
{
int ct;
int nt;
thread_t* t = &threads;
nt = ct = t->current;
- if (++nt >= t->created)
+ if (++nt >= t->num_threads)
nt = 0;
t->current = nt;
stctx(&t->ctx[ct]);
@@ -112,11 +110,11 @@ int create_thread(void* fp, void* sp, int stk_size)
{
thread_t* t = &threads;
- if (t->created >= MAXTHREADS)
+ if (t->num_threads >= MAXTHREADS)
return -1;
else
{
- ctx_t* ctxp = &t->ctx[t->created++];
+ ctx_t* ctxp = &t->ctx[t->num_threads++];
stctx(ctxp);
/* Subtract 4 to leave room for the PR push in ldctx()
Align it on an even 32 bit boundary */
@@ -125,3 +123,9 @@ int create_thread(void* fp, void* sp, int stk_size)
}
return 0;
}
+
+void init_threads(void)
+{
+ threads.num_threads = 1; /* We have 1 thread to begin with */
+ threads.current = 0; /* The current thread is number 0 */
+}
diff --git a/firmware/thread.h b/firmware/thread.h
index f1f074313c..dd42c8cd35 100644
--- a/firmware/thread.h
+++ b/firmware/thread.h
@@ -23,5 +23,6 @@
int create_thread(void* fp, void* sp, int stk_size);
void switch_thread(void);
+void init_threads(void);
#endif