aboutsummaryrefslogtreecommitdiffstats
path: root/os/rt/include
diff options
context:
space:
mode:
Diffstat (limited to 'os/rt/include')
-rw-r--r--os/rt/include/chdynamic.h97
-rw-r--r--os/rt/include/chschd.h107
2 files changed, 159 insertions, 45 deletions
diff --git a/os/rt/include/chdynamic.h b/os/rt/include/chdynamic.h
new file mode 100644
index 000000000..fa42bf3ae
--- /dev/null
+++ b/os/rt/include/chdynamic.h
@@ -0,0 +1,97 @@
+/*
+ ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio.
+
+ This file is part of ChibiOS.
+
+ ChibiOS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * @file chdynamic.h
+ * @brief Dynamic threads macros and structures.
+ *
+ * @addtogroup dynamic_threads
+ * @{
+ */
+
+#ifndef _CHDYNAMIC_H_
+#define _CHDYNAMIC_H_
+
+#if (CH_CFG_USE_DYNAMIC == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Module constants. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Module pre-compile time settings. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*
+ * Module dependencies check.
+ */
+#if CH_CFG_USE_WAITEXIT == FALSE
+#error "CH_CFG_USE_DYNAMIC requires CH_CFG_USE_WAITEXIT"
+#endif
+
+#if (CH_CFG_USE_HEAP == FALSE) && (CH_CFG_USE_MEMPOOLS == FALSE)
+#error "CH_CFG_USE_DYNAMIC requires CH_CFG_USE_HEAP and/or CH_CFG_USE_MEMPOOLS"
+#endif
+
+/*===========================================================================*/
+/* Module data structures and types. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Module macros. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+/*
+ * Dynamic threads APIs.
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+#if CH_CFG_USE_HEAP == TRUE
+ thread_t *chThdCreateFromHeap(memory_heap_t *heapp, size_t size,
+ const char *name, tprio_t prio,
+ tfunc_t pf, void *arg);
+ void chThdFreeToHeap(thread_t *tp);
+#endif
+#if CH_CFG_USE_MEMPOOLS == TRUE
+ thread_t *chThdCreateFromMemoryPool(memory_pool_t *mp, const char *name,
+ tprio_t prio, tfunc_t pf, void *arg);
+ void chThdFreeToMemoryPool(thread_t *tp, memory_pool_t *mp);
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+/*===========================================================================*/
+/* Module inline functions. */
+/*===========================================================================*/
+
+#endif /* CH_CFG_USE_DYNAMIC == TRUE */
+
+#endif /* _CHDYNAMIC_H_ */
+
+/** @} */
diff --git a/os/rt/include/chschd.h b/os/rt/include/chschd.h
index 8275a1eee..ca48afe75 100644
--- a/os/rt/include/chschd.h
+++ b/os/rt/include/chschd.h
@@ -218,131 +218,148 @@ struct ch_thread {
/* End of the fields shared with the ReadyList structure. */
#if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__)
/**
- * @brief Thread name or @p NULL.
+ * @brief Thread name or @p NULL.
*/
const char *name;
#endif
/**
- * @brief Thread stack boundary.
- * @note This pointer matches with the working area base address.
+ * @brief Thread stack boundary.
+ * @note This pointer matches with the working area base address.
*/
stkalign_t *stklimit;
/**
- * @brief Current thread state.
+ * @brief Current thread state.
*/
tstate_t state;
/**
- * @brief Number of ticks remaining to this thread.
+ * @brief Various thread flags.
+ */
+ tmode_t flags;
+#if (CH_CFG_USE_DYNAMIC == TRUE) || defined(__DOXYGEN__)
+ /**
+ * @brief References to this thread.
+ */
+ trefs_t refs;
+#endif
+ /**
+ * @brief Number of ticks remaining to this thread.
*/
#if (CH_CFG_TIME_QUANTUM > 0) || defined(__DOXYGEN__)
tslices_t preempt;
#endif
#if (CH_DBG_THREADS_PROFILING == TRUE) || defined(__DOXYGEN__)
/**
- * @brief Thread consumed time in ticks.
- * @note This field can overflow.
+ * @brief Thread consumed time in ticks.
+ * @note This field can overflow.
*/
volatile systime_t time;
#endif
/**
- * @brief State-specific fields.
- * @note All the fields declared in this union are only valid in the
- * specified state or condition and are thus volatile.
+ * @brief State-specific fields.
+ * @note All the fields declared in this union are only valid in the
+ * specified state or condition and are thus volatile.
*/
union {
/**
- * @brief Thread wakeup code.
- * @note This field contains the low level message sent to the thread
- * by the waking thread or interrupt handler. The value is valid
- * after exiting the @p chSchWakeupS() function.
+ * @brief Thread wakeup code.
+ * @note This field contains the low level message sent to the thread
+ * by the waking thread or interrupt handler. The value is valid
+ * after exiting the @p chSchWakeupS() function.
*/
msg_t rdymsg;
/**
- * @brief Thread exit code.
- * @note The thread termination code is stored in this field in order
- * to be retrieved by the thread performing a @p chThdWait() on
- * this thread.
+ * @brief Thread exit code.
+ * @note The thread termination code is stored in this field in order
+ * to be retrieved by the thread performing a @p chThdWait() on
+ * this thread.
*/
msg_t exitcode;
/**
- * @brief Pointer to a generic "wait" object.
- * @note This field is used to get a generic pointer to a synchronization
- * object and is valid when the thread is in one of the wait
- * states.
+ * @brief Pointer to a generic "wait" object.
+ * @note This field is used to get a generic pointer to a synchronization
+ * object and is valid when the thread is in one of the wait
+ * states.
*/
void *wtobjp;
/**
- * @brief Pointer to a generic thread reference object.
- * @note This field is used to get a pointer to a synchronization
- * object and is valid when the thread is in @p CH_STATE_SUSPENDED
- * state.
+ * @brief Pointer to a generic thread reference object.
+ * @note This field is used to get a pointer to a synchronization
+ * object and is valid when the thread is in @p CH_STATE_SUSPENDED
+ * state.
*/
thread_reference_t *wttrp;
#if (CH_CFG_USE_MESSAGES == TRUE) || defined(__DOXYGEN__)
/**
- * @brief Thread sent message.
+ * @brief Thread sent message.
*/
msg_t sentmsg;
#endif
#if (CH_CFG_USE_SEMAPHORES == TRUE) || defined(__DOXYGEN__)
/**
- * @brief Pointer to a generic semaphore object.
- * @note This field is used to get a pointer to a synchronization
- * object and is valid when the thread is in @p CH_STATE_WTSEM
- * state.
+ * @brief Pointer to a generic semaphore object.
+ * @note This field is used to get a pointer to a synchronization
+ * object and is valid when the thread is in @p CH_STATE_WTSEM
+ * state.
*/
struct ch_semaphore *wtsemp;
#endif
#if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__)
/**
- * @brief Pointer to a generic mutex object.
- * @note This field is used to get a pointer to a synchronization
- * object and is valid when the thread is in @p CH_STATE_WTMTX
- * state.
+ * @brief Pointer to a generic mutex object.
+ * @note This field is used to get a pointer to a synchronization
+ * object and is valid when the thread is in @p CH_STATE_WTMTX
+ * state.
*/
struct ch_mutex *wtmtxp;
#endif
#if (CH_CFG_USE_EVENTS == TRUE) || defined(__DOXYGEN__)
/**
- * @brief Enabled events mask.
- * @note This field is only valid while the thread is in the
- * @p CH_STATE_WTOREVT or @p CH_STATE_WTANDEVT states.
+ * @brief Enabled events mask.
+ * @note This field is only valid while the thread is in the
+ * @p CH_STATE_WTOREVT or @p CH_STATE_WTANDEVT states.
*/
eventmask_t ewmask;
#endif
} u;
#if (CH_CFG_USE_WAITEXIT == TRUE) || defined(__DOXYGEN__)
/**
- * @brief Termination waiting list.
+ * @brief Termination waiting list.
*/
threads_list_t waiting;
#endif
#if (CH_CFG_USE_MESSAGES == TRUE) || defined(__DOXYGEN__)
/**
- * @brief Messages queue.
+ * @brief Messages queue.
*/
threads_queue_t msgqueue;
#endif
#if (CH_CFG_USE_EVENTS == TRUE) || defined(__DOXYGEN__)
/**
- * @brief Pending events mask.
+ * @brief Pending events mask.
*/
eventmask_t epending;
#endif
#if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__)
/**
- * @brief List of the mutexes owned by this thread.
- * @note The list is terminated by a @p NULL in this field.
+ * @brief List of the mutexes owned by this thread.
+ * @note The list is terminated by a @p NULL in this field.
*/
struct ch_mutex *mtxlist;
/**
- * @brief Thread's own, non-inherited, priority.
+ * @brief Thread's own, non-inherited, priority.
*/
tprio_t realprio;
#endif
+#if ((CH_CFG_USE_DYNAMIC == TRUE) && (CH_CFG_USE_MEMPOOLS == TRUE)) || \
+ defined(__DOXYGEN__)
+ /**
+ * @brief Memory Pool where the thread workspace is returned.
+ */
+ void *mpool;
+#endif
#if (CH_DBG_STATISTICS == TRUE) || defined(__DOXYGEN__)
/**
- * @brief Thread statistics.
+ * @brief Thread statistics.
*/
time_measurement_t stats;
#endif