1
0
Fork 0
forked from len0rd/rockbox

Added init_threads function

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@920 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Linus Nielsen Feltzing 2002-06-07 14:56:10 +00:00
parent 999c255599
commit 9430a0b7d6
3 changed files with 15 additions and 7 deletions

View file

@ -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++)
{

View file

@ -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 */
}

View file

@ -23,5 +23,6 @@
int create_thread(void* fp, void* sp, int stk_size);
void switch_thread(void);
void init_threads(void);
#endif