From 9430a0b7d6beeab9c5c5f223ccb4b6d5d2a2ea66 Mon Sep 17 00:00:00 2001 From: Linus Nielsen Feltzing Date: Fri, 7 Jun 2002 14:56:10 +0000 Subject: Added init_threads function git-svn-id: svn://svn.rockbox.org/rockbox/trunk@920 a1c6a512-1295-4272-9138-f99709370657 --- firmware/kernel.c | 3 +++ firmware/thread.c | 18 +++++++++++------- firmware/thread.h | 1 + 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 -- cgit v1.2.3