aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2013-12-22 22:44:08 -0500
committerKevin O'Connor <kevin@koconnor.net>2013-12-27 12:40:47 -0500
commit48367e2f1a68608d83207d4398767f8ffc0961f3 (patch)
treee2d486e0abbae9ba4aed889d94a1df506bf287f2
parentb7558a36203aaf08cbe698e6495bf6db096433ec (diff)
downloadseabios-48367e2f1a68608d83207d4398767f8ffc0961f3.zip
seabios-48367e2f1a68608d83207d4398767f8ffc0961f3.tar.gz
seabios-48367e2f1a68608d83207d4398767f8ffc0961f3.tar.bz2
Always perform thread cleanup on MainThread stack.
The thread cleanup was being performed on whatever thread stack was next in the list. However, with high debugging this causes spurious _free() debug messages to show up in random threads which can be confusing when analyzing the debug output. So, always run __end_thread() on the MainThread stack to prevent this confusion. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r--src/stacks.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/stacks.c b/src/stacks.c
index b7d8ade..9c528f5 100644
--- a/src/stacks.c
+++ b/src/stacks.c
@@ -293,13 +293,13 @@ switch_next(struct thread_info *cur)
: "ebx", "edx", "esi", "edi", "cc", "memory");
}
-// Last thing called from a thread (called on "next" stack).
+// Last thing called from a thread (called on MainThread stack).
static void
__end_thread(struct thread_info *old)
{
hlist_del(&old->node);
- free(old);
dprintf(DEBUG_thread, "\\%08x/ End thread\n", (u32)old);
+ free(old);
if (!have_threads())
dprintf(1, "All threads complete.\n");
}
@@ -316,11 +316,10 @@ run_thread(void (*func)(void*), void *data)
if (!thread)
goto fail;
+ dprintf(DEBUG_thread, "/%08x\\ Start thread\n", (u32)thread);
thread->stackpos = (void*)thread + THREADSTACKSIZE;
struct thread_info *cur = getCurThread();
hlist_add_after(&thread->node, &cur->node);
-
- dprintf(DEBUG_thread, "/%08x\\ Start thread\n", (u32)thread);
asm volatile(
// Start thread
" pushl $1f\n" // store return pc
@@ -330,15 +329,16 @@ run_thread(void (*func)(void*), void *data)
" calll *%%ecx\n" // Call func
// End thread
- " movl 4(%%ebx), %%ecx\n" // %ecx = thread->node.next
- " movl -4(%%ecx), %%esp\n" // %esp = next->stackpos
- " movl %%ebx, %%eax\n"
+ " movl %%ebx, %%eax\n" // %eax = thread
+ " movl 4(%%ebx), %%ebx\n" // %ebx = thread->node.next
+ " movl (%5), %%esp\n" // %esp = MainThread.stackpos
" calll %4\n" // call __end_thread(thread)
+ " movl -4(%%ebx), %%esp\n" // %esp = next->stackpos
" popl %%ebp\n" // restore %ebp
" retl\n" // restore pc
"1:\n"
: "+a"(data), "+c"(func), "+b"(thread), "+d"(cur)
- : "m"(*(u8*)__end_thread)
+ : "m"(*(u8*)__end_thread), "m"(MainThread)
: "esi", "edi", "cc", "memory");
return;