aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2008-09-22 15:29:48 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2008-09-22 15:29:48 +0000
commit9a1c91e6ee9baaee3529e16fc732cbd9c7e99844 (patch)
tree5916995c67730dc328d2bd40392f6d21c3a54c7e
parent9b2c9869dd0f5b544d6f1c43c2abea30e5a27b94 (diff)
downloadChibiOS-9a1c91e6ee9baaee3529e16fc732cbd9c7e99844.tar.gz
ChibiOS-9a1c91e6ee9baaee3529e16fc732cbd9c7e99844.tar.bz2
ChibiOS-9a1c91e6ee9baaee3529e16fc732cbd9c7e99844.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@437 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r--demos/ARM7-AT91SAM7X-GCC/chconf.h6
-rw-r--r--demos/ARM7-AT91SAM7X-WEB-GCC/chconf.h6
-rw-r--r--demos/ARM7-LPC214x-G++/chconf.h6
-rw-r--r--demos/ARM7-LPC214x-GCC-minimal/chconf.h6
-rw-r--r--demos/ARM7-LPC214x-GCC/chconf.h6
-rw-r--r--demos/ARMCM3-STM32F103-GCC/chconf.h6
-rw-r--r--demos/AVR-AT90CANx-GCC/chconf.h6
-rw-r--r--demos/AVR-ATmega128-GCC/chconf.h6
-rw-r--r--demos/MSP430-MSP430x1611-GCC/chconf.h6
-rw-r--r--demos/Win32-MinGW/chconf.h6
-rw-r--r--docs/Doxyfile3
-rw-r--r--readme.txt15
-rw-r--r--src/chinit.c6
-rw-r--r--src/chthreads.c169
-rw-r--r--src/include/ch.h4
-rw-r--r--src/include/threads.h28
-rw-r--r--src/templates/chconf.h6
-rw-r--r--test/testmsg.c2
-rw-r--r--test/testmtx.c26
-rw-r--r--test/testrdy.c20
-rw-r--r--test/testsem.c10
21 files changed, 283 insertions, 66 deletions
diff --git a/demos/ARM7-AT91SAM7X-GCC/chconf.h b/demos/ARM7-AT91SAM7X-GCC/chconf.h
index 57cc9d013..13c3766e4 100644
--- a/demos/ARM7-AT91SAM7X-GCC/chconf.h
+++ b/demos/ARM7-AT91SAM7X-GCC/chconf.h
@@ -147,6 +147,12 @@
* are included in the kernel.*/
#define CH_USE_MEMPOOLS
+/** Configuration option: if specified then the dynamic objects creation APIs
+ * are included in the kernel.
+ * @note requires \p CH_USE_WAITEXIT.
+ */
+#define CH_USE_DYNAMIC
+
/** Configuration option: Frequency of the system timer that drives the system
* ticks. This also defines the system time unit.*/
#define CH_FREQUENCY 1000
diff --git a/demos/ARM7-AT91SAM7X-WEB-GCC/chconf.h b/demos/ARM7-AT91SAM7X-WEB-GCC/chconf.h
index 57cc9d013..13c3766e4 100644
--- a/demos/ARM7-AT91SAM7X-WEB-GCC/chconf.h
+++ b/demos/ARM7-AT91SAM7X-WEB-GCC/chconf.h
@@ -147,6 +147,12 @@
* are included in the kernel.*/
#define CH_USE_MEMPOOLS
+/** Configuration option: if specified then the dynamic objects creation APIs
+ * are included in the kernel.
+ * @note requires \p CH_USE_WAITEXIT.
+ */
+#define CH_USE_DYNAMIC
+
/** Configuration option: Frequency of the system timer that drives the system
* ticks. This also defines the system time unit.*/
#define CH_FREQUENCY 1000
diff --git a/demos/ARM7-LPC214x-G++/chconf.h b/demos/ARM7-LPC214x-G++/chconf.h
index 292074816..3bf626af0 100644
--- a/demos/ARM7-LPC214x-G++/chconf.h
+++ b/demos/ARM7-LPC214x-G++/chconf.h
@@ -147,6 +147,12 @@
* are included in the kernel.*/
#define CH_USE_MEMPOOLS
+/** Configuration option: if specified then the dynamic objects creation APIs
+ * are included in the kernel.
+ * @note requires \p CH_USE_WAITEXIT.
+ */
+#define CH_USE_DYNAMIC
+
/** Configuration option: Frequency of the system timer that drives the system
* ticks. This also defines the system time unit.*/
#define CH_FREQUENCY 1000
diff --git a/demos/ARM7-LPC214x-GCC-minimal/chconf.h b/demos/ARM7-LPC214x-GCC-minimal/chconf.h
index 206272504..da927fe6a 100644
--- a/demos/ARM7-LPC214x-GCC-minimal/chconf.h
+++ b/demos/ARM7-LPC214x-GCC-minimal/chconf.h
@@ -147,6 +147,12 @@
* are included in the kernel.*/
//#define CH_USE_MEMPOOLS
+/** Configuration option: if specified then the dynamic objects creation APIs
+ * are included in the kernel.
+ * @note requires \p CH_USE_WAITEXIT.
+ */
+//#define CH_USE_DYNAMIC
+
/** Configuration option: Frequency of the system timer that drives the system
* ticks. This also defines the system time unit.*/
#define CH_FREQUENCY 1000
diff --git a/demos/ARM7-LPC214x-GCC/chconf.h b/demos/ARM7-LPC214x-GCC/chconf.h
index 57cc9d013..13c3766e4 100644
--- a/demos/ARM7-LPC214x-GCC/chconf.h
+++ b/demos/ARM7-LPC214x-GCC/chconf.h
@@ -147,6 +147,12 @@
* are included in the kernel.*/
#define CH_USE_MEMPOOLS
+/** Configuration option: if specified then the dynamic objects creation APIs
+ * are included in the kernel.
+ * @note requires \p CH_USE_WAITEXIT.
+ */
+#define CH_USE_DYNAMIC
+
/** Configuration option: Frequency of the system timer that drives the system
* ticks. This also defines the system time unit.*/
#define CH_FREQUENCY 1000
diff --git a/demos/ARMCM3-STM32F103-GCC/chconf.h b/demos/ARMCM3-STM32F103-GCC/chconf.h
index 57cc9d013..13c3766e4 100644
--- a/demos/ARMCM3-STM32F103-GCC/chconf.h
+++ b/demos/ARMCM3-STM32F103-GCC/chconf.h
@@ -147,6 +147,12 @@
* are included in the kernel.*/
#define CH_USE_MEMPOOLS
+/** Configuration option: if specified then the dynamic objects creation APIs
+ * are included in the kernel.
+ * @note requires \p CH_USE_WAITEXIT.
+ */
+#define CH_USE_DYNAMIC
+
/** Configuration option: Frequency of the system timer that drives the system
* ticks. This also defines the system time unit.*/
#define CH_FREQUENCY 1000
diff --git a/demos/AVR-AT90CANx-GCC/chconf.h b/demos/AVR-AT90CANx-GCC/chconf.h
index eca46b974..a3c3697af 100644
--- a/demos/AVR-AT90CANx-GCC/chconf.h
+++ b/demos/AVR-AT90CANx-GCC/chconf.h
@@ -147,6 +147,12 @@
* are included in the kernel.*/
#define CH_USE_MEMPOOLS
+/** Configuration option: if specified then the dynamic objects creation APIs
+ * are included in the kernel.
+ * @note requires \p CH_USE_WAITEXIT.
+ */
+#define CH_USE_DYNAMIC
+
/** Configuration option: Frequency of the system timer that drives the system
* ticks. This also defines the system time unit.*/
#define CH_FREQUENCY 1000
diff --git a/demos/AVR-ATmega128-GCC/chconf.h b/demos/AVR-ATmega128-GCC/chconf.h
index c44cd39d5..f3975e8a4 100644
--- a/demos/AVR-ATmega128-GCC/chconf.h
+++ b/demos/AVR-ATmega128-GCC/chconf.h
@@ -147,6 +147,12 @@
* are included in the kernel.*/
#define CH_USE_MEMPOOLS
+/** Configuration option: if specified then the dynamic objects creation APIs
+ * are included in the kernel.
+ * @note requires \p CH_USE_WAITEXIT.
+ */
+#define CH_USE_DYNAMIC
+
/** Configuration option: Frequency of the system timer that drives the system
* ticks. This also defines the system time unit.*/
#define CH_FREQUENCY 1000
diff --git a/demos/MSP430-MSP430x1611-GCC/chconf.h b/demos/MSP430-MSP430x1611-GCC/chconf.h
index 0d1773a6a..40a333f1c 100644
--- a/demos/MSP430-MSP430x1611-GCC/chconf.h
+++ b/demos/MSP430-MSP430x1611-GCC/chconf.h
@@ -148,6 +148,12 @@
* are included in the kernel.*/
#define CH_USE_MEMPOOLS
+/** Configuration option: if specified then the dynamic objects creation APIs
+ * are included in the kernel.
+ * @note requires \p CH_USE_WAITEXIT.
+ */
+#define CH_USE_DYNAMIC
+
/** Configuration option: Frequency of the system timer that drives the system
* ticks. This also defines the system time unit.*/
#define CH_FREQUENCY 1000
diff --git a/demos/Win32-MinGW/chconf.h b/demos/Win32-MinGW/chconf.h
index b52281cfa..c5bbf0410 100644
--- a/demos/Win32-MinGW/chconf.h
+++ b/demos/Win32-MinGW/chconf.h
@@ -148,6 +148,12 @@
* are included in the kernel.*/
#define CH_USE_MEMPOOLS
+/** Configuration option: if specified then the dynamic objects creation APIs
+ * are included in the kernel.
+ * @note requires \p CH_USE_WAITEXIT.
+ */
+#define CH_USE_DYNAMIC
+
/** Configuration option: Frequency of the system timer that drives the system
* ticks. This also defines the system time unit.*/
#define CH_FREQUENCY 1000
diff --git a/docs/Doxyfile b/docs/Doxyfile
index 4e317e174..3abb12ff1 100644
--- a/docs/Doxyfile
+++ b/docs/Doxyfile
@@ -260,7 +260,8 @@ PREDEFINED = __JUST_STUBS__ \
CH_USE_MESSAGES_EVENT \
CH_USE_MESSAGES_PRIORITY \
CH_USE_DEBUG \
- CH_USE_TRACE
+ CH_USE_TRACE \
+ CH_USE_DYNAMIC
EXPAND_AS_DEFINED =
SKIP_FUNCTION_MACROS = YES
#---------------------------------------------------------------------------
diff --git a/readme.txt b/readme.txt
index f68d6979a..446995854 100644
--- a/readme.txt
+++ b/readme.txt
@@ -75,13 +75,16 @@ Win32-MinGW - ChibiOS/RT simulator and demo into a WIN32 process,
*****************************************************************************
*** 0.7.1 ***
-- NEW: New chThdInit() API, this API allows to quickly create threads in the
- PRSUSPENDED state. This API also allows to start threads from interrupt
- handlers.
-- CHANGE: The chThdCreate() API no more has the mode parameter, a different
- API is now used in order to start suspended threads.
+- NEW: New chThdInit() and chThdCreateStatic() APIs now replace the old
+ chThdCreate() and chThdCreateFast() that are marked as deprecated.
+ The new APIs use one less parameter and are faster.
+- NEW: New dynamic chThdCreateFromHeap() and chthdCreateFromMemoryPool() APIs.
+ The dynamic APIs are only included if the CH_USE_DYNAMIC option is specified
+ into the project configuration file.
- FIX: The chThdCreate() had a regression in 0.7.0, the mode parameter was
- ignored. Note that in this version the mode parameter had been removed.
+ ignored. Note that in this version the API is deprecated and the bug
+ documented as correct behavior. If you need to create a suspended thread
+ please use the new chThdInit() API.
*** 0.7.0 ***
- NEW: Memory Heap Allocator functionality added. The allocator implements a
diff --git a/src/chinit.c b/src/chinit.c
index 0063fa458..0d4aafea1 100644
--- a/src/chinit.c
+++ b/src/chinit.c
@@ -49,7 +49,7 @@ void chSysInit(void) {
/*
* Now this instructions flow becomes the main thread.
*/
- init_thread(NORMALPRIO, &mainthread);
+ init_thread(&mainthread, NORMALPRIO);
mainthread.p_state = PRCURR;
currp = &mainthread;
@@ -61,8 +61,8 @@ void chSysInit(void) {
* serve interrupts in its context while keeping the lowest energy saving
* mode compatible with the system status.
*/
- chThdCreateFast(IDLEPRIO, waIdleThread, sizeof(waIdleThread),
- (tfunc_t)_IdleThread);
+ chThdCreateStatic(waIdleThread, sizeof(waIdleThread),
+ IDLEPRIO, (tfunc_t)_IdleThread, NULL);
}
/**
diff --git a/src/chthreads.c b/src/chthreads.c
index e98bb725f..f4d355a4b 100644
--- a/src/chthreads.c
+++ b/src/chthreads.c
@@ -27,7 +27,7 @@
/*
* Initializes a thread structure.
*/
-void init_thread(tprio_t prio, Thread *tp) {
+void init_thread(Thread *tp, tprio_t prio) {
static tid_t nextid = 0;
tp->p_tid = nextid++;
@@ -83,8 +83,8 @@ static void memfill(uint8_t *p, uint32_t n, uint8_t v) {
* @note This function can be used to start a thead from within an interrupt
* handler by manually making it ready with \p chSchReadyI().
*/
-Thread *chThdInit(tprio_t prio, void *workspace,
- size_t wsize, tfunc_t pf, void *arg) {
+Thread *chThdInit(void *workspace, size_t wsize,
+ tprio_t prio, tfunc_t pf, void *arg) {
/* thread structure is layed out in the lower part of the thread workspace */
Thread *tp = workspace;
@@ -95,17 +95,17 @@ Thread *chThdInit(tprio_t prio, void *workspace,
memfill(workspace, wsize, MEM_FILL_PATTERN);
#endif
SETUP_CONTEXT(workspace, wsize, pf, arg);
- init_thread(prio, tp);
+ init_thread(tp, prio);
return tp;
}
/**
- * Creates a new thread.
+ * Creates a new thread into a static memory area.
+ * @param workspace pointer to a working area dedicated to the thread stack
+ * @param wsize size of the working area.
* @param prio the priority level for the new thread. Usually the threads are
* created with priority \p NORMALPRIO, priorities
* can range from \p LOWPRIO to \p HIGHPRIO.
- * @param workspace pointer to a working area dedicated to the thread stack
- * @param wsize size of the working area.
* @param pf the thread function. Returning from this function automatically
* terminates the thread.
* @param arg an argument passed to the thread function. It can be \p NULL.
@@ -114,16 +114,113 @@ Thread *chThdInit(tprio_t prio, void *workspace,
* @note A thread can terminate by calling \p chThdExit() or by simply
* returning from its main function.
*/
-Thread *chThdCreate(tprio_t prio, void *workspace,
- size_t wsize, tfunc_t pf, void *arg) {
+Thread *chThdCreateStatic(void *workspace, size_t wsize,
+ tprio_t prio, tfunc_t pf, void *arg) {
- Thread *tp = chThdInit(prio, workspace, wsize, pf, arg);
+ Thread *tp = chThdInit(workspace, wsize, prio, pf, arg);
chSysLock();
chSchWakeupS(tp, RDY_OK);
chSysUnlock();
return tp;
}
+#if defined(CH_USE_DYNAMIC) && defined(CH_USE_WAITEXIT) && defined(CH_USE_HEAP)
+/**
+ * Creates a new thread allocating the memory from the heap.
+ * @param wsize size of the working area to be allocated
+ * @param prio the priority level for the new thread. Usually the threads are
+ * created with priority \p NORMALPRIO, priorities
+ * can range from \p LOWPRIO to \p HIGHPRIO.
+ * @param pf the thread function. Returning from this function automatically
+ * terminates the thread.
+ * @param arg an argument passed to the thread function. It can be \p NULL.
+ * @return the pointer to the \p Thread structure allocated for the
+ * thread into the working space area or \p NULL if the memory cannot
+ * be allocated.
+ * @note A thread can terminate by calling \p chThdExit() or by simply
+ * returning from its main function.
+ * @note The memory allocated for the thread is not released when the thread
+ * terminates but when a \p chThdWait() is performed.
+ * @note The function is available only if the \p CH_USE_DYNAMIC,
+ * \p CH_USE_HEAP and \p CH_USE_WAITEXIT options are enabled
+ * in \p chconf.h.
+ */
+Thread *chThdCreateFromHeap(size_t wsize, tprio_t prio,
+ tfunc_t pf, void *arg) {
+
+ void *workspace = chHeapAlloc(wsize);
+ if (workspace == NULL)
+ return NULL;
+ Thread *tp = chThdInit(workspace, wsize, prio, pf, arg);
+ tp->p_flags |= P_MEM_MODE_HEAP;
+ chSysLock();
+ chSchWakeupS(tp, RDY_OK);
+ chSysUnlock();
+ return tp;
+}
+#endif /* defined(CH_USE_DYNAMIC) && defined(CH_USE_WAITEXIT) && defined(CH_USE_HEAP) */
+
+#if defined(CH_USE_DYNAMIC) && defined(CH_USE_WAITEXIT) && defined(CH_USE_MEMPOOLS)
+/**
+ * Creates a new thread allocating the memory from the specified Memory Pool.
+ * @param mp the memory pool
+ * @param prio the priority level for the new thread. Usually the threads are
+ * created with priority \p NORMALPRIO, priorities
+ * can range from \p LOWPRIO to \p HIGHPRIO.
+ * @param pf the thread function. Returning from this function automatically
+ * terminates the thread.
+ * @param arg an argument passed to the thread function. It can be \p NULL.
+ * @return the pointer to the \p Thread structure allocated for the
+ * thread into the working space area or \p NULL if the memory cannot
+ * be allocated.
+ * @note A thread can terminate by calling \p chThdExit() or by simply
+ * returning from its main function.
+ * @note The memory allocated for the thread is not released when the thread
+ * terminates but when a \p chThdWait() is performed.
+ * @note The function is available only if the \p CH_USE_DYNAMIC,
+ * \p CH_USE_MEMPOOLS and \p CH_USE_WAITEXIT options are enabled
+ * in \p chconf.h.
+ */
+Thread *chThdCreateFromMemoryPool(MemoryPool *mp, tprio_t prio,
+ tfunc_t pf, void *arg) {
+
+ void *workspace = chPoolAlloc(mp);
+ if (workspace == NULL)
+ return NULL;
+ Thread *tp = chThdInit(workspace, mp->mp_object_size, prio, pf, arg);
+ tp->p_flags |= P_MEM_MODE_MEMPOOL;
+ tp->p_mpool = mp;
+ chSysLock();
+ chSchWakeupS(tp, RDY_OK);
+ chSysUnlock();
+ return tp;
+}
+#endif /* defined(CH_USE_DYNAMIC) && defined(CH_USE_WAITEXIT) && defined(CH_USE_MEMPOOLS) */
+
+/**
+ * Creates a new thread.
+ * @param prio the priority level for the new thread. Usually the threads are
+ * created with priority \p NORMALPRIO, priorities
+ * can range from \p LOWPRIO to \p HIGHPRIO.
+ * @param mode ignored
+ * @param workspace pointer to a working area dedicated to the thread stack
+ * @param wsize size of the working area.
+ * @param pf the thread function. Returning from this function automatically
+ * terminates the thread.
+ * @param arg an argument passed to the thread function. It can be \p NULL.
+ * @return the pointer to the \p Thread structure allocated for the
+ * thread into the working space area.
+ * @note A thread can terminate by calling \p chThdExit() or by simply
+ * returning from its main function.
+ * @deprecated Please use \p chThdCreateStatic() or \p chThdInit() instead,
+ * this function will be removed in version 1.0.0.
+ */
+Thread *chThdCreate(tprio_t prio, tmode_t mode, void *workspace,
+ size_t wsize, tfunc_t pf, void *arg) {
+
+ return chThdCreateStatic(workspace, wsize, prio, pf, arg);
+}
+
/**
* Creates a new thread.
* @param prio the priority level for the new thread. Usually the threads are
@@ -137,16 +234,13 @@ Thread *chThdCreate(tprio_t prio, void *workspace,
* thread into the working space area.
* @note A thread can terminate by calling \p chThdExit() or by simply
* returning from its main function.
- * @deprecated
+ * @deprecated Please use \p chThdCreateStatic() or \p chThdInit() instead,
+ * this function will be removed in version 1.0.0.
*/
Thread *chThdCreateFast(tprio_t prio, void *workspace,
size_t wsize, tfunc_t pf) {
- Thread *tp = chThdInit(prio, workspace, wsize, pf, NULL);
- chSysLock();
- chSchWakeupS(tp, RDY_OK);
- chSysUnlock();
- return tp;
+ return chThdCreateStatic(workspace, wsize, prio, pf, NULL);
}
/**
@@ -245,9 +339,21 @@ void chThdExit(msg_t msg) {
/**
* Blocks the execution of the invoking thread until the specified thread
* terminates then the exit code is returned.
- *
- * @param tp the pointer to the thread
- * @return the exit code
+ * The memory used by the exited thread is handled in different ways depending
+ * on the API that spawned the thread:
+ * <ul>
+ * <li>If the thread was spawned by \p chThdCreateStatic() or by \p chThdInit()
+ * then nothing happens and the thread working area is not released or
+ * modified in any way. This is the default, totally static, behavior.</li>
+ * <li>If the thread was spawned by \p chThdCreateFromHeap() then the working
+ * area is returned to the system heap.</li>
+ * <li>If the thread was spawned by \p chThdCreateFromMemoryPool() then the
+ * working area is returned to the owning memory pool.</li>
+ * </ul>
+ * @param tp the thread pointer
+ * @return the exit code from the terminated thread
+ * @note After invoking \p chThdWait() the thread pointer becomes invalid and
+ * must not be used as parameter for further system calls.
* @note The function is available only if the \p CH_USE_WAITEXIT
* option is enabled in \p chconf.h.
*/
@@ -262,8 +368,33 @@ msg_t chThdWait(Thread *tp) {
}
msg = tp->p_exitcode;
+#ifndef CH_USE_DYNAMIC
+ chSysUnlock();
+ return msg;
+#else /* CH_USE_DYNAMIC */
+ if (notempty(&tp->p_waiting)) {
+ chSysUnlock();
+ return msg;
+ }
+
+ /* This is the last thread waiting for termination, returning memory.*/
+ tmode_t mode = tp->p_flags & P_MEM_MODE_MASK;
chSysUnlock();
+
+ switch (mode) {
+#ifdef CH_USE_HEAP
+ case P_MEM_MODE_HEAP:
+ chHeapFree(tp);
+ break;
+#endif
+#ifdef CH_USE_MEMPOOLS
+ case P_MEM_MODE_MEMPOOL:
+ chPoolFree(tp->p_mpool, tp);
+ break;
+#endif
+ }
return msg;
+#endif /* CH_USE_DYNAMIC */
}
#endif /* CH_USE_WAITEXIT */
diff --git a/src/include/ch.h b/src/include/ch.h
index 7325de0db..0ccb42455 100644
--- a/src/include/ch.h
+++ b/src/include/ch.h
@@ -37,13 +37,13 @@
#include "mutexes.h"
#include "events.h"
#include "messages.h"
+#include "heap.h"
+#include "mempools.h"
#include "threads.h"
#include "inline.h"
#include "sleep.h"
#include "queues.h"
#include "serial.h"
-#include "heap.h"
-#include "mempools.h"
#include "debug.h"
/*
diff --git a/src/include/threads.h b/src/include/threads.h
index a98faf792..a1c8167b8 100644
--- a/src/include/threads.h
+++ b/src/include/threads.h
@@ -106,6 +106,10 @@ struct Thread {
/** Thread's own, non-inherited, priority. */
tprio_t p_realprio;
#endif
+#if defined(CH_USE_DYNAMIC) && defined(CH_USE_MEMPOOLS)
+ /** Memory Pool where the thread workspace is returned. */
+ void *p_mpool;
+#endif
#ifdef CH_USE_THREAD_EXT
THREAD_EXT_FIELDS
#endif
@@ -134,8 +138,14 @@ struct Thread {
/** Thread state: After termination.*/
#define PREXIT 10
-/** Thread option: Termination requested flag.*/
-#define P_TERMINATE 1
+/*
+ * Various flags into the thread p_flags field.
+ */
+#define P_MEM_MODE_MASK 3 /* Thread memory mode mask. */
+#define P_MEM_MODE_STATIC 0 /* Thread memory mode: static. */
+#define P_MEM_MODE_HEAP 1 /* Thread memory mode: heap. */
+#define P_MEM_MODE_MEMPOOL 2 /* Thread memory mode: mempool. */
+#define P_TERMINATE 4 /* Termination requested. */
/** Pseudo priority used by the ready list header, do not use.*/
#define NOPRIO 0
@@ -151,7 +161,7 @@ struct Thread {
#define ABSPRIO 255
/* Not an API, don't use into the application code.*/
-void init_thread(tprio_t prio, Thread *tp);
+void init_thread(Thread *tp, tprio_t prio);
/** Thread function.*/
typedef msg_t (*tfunc_t)(void *);
@@ -162,9 +172,15 @@ typedef msg_t (*tfunc_t)(void *);
#ifdef __cplusplus
extern "C" {
#endif
- Thread *chThdInit(tprio_t prio, void *workspace,
- size_t wsize, tfunc_t pf, void *arg);
- Thread *chThdCreate(tprio_t prio, void *workspace,
+ Thread *chThdInit(void *workspace, size_t wsize,
+ tprio_t prio, tfunc_t pf, void *arg);
+ Thread *chThdCreateStatic(void *workspace, size_t wsize,
+ tprio_t prio, tfunc_t pf, void *arg);
+ Thread *chThdCreateFromHeap(size_t wsize, tprio_t prio,
+ tfunc_t pf, void *arg);
+ Thread *chThdCreateFromMemoryPool(MemoryPool *mp, tprio_t prio,
+ tfunc_t pf, void *arg);
+ Thread *chThdCreate(tprio_t prio, tmode_t mode, void *workspace,
size_t wsize, tfunc_t pf, void *arg);
Thread *chThdCreateFast(tprio_t prio, void *workspace,
size_t wsize, tfunc_t pf);
diff --git a/src/templates/chconf.h b/src/templates/chconf.h
index 48ef017a8..1f5ca1446 100644
--- a/src/templates/chconf.h
+++ b/src/templates/chconf.h
@@ -148,6 +148,12 @@
* are included in the kernel.*/
#define CH_USE_MEMPOOLS
+/** Configuration option: if specified then the dynamic objects creation APIs
+ * are included in the kernel.
+ * @note requires \p CH_USE_WAITEXIT.
+ */
+#define CH_USE_DYNAMIC
+
/** Configuration option: Frequency of the system timer that drives the system
* ticks. This also defines the system time unit.*/
#define CH_FREQUENCY 1000
diff --git a/test/testmsg.c b/test/testmsg.c
index 5e9cba0d8..fcf811fa1 100644
--- a/test/testmsg.c
+++ b/test/testmsg.c
@@ -47,7 +47,7 @@ static msg_t thread(void *p) {
static void msg1_execute(void) {
msg_t msg;
- threads[0] = chThdCreate(chThdGetPriority()-1, wa[0], STKSIZE, thread, chThdSelf());
+ threads[0] = chThdCreateStatic(wa[0], STKSIZE, chThdGetPriority()-1, thread, chThdSelf());
do {
chMsgRelease(msg = chMsgWait());
if (msg)
diff --git a/test/testmtx.c b/test/testmtx.c
index f5a4c139c..3954e9338 100644
--- a/test/testmtx.c
+++ b/test/testmtx.c
@@ -52,11 +52,11 @@ static void mtx1_execute(void) {
tprio_t prio = chThdGetPriority(); // Bacause priority inheritance.
chMtxLock(&m1);
- threads[0] = chThdCreate(prio+1, wa[0], STKSIZE, thread1, "E");
- threads[1] = chThdCreate(prio+2, wa[1], STKSIZE, thread1, "D");
- threads[2] = chThdCreate(prio+3, wa[2], STKSIZE, thread1, "C");
- threads[3] = chThdCreate(prio+4, wa[3], STKSIZE, thread1, "B");
- threads[4] = chThdCreate(prio+5, wa[4], STKSIZE, thread1, "A");
+ threads[0] = chThdCreateStatic(wa[0], STKSIZE, prio+1, thread1, "E");
+ threads[1] = chThdCreateStatic(wa[1], STKSIZE, prio+2, thread1, "D");
+ threads[2] = chThdCreateStatic(wa[2], STKSIZE, prio+3, thread1, "C");
+ threads[3] = chThdCreateStatic(wa[3], STKSIZE, prio+4, thread1, "B");
+ threads[4] = chThdCreateStatic(wa[4], STKSIZE, prio+5, thread1, "A");
chMtxUnlock();
test_assert(prio == chThdGetPriority(), "priority return failure");
test_wait_threads();
@@ -117,9 +117,9 @@ static msg_t thread4(void *p) {
*/
static void mtx2_execute(void) {
- threads[0] = chThdCreate(chThdGetPriority()-1, wa[0], STKSIZE, thread2, "A");
- threads[1] = chThdCreate(chThdGetPriority()-3, wa[1], STKSIZE, thread3, "C");
- threads[2] = chThdCreate(chThdGetPriority()-2, wa[2], STKSIZE, thread4, "B");
+ threads[0] = chThdCreateStatic(wa[0], STKSIZE, chThdGetPriority()-1, thread2, "A");
+ threads[1] = chThdCreateStatic(wa[1], STKSIZE, chThdGetPriority()-3, thread3, "C");
+ threads[2] = chThdCreateStatic(wa[2], STKSIZE, chThdGetPriority()-2, thread4, "B");
test_wait_threads();
test_assert_sequence("ABC");
}
@@ -206,11 +206,11 @@ static msg_t thread9(void *p) {
*/
static void mtx3_execute(void) {
- threads[0] = chThdCreate(chThdGetPriority()-5, wa[0], STKSIZE, thread5, "E");
- threads[1] = chThdCreate(chThdGetPriority()-4, wa[1], STKSIZE, thread6, "D");
- threads[2] = chThdCreate(chThdGetPriority()-3, wa[2], STKSIZE, thread7, "C");
- threads[3] = chThdCreate(chThdGetPriority()-2, wa[3], STKSIZE, thread8, "B");
- threads[4] = chThdCreate(chThdGetPriority()-1, wa[4], STKSIZE, thread9, "A");
+ threads[0] = chThdCreateStatic(wa[0], STKSIZE, chThdGetPriority()-5, thread5, "E");
+ threads[1] = chThdCreateStatic(wa[1], STKSIZE, chThdGetPriority()-4, thread6, "D");
+ threads[2] = chThdCreateStatic(wa[2], STKSIZE, chThdGetPriority()-3, thread7, "C");
+ threads[3] = chThdCreateStatic(wa[3], STKSIZE, chThdGetPriority()-2, thread8, "B");
+ threads[4] = chThdCreateStatic(wa[4], STKSIZE, chThdGetPriority()-1, thread9, "A");
test_wait_threads();
test_assert_sequence("ABCDE");
}
diff --git a/test/testrdy.c b/test/testrdy.c
index fd6b7b17f..2d39e5ff4 100644
--- a/test/testrdy.c
+++ b/test/testrdy.c
@@ -40,11 +40,11 @@ static void rdy1_teardown(void) {
static void rdy1_execute(void) {
- threads[0] = chThdCreate(chThdGetPriority()-5, wa[0], STKSIZE, thread, "E");
- threads[1] = chThdCreate(chThdGetPriority()-4, wa[1], STKSIZE, thread, "D");
- threads[2] = chThdCreate(chThdGetPriority()-3, wa[2], STKSIZE, thread, "C");
- threads[3] = chThdCreate(chThdGetPriority()-2, wa[3], STKSIZE, thread, "B");
- threads[4] = chThdCreate(chThdGetPriority()-1, wa[4], STKSIZE, thread, "A");
+ threads[0] = chThdCreateStatic(wa[0], STKSIZE, chThdGetPriority()-5, thread, "E");
+ threads[1] = chThdCreateStatic(wa[1], STKSIZE, chThdGetPriority()-4, thread, "D");
+ threads[2] = chThdCreateStatic(wa[2], STKSIZE, chThdGetPriority()-3, thread, "C");
+ threads[3] = chThdCreateStatic(wa[3], STKSIZE, chThdGetPriority()-2, thread, "B");
+ threads[4] = chThdCreateStatic(wa[4], STKSIZE, chThdGetPriority()-1, thread, "A");
test_wait_threads();
test_assert_sequence("ABCDE");
}
@@ -69,11 +69,11 @@ static void rdy2_teardown(void) {
static void rdy2_execute(void) {
- threads[1] = chThdCreate(chThdGetPriority()-4, wa[1], STKSIZE, thread, "D");
- threads[0] = chThdCreate(chThdGetPriority()-5, wa[0], STKSIZE, thread, "E");
- threads[4] = chThdCreate(chThdGetPriority()-1, wa[4], STKSIZE, thread, "A");
- threads[3] = chThdCreate(chThdGetPriority()-2, wa[3], STKSIZE, thread, "B");
- threads[2] = chThdCreate(chThdGetPriority()-3, wa[2], STKSIZE, thread, "C");
+ threads[1] = chThdCreateStatic(wa[1], STKSIZE, chThdGetPriority()-4, thread, "D");
+ threads[0] = chThdCreateStatic(wa[0], STKSIZE, chThdGetPriority()-5, thread, "E");
+ threads[4] = chThdCreateStatic(wa[4], STKSIZE, chThdGetPriority()-1, thread, "A");
+ threads[3] = chThdCreateStatic(wa[3], STKSIZE, chThdGetPriority()-2, thread, "B");
+ threads[2] = chThdCreateStatic(wa[2], STKSIZE, chThdGetPriority()-3, thread, "C");
test_wait_threads();
test_assert_sequence("ABCDE");
}
diff --git a/test/testsem.c b/test/testsem.c
index 4442117e9..6afa715cb 100644
--- a/test/testsem.c
+++ b/test/testsem.c
@@ -47,11 +47,11 @@ static msg_t thread(void *p) {
static void sem1_execute(void) {
- threads[0] = chThdCreate(chThdGetPriority()+5, wa[0], STKSIZE, thread, "A");
- threads[1] = chThdCreate(chThdGetPriority()+1, wa[1], STKSIZE, thread, "B");
- threads[2] = chThdCreate(chThdGetPriority()+3, wa[2], STKSIZE, thread, "C");
- threads[3] = chThdCreate(chThdGetPriority()+4, wa[3], STKSIZE, thread, "D");
- threads[4] = chThdCreate(chThdGetPriority()+2, wa[4], STKSIZE, thread, "E");
+ threads[0] = chThdCreateStatic(wa[0], STKSIZE, chThdGetPriority()+5, thread, "A");
+ threads[1] = chThdCreateStatic(wa[1], STKSIZE, chThdGetPriority()+1, thread, "B");
+ threads[2] = chThdCreateStatic(wa[2], STKSIZE, chThdGetPriority()+3, thread, "C");
+ threads[3] = chThdCreateStatic(wa[3], STKSIZE, chThdGetPriority()+4, thread, "D");
+ threads[4] = chThdCreateStatic(wa[4], STKSIZE, chThdGetPriority()+2, thread, "E");
chSemSignal(&sem1);
chSemSignal(&sem1);
chSemSignal(&sem1);