lwIP: remove dependency on heap module
authorarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Wed, 3 Nov 2010 10:35:07 +0000 (10:35 +0000)
committerarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Wed, 3 Nov 2010 10:35:07 +0000 (10:35 +0000)
lwIP now implements its own thread stacks' allocator if CONFIG_KERN_HEAP
is disabled.

git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4497 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/net/lwip.h
bertos/net/lwip/src/arch/sys_arch.c

index d07e311f56cb1951133e1b735b8500ace502dba4..3f592ff048e85bc45406a77162e4a3556cc8c48a 100644 (file)
@@ -35,7 +35,7 @@
  *
  * $WIZ$ module_name = "lwip"
  * $WIZ$ module_configuration = "bertos/cfg/cfg_lwip.h"
- * $WIZ$ module_depends = "kern", "signal", "msg", "event", "eth", "heap"
+ * $WIZ$ module_depends = "kern", "signal", "msg", "event", "eth"
  */
 
 #ifndef NET_LWIP_H
index 1d314cc3d7e15ec481406ac06f6c56f14db3d2cd..a7feddbd19a795f0e2667128f7d9be4ade7c347b 100644 (file)
@@ -336,10 +336,23 @@ static void thread_trampoline(void)
        thread_node->entry(thread_node->arg);
 }
 
+#if !CONFIG_KERN_HEAP
+/*
+ * NOTE: threads are never destroyed, consequently these stacks are never
+ * deallocated. So, the stack allocator can be implemented as a simple index
+ * that is atomically incremented at each allocation.
+ */
+static cpu_stack_t thread_stack[MAX_THREAD_CNT]
+                       [DEFAULT_THREAD_STACKSIZE / sizeof(cpu_stack_t)]
+                               ALIGNED(sizeof(cpu_stack_t));
+static int last_stack;
+#endif
+
 sys_thread_t sys_thread_new(char *name, void (* thread)(void *arg),
                                void *arg, int stacksize, int prio)
 {
        ThreadNode *thread_node;
+       cpu_stack_t *stackbase;
 
        proc_forbid();
        thread_node = (ThreadNode *)list_remHead(&free_thread);
@@ -354,8 +367,14 @@ sys_thread_t sys_thread_new(char *name, void (* thread)(void *arg),
        thread_node->entry = thread;
        thread_node->arg = arg;
 
+       #if !CONFIG_KERN_HEAP
+               ASSERT(stacksize <= DEFAULT_THREAD_STACKSIZE);
+               PROC_ATOMIC(stackbase = &thread_stack[last_stack++]);
+       #else
+               stackbase = NULL;
+       #endif
        thread_node->pid = proc_new_with_name(name, thread_trampoline,
-                               (void *)thread_node, stacksize, NULL);
+                               (void *)thread_node, stacksize, stackbase);
        if (thread_node->pid == NULL)
                return NULL;