aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2009-09-09 09:07:58 -0700
committerH. Peter Anvin <hpa@zytor.com>2009-09-09 09:07:58 -0700
commit521fca8a9a15445a0bda1d053cd167940bf9b24e (patch)
tree77e0525781a4b24ff0bc94e2ad1b6573b42d4696
parent0785d12409b73cad87d02cac735f7cbb79580201 (diff)
downloadlwip-521fca8a9a15445a0bda1d053cd167940bf9b24e.tar.gz
lwip-521fca8a9a15445a0bda1d053cd167940bf9b24e.tar.xz
lwip-521fca8a9a15445a0bda1d053cd167940bf9b24e.zip
core: thread: have start_thread() allocate memory dynamically
Have start_thread() allocate memory dynamically, using malloc(). XXX: should probably free that memory in __exit_thread()... could be "interesting". Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--core/include/thread.h4
-rw-r--r--core/thread/idle_thread.c7
-rw-r--r--core/thread/start_thread.c17
-rw-r--r--core/thread/timeout.c2
4 files changed, 18 insertions, 12 deletions
diff --git a/core/include/thread.h b/core/include/thread.h
index bba92d7c..3b34e154 100644
--- a/core/include/thread.h
+++ b/core/include/thread.h
@@ -73,8 +73,8 @@ static inline void irq_restore(irq_state_t __st)
asm volatile("pushl %0 ; popfl" : : "rm" (__st));
}
-void start_thread(struct thread *t, void *stack, size_t stack_size, int prio,
- void (*start_func)(void *), void *func_arg);
+struct thread *start_thread(size_t stack_size, int prio,
+ void (*start_func)(void *), void *func_arg);
void __exit_thread(void);
void kill_thread(struct thread *);
diff --git a/core/thread/idle_thread.c b/core/thread/idle_thread.c
index 8a319ff4..5c79e316 100644
--- a/core/thread/idle_thread.c
+++ b/core/thread/idle_thread.c
@@ -2,10 +2,6 @@
#include <limits.h>
#include <sys/cpu.h>
-static struct thread idle_thread;
-
-static char idle_thread_stack[4096];
-
static void idle_thread_func(void *dummy)
{
(void)dummy;
@@ -19,7 +15,6 @@ static void idle_thread_func(void *dummy)
void start_idle_thread(void)
{
- start_thread(&idle_thread, idle_thread_stack, sizeof idle_thread_stack,
- INT_MAX, idle_thread_func, NULL);
+ start_thread(4096, INT_MAX, idle_thread_func, NULL);
}
diff --git a/core/thread/start_thread.c b/core/thread/start_thread.c
index f07984ff..afe7ecfb 100644
--- a/core/thread/start_thread.c
+++ b/core/thread/start_thread.c
@@ -1,13 +1,23 @@
#include <string.h>
+#include <stdlib.h>
#include "thread.h"
extern void (*__start_thread)(void);
-void start_thread(struct thread *t, void *stack, size_t stack_size, int prio,
- void (*start_func)(void *), void *func_arg)
+struct thread *start_thread(size_t stack_size, int prio,
+ void (*start_func)(void *), void *func_arg)
{
irq_state_t irq;
- struct thread *curr;
+ struct thread *curr, *t;
+ char *stack;
+ const size_t thread_mask = __alignof__(struct thread)-1;
+
+ stack_size = (stack_size + thread_mask) & ~thread_mask;
+ stack = malloc(stack_size + sizeof(struct thread));
+ if (!stack)
+ return NULL;
+
+ t = (struct thread *)(stack + stack_size);
memset(t, 0, sizeof *t);
@@ -30,4 +40,5 @@ void start_thread(struct thread *t, void *stack, size_t stack_size, int prio,
__schedule();
irq_restore(irq);
+ return t;
}
diff --git a/core/thread/timeout.c b/core/thread/timeout.c
index ff01ebe5..05f5352d 100644
--- a/core/thread/timeout.c
+++ b/core/thread/timeout.c
@@ -24,7 +24,7 @@ void __thread_process_timeouts(void)
for (tp = curr->list.next; tp != &curr->list; tp = tp->next) {
t = container_of(tp, struct thread, list);
if ((block = t->blocked) && (timeout = block->timeout)) {
- if ((signed int)(timeout - now) <= 0) {
+ if ((sjiffies_t)(timeout - now) <= 0) {
struct semaphore *sem = block->semaphore;
/* Remove us from the queue and increase the count */
block->list.next->prev = block->list.prev;