aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2013-06-08 22:11:07 -0400
committerKevin O'Connor <kevin@koconnor.net>2013-06-08 22:11:07 -0400
commit2a8633f548a221630dfdc069cb90791962367b3c (patch)
treea7e052508df9c75afbd30986dcbd68878df24606
parent3cf301fd8c12785e90d654c711eacd18b752e505 (diff)
downloadseabios-2a8633f548a221630dfdc069cb90791962367b3c.tar.gz
Introduce helper function have_threads() in stacks.c.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r--src/stacks.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/stacks.c b/src/stacks.c
index bf9db06..65f2c99 100644
--- a/src/stacks.c
+++ b/src/stacks.c
@@ -248,6 +248,13 @@ struct thread_info MainThread VARFSEG = {
};
#define THREADSTACKSIZE 4096
+// Check if any threads are running.
+static int
+have_threads(void)
+{
+ return CONFIG_THREADS && GET_FLATPTR(MainThread.next) != &MainThread;
+}
+
// Return the 'struct thread_info' for the currently running thread.
struct thread_info *
getCurThread(void)
@@ -287,7 +294,7 @@ __end_thread(struct thread_info *old)
*old->pprev = old->next;
free(old);
dprintf(DEBUG_thread, "\\%08x/ End thread\n", (u32)old);
- if (MainThread.next == &MainThread)
+ if (!have_threads())
dprintf(1, "All threads complete.\n");
}
@@ -384,7 +391,7 @@ yield_toirq(void)
stack_hop_back(0, 0, wait_irq);
return;
}
- if (CONFIG_THREADS && MainThread.next != &MainThread) {
+ if (have_threads()) {
// Threads still active - do a yield instead.
yield();
return;
@@ -398,9 +405,7 @@ void
wait_threads(void)
{
ASSERT32FLAT();
- if (! CONFIG_THREADS)
- return;
- while (MainThread.next != &MainThread)
+ while (have_threads())
yield();
}
@@ -480,10 +485,7 @@ yield_preempt(void)
void
check_preempt(void)
{
- if (! CONFIG_THREAD_OPTIONROMS || !GET_GLOBAL(CanPreempt)
- || GET_FLATPTR(MainThread.next) == &MainThread)
- return;
-
extern void _cfunc32flat_yield_preempt(void);
- call32(_cfunc32flat_yield_preempt, 0, 0);
+ if (CONFIG_THREAD_OPTIONROMS && GET_GLOBAL(CanPreempt) && have_threads())
+ call32(_cfunc32flat_yield_preempt, 0, 0);
}