From: H. Peter Anvin Date: Wed, 9 Sep 2009 16:07:58 +0000 (-0700) Subject: core: thread: have start_thread() allocate memory dynamically X-Git-Tag: syslinux-4.10-pre1~81 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0c44fcf078132b1f2915b7df9fcf4724f9d96b23;p=platform%2Fupstream%2Fsyslinux.git 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 --- diff --git a/core/include/thread.h b/core/include/thread.h index 917c36a..514c30b 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 8a319ff..5c79e31 100644 --- a/core/thread/idle_thread.c +++ b/core/thread/idle_thread.c @@ -2,10 +2,6 @@ #include #include -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 f07984f..afe7ecf 100644 --- a/core/thread/start_thread.c +++ b/core/thread/start_thread.c @@ -1,13 +1,23 @@ #include +#include #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; }