summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2004-06-22 11:32:36 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2004-06-22 11:32:36 +0000
commit9830b164ef09277df433be37c2adafe3b078c3d4 (patch)
tree3c5e85352614bbd9bec0bc9150fcf9c600e131d9
parent32fef7a0ca10a09f42d35d957e4dbfcae85d0631 (diff)
downloadrockbox-9830b164ef09277df433be37c2adafe3b078c3d4.tar.gz
rockbox-9830b164ef09277df433be37c2adafe3b078c3d4.zip
switch_thread() now checks the stack of the current thread instead of the next, to report stack errors sooner. I removed some TAB chars in the process.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4792 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/thread.c70
1 files changed, 36 insertions, 34 deletions
diff --git a/firmware/thread.c b/firmware/thread.c
index e7c4606bcc..294359b762 100644
--- a/firmware/thread.c
+++ b/firmware/thread.c
@@ -112,16 +112,18 @@ void switch_thread(void)
#endif
next = current = current_thread;
+
if (++next >= num_threads)
next = 0;
current_thread = next;
store_context(&thread_contexts[current]);
- load_context(&thread_contexts[next]);
-
- stackptr = thread_stack[next];
+ /* Check if the current thread stack is overflown */
+ stackptr = thread_stack[current];
if(stackptr[0] != 0xdeadbeef)
- panicf("Stkov %s", thread_name[next]);
+ panicf("Stkov %s", thread_name[current]);
+
+ load_context(&thread_contexts[next]);
}
void sleep_thread(void)
@@ -142,36 +144,36 @@ void wake_up_thread(void)
*/
int create_thread(void* function, void* stack, int stack_size, char *name)
{
- unsigned int i;
- unsigned int stacklen;
- unsigned int *stackptr;
- struct regs *regs;
+ unsigned int i;
+ unsigned int stacklen;
+ unsigned int *stackptr;
+ struct regs *regs;
- if (num_threads >= MAXTHREADS)
- return -1;
-
- /* Munge the stack to make it easy to spot stack overflows */
- stacklen = stack_size / 4;
- stackptr = stack;
- for(i = 0;i < stacklen;i++)
- {
- stackptr[i] = 0xdeadbeef;
- }
-
- /* Store interesting information */
- thread_name[num_threads] = name;
- thread_stack[num_threads] = stack;
- thread_stack_size[num_threads] = stack_size;
- regs = &thread_contexts[num_threads];
- store_context(regs);
- /* Subtract 4 to leave room for the PR push in load_context()
- Align it on an even 32 bit boundary */
- regs->sp = (void*)(((unsigned int)stack + stack_size - 4) & ~3);
- regs->sr = 0;
- regs->pr = function;
-
- wake_up_thread();
- return num_threads++; /* return the current ID, e.g for remove_thread() */
+ if (num_threads >= MAXTHREADS)
+ return -1;
+
+ /* Munge the stack to make it easy to spot stack overflows */
+ stacklen = stack_size / 4;
+ stackptr = stack;
+ for(i = 0;i < stacklen;i++)
+ {
+ stackptr[i] = 0xdeadbeef;
+ }
+
+ /* Store interesting information */
+ thread_name[num_threads] = name;
+ thread_stack[num_threads] = stack;
+ thread_stack_size[num_threads] = stack_size;
+ regs = &thread_contexts[num_threads];
+ store_context(regs);
+ /* Subtract 4 to leave room for the PR push in load_context()
+ Align it on an even 32 bit boundary */
+ regs->sp = (void*)(((unsigned int)stack + stack_size - 4) & ~3);
+ regs->sr = 0;
+ regs->pr = function;
+
+ wake_up_thread();
+ return num_threads++; /* return the current ID, e.g for remove_thread() */
}
/*---------------------------------------------------------------------------
@@ -222,7 +224,7 @@ int thread_stack_usage(int threadnum)
for(i = 0;i < thread_stack_size[threadnum]/sizeof(int);i++)
{
if(stackptr[i] != 0xdeadbeef)
- break;
+ break;
}
return ((thread_stack_size[threadnum] - i * 4) * 100) /