[syslinux:lwip] core: thread: have start_thread() allocate memory dynamically
syslinux-bot for H. Peter Anvin
hpa at zytor.com
Fri Apr 22 20:05:05 PDT 2011
Commit-ID: 0c44fcf078132b1f2915b7df9fcf4724f9d96b23
Gitweb: http://syslinux.zytor.com/commit/0c44fcf078132b1f2915b7df9fcf4724f9d96b23
Author: H. Peter Anvin <hpa at zytor.com>
AuthorDate: Wed, 9 Sep 2009 09:07:58 -0700
Committer: Eric W. Biederman <ebiederm at xmission.com>
CommitDate: Fri, 8 Apr 2011 14:41:15 -0700
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 at zytor.com>
---
core/include/thread.h | 4 ++--
core/thread/idle_thread.c | 7 +------
core/thread/start_thread.c | 17 ++++++++++++++---
3 files changed, 17 insertions(+), 11 deletions(-)
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 <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 f07984f..afe7ecf 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;
}
More information about the Syslinux-commits
mailing list