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:
parent
999c255599
commit
9430a0b7d6
3 changed files with 15 additions and 7 deletions
|
@ -36,6 +36,9 @@ void kernel_init(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
/* Init the threading API */
|
||||||
|
init_threads();
|
||||||
|
|
||||||
/* Clear the tick task array */
|
/* Clear the tick task array */
|
||||||
for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
|
for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,12 +29,11 @@ typedef union
|
||||||
unsigned int sr; /* Status register */
|
unsigned int sr; /* Status register */
|
||||||
void* pr; /* Procedure register */
|
void* pr; /* Procedure register */
|
||||||
} regs;
|
} regs;
|
||||||
unsigned int mem[12];
|
|
||||||
} ctx_t;
|
} ctx_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int created;
|
int num_threads;
|
||||||
int current;
|
int current;
|
||||||
ctx_t ctx[MAXTHREADS];
|
ctx_t ctx[MAXTHREADS];
|
||||||
} thread_t;
|
} thread_t;
|
||||||
|
@ -88,15 +87,14 @@ static inline void ldctx(void* addr)
|
||||||
* Switch thread in round robin fashion.
|
* Switch thread in round robin fashion.
|
||||||
*---------------------------------------------------------------------------
|
*---------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
void
|
void switch_thread(void)
|
||||||
switch_thread(void)
|
|
||||||
{
|
{
|
||||||
int ct;
|
int ct;
|
||||||
int nt;
|
int nt;
|
||||||
thread_t* t = &threads;
|
thread_t* t = &threads;
|
||||||
|
|
||||||
nt = ct = t->current;
|
nt = ct = t->current;
|
||||||
if (++nt >= t->created)
|
if (++nt >= t->num_threads)
|
||||||
nt = 0;
|
nt = 0;
|
||||||
t->current = nt;
|
t->current = nt;
|
||||||
stctx(&t->ctx[ct]);
|
stctx(&t->ctx[ct]);
|
||||||
|
@ -112,11 +110,11 @@ int create_thread(void* fp, void* sp, int stk_size)
|
||||||
{
|
{
|
||||||
thread_t* t = &threads;
|
thread_t* t = &threads;
|
||||||
|
|
||||||
if (t->created >= MAXTHREADS)
|
if (t->num_threads >= MAXTHREADS)
|
||||||
return -1;
|
return -1;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ctx_t* ctxp = &t->ctx[t->created++];
|
ctx_t* ctxp = &t->ctx[t->num_threads++];
|
||||||
stctx(ctxp);
|
stctx(ctxp);
|
||||||
/* Subtract 4 to leave room for the PR push in ldctx()
|
/* Subtract 4 to leave room for the PR push in ldctx()
|
||||||
Align it on an even 32 bit boundary */
|
Align it on an even 32 bit boundary */
|
||||||
|
@ -125,3 +123,9 @@ int create_thread(void* fp, void* sp, int stk_size)
|
||||||
}
|
}
|
||||||
return 0;
|
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 */
|
||||||
|
}
|
||||||
|
|
|
@ -23,5 +23,6 @@
|
||||||
|
|
||||||
int create_thread(void* fp, void* sp, int stk_size);
|
int create_thread(void* fp, void* sp, int stk_size);
|
||||||
void switch_thread(void);
|
void switch_thread(void);
|
||||||
|
void init_threads(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue