diff options
Diffstat (limited to 'firmware/thread.c')
-rw-r--r-- | firmware/thread.c | 18 |
1 files changed, 11 insertions, 7 deletions
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 | ||
35 | typedef struct | 34 | typedef 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 | */ |
91 | void | 90 | void switch_thread(void) |
92 | switch_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 | |||
127 | void 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 | } | ||