proc_test: use kernel dynamic memory if CONFIG_KERN_HEAP is enabled.
authorarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Thu, 18 Mar 2010 11:49:57 +0000 (11:49 +0000)
committerarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Thu, 18 Mar 2010 11:49:57 +0000 (11:49 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3235 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/kern/proc_test.c

index cb8b4a0d0bcb023cade65a26436a40012f2f60b0..b4f64c6a97a6751e80e52831c6d0d51b4ecd6bff 100644 (file)
@@ -87,21 +87,25 @@ static unsigned int done[TASKS];
 static cpu_atomic_t barrier[TASKS];
 static cpu_atomic_t main_barrier;
 
-#define WORKER_STACK_SIZE KERN_MINSTACKSIZE * 2
-
 /* Base time delay for processes using timer_delay() */
 #define DELAY  5
 
 // Define process stacks for test.
+#define WORKER_STACK_SIZE KERN_MINSTACKSIZE * 2
+
+#if CONFIG_KERN_HEAP
+#define WORKER_STACK(id)        NULL
+#else /* !CONFIG_KERN_HEAP */
 static cpu_stack_t worker_stack[TASKS][(WORKER_STACK_SIZE +
                        sizeof(cpu_stack_t) - 1) / sizeof(cpu_stack_t)];
+#define WORKER_STACK(id)        (&worker_stack[id][0])
+#endif /* CONFIG_KERN_HEAP */
 
 static int prime_numbers[] =
 {
        1, 3, 5, 7, 11, 13, 17, 19,
        23, 29, 31, 37, 41, 43, 47, 53,
 };
-
 STATIC_ASSERT(TASKS <= countof(prime_numbers));
 
 #if CONFIG_KERN_PREEMPT
@@ -159,7 +163,7 @@ static int worker_test(void)
                snprintf(&name[i][0], sizeof(name[i]), "worker_%zd", i + 1);
                name[i][sizeof(name[i]) - 1] = '\0';
                proc_new_with_name(name[i], worker, (iptr_t)(i + 1),
-                               WORKER_STACK_SIZE, &worker_stack[i][0]);
+                               WORKER_STACK_SIZE, WORKER_STACK(i));
        }
        /* Synchronize on start */
        while (1)
@@ -239,7 +243,7 @@ static int preempt_worker_test(void)
                                "preempt_worker_%zd", i + 1);
                name[i][sizeof(name[i]) - 1] = '\0';
                proc_new_with_name(name[i], preempt_worker, (iptr_t)(i + 1),
-                               WORKER_STACK_SIZE, &worker_stack[i][0]);
+                               WORKER_STACK_SIZE, WORKER_STACK(i));
        }
        kputs("> Main: Processes created\n");
        /* Synchronize on start */
@@ -283,8 +287,6 @@ static int preempt_worker_test(void)
 
 #if CONFIG_KERN_SIGNALS & CONFIG_KERN_PRI
 
-#define PROC_PRI_TEST_STACK(num)  PROC_DEFINE_STACK(proc_test##num##_stack, KERN_MINSTACKSIZE);
-
 // Define params to test priority
 #define PROC_PRI_TEST(num) static void proc_pri_test##num(void) \
 { \
@@ -297,15 +299,11 @@ static int preempt_worker_test(void)
 #define PROC_PRI_TEST_INIT(num, proc)                                  \
 do {                                                                   \
        struct Process *p = proc_new(proc_pri_test##num, (proc),        \
-                                       sizeof(proc_test##num##_stack), \
-                                       proc_test##num##_stack);        \
+                                       WORKER_STACK_SIZE,              \
+                                       WORKER_STACK(num));             \
        proc_setPri(p, num + 1);                                        \
 } while (0)
 
-PROC_PRI_TEST_STACK(0)
-PROC_PRI_TEST_STACK(1)
-PROC_PRI_TEST_STACK(2)
-
 PROC_PRI_TEST(0)
 PROC_PRI_TEST(1)
 PROC_PRI_TEST(2)