summaryrefslogtreecommitdiff
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)
36{ 36{
37 int i; 37 int i;
38 38
39 /* Init the threading API */
40 init_threads();
41
39 /* Clear the tick task array */ 42 /* Clear the tick task array */
40 for(i = 0;i < MAX_NUM_TICK_TASKS;i++) 43 for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
41 { 44 {
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
29 unsigned int sr; /* Status register */ 29 unsigned int sr; /* Status register */
30 void* pr; /* Procedure register */ 30 void* pr; /* Procedure register */
31 } regs; 31 } regs;
32 unsigned int mem[12];
33} ctx_t; 32} ctx_t;
34 33
35typedef struct 34typedef struct
36{ 35{
37 int created; 36 int num_threads;
38 int current; 37 int current;
39 ctx_t ctx[MAXTHREADS]; 38 ctx_t ctx[MAXTHREADS];
40} thread_t; 39} thread_t;
@@ -88,15 +87,14 @@ static inline void ldctx(void* addr)
88 * Switch thread in round robin fashion. 87 * Switch thread in round robin fashion.
89 *--------------------------------------------------------------------------- 88 *---------------------------------------------------------------------------
90 */ 89 */
91void 90void switch_thread(void)
92switch_thread(void)
93{ 91{
94 int ct; 92 int ct;
95 int nt; 93 int nt;
96 thread_t* t = &threads; 94 thread_t* t = &threads;
97 95
98 nt = ct = t->current; 96 nt = ct = t->current;
99 if (++nt >= t->created) 97 if (++nt >= t->num_threads)
100 nt = 0; 98 nt = 0;
101 t->current = nt; 99 t->current = nt;
102 stctx(&t->ctx[ct]); 100 stctx(&t->ctx[ct]);
@@ -112,11 +110,11 @@ int create_thread(void* fp, void* sp, int stk_size)
112{ 110{
113 thread_t* t = &threads; 111 thread_t* t = &threads;
114 112
115 if (t->created >= MAXTHREADS) 113 if (t->num_threads >= MAXTHREADS)
116 return -1; 114 return -1;
117 else 115 else
118 { 116 {
119 ctx_t* ctxp = &t->ctx[t->created++]; 117 ctx_t* ctxp = &t->ctx[t->num_threads++];
120 stctx(ctxp); 118 stctx(ctxp);
121 /* Subtract 4 to leave room for the PR push in ldctx() 119 /* Subtract 4 to leave room for the PR push in ldctx()
122 Align it on an even 32 bit boundary */ 120 Align it on an even 32 bit boundary */
@@ -125,3 +123,9 @@ int create_thread(void* fp, void* sp, int stk_size)
125 } 123 }
126 return 0; 124 return 0;
127} 125}
126
127void init_threads(void)
128{
129 threads.num_threads = 1; /* We have 1 thread to begin with */
130 threads.current = 0; /* The current thread is number 0 */
131}
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 @@
23 23
24int create_thread(void* fp, void* sp, int stk_size); 24int create_thread(void* fp, void* sp, int stk_size);
25void switch_thread(void); 25void switch_thread(void);
26void init_threads(void);
26 27
27#endif 28#endif