aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--os/rt/include/chdynamic.h (renamed from os/common/oslib/include/chdynamic.h)0
-rw-r--r--os/rt/include/chschd.h107
-rw-r--r--os/rt/rt.mk10
-rw-r--r--os/rt/src/chdynamic.c (renamed from os/common/oslib/src/chdynamic.c)1
-rw-r--r--os/rt/src/chregistry.c23
-rw-r--r--os/rt/src/chsys.c1
-rw-r--r--os/rt/src/chthreads.c1
7 files changed, 89 insertions, 54 deletions
diff --git a/os/common/oslib/include/chdynamic.h b/os/rt/include/chdynamic.h
index fa42bf3ae..fa42bf3ae 100644
--- a/os/common/oslib/include/chdynamic.h
+++ b/os/rt/include/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
diff --git a/os/rt/rt.mk b/os/rt/rt.mk
index 971e18c23..cf92d654d 100644
--- a/os/rt/rt.mk
+++ b/os/rt/rt.mk
@@ -35,6 +35,9 @@ endif
ifneq ($(findstring CH_CFG_USE_QUEUES TRUE,$(CHCONF)),)
KERNSRC += $(CHIBIOS)/os/rt/src/chqueues.c
endif
+ifneq ($(findstring CH_CFG_USE_DYNAMIC TRUE,$(CHCONF)),)
+KERNSRC += $(CHIBIOS)/os/rt/src/chdynamic.c
+endif
ifneq ($(findstring CH_CFG_USE_MAILBOXES TRUE,$(CHCONF)),)
KERNSRC += $(CHIBIOS)/os/common/oslib/src/chmboxes.c
endif
@@ -47,9 +50,6 @@ endif
ifneq ($(findstring CH_CFG_USE_MEMPOOLS TRUE,$(CHCONF)),)
KERNSRC += $(CHIBIOS)/os/common/oslib/src/chmempools.c
endif
-ifneq ($(findstring CH_CFG_USE_DYNAMIC TRUE,$(CHCONF)),)
-KERNSRC += $(CHIBIOS)/os/common/oslib/src/chdynamic.c
-endif
else
KERNSRC := $(CHIBIOS)/os/rt/src/chsys.c \
$(CHIBIOS)/os/rt/src/chdebug.c \
@@ -65,11 +65,11 @@ KERNSRC := $(CHIBIOS)/os/rt/src/chsys.c \
$(CHIBIOS)/os/rt/src/chevents.c \
$(CHIBIOS)/os/rt/src/chmsg.c \
$(CHIBIOS)/os/rt/src/chqueues.c \
+ $(CHIBIOS)/os/rt/src/chdynamic.c \
$(CHIBIOS)/os/common/oslib/src/chmboxes.c \
$(CHIBIOS)/os/common/oslib/src/chmemcore.c \
$(CHIBIOS)/os/common/oslib/src/chheap.c \
- $(CHIBIOS)/os/common/oslib/src/chmempools.c \
- $(CHIBIOS)/os/common/oslib/src/chdynamic.c
+ $(CHIBIOS)/os/common/oslib/src/chmempools.c
endif
# Required include directories
diff --git a/os/common/oslib/src/chdynamic.c b/os/rt/src/chdynamic.c
index 3865c318a..414cfe2c8 100644
--- a/os/common/oslib/src/chdynamic.c
+++ b/os/rt/src/chdynamic.c
@@ -23,7 +23,6 @@
*
* @addtogroup dynamic_threads
* @details Dynamic threads related APIs and services.
- * @note Compatible with RT only.
* @{
*/
diff --git a/os/rt/src/chregistry.c b/os/rt/src/chregistry.c
index 944383bf1..7d870897b 100644
--- a/os/rt/src/chregistry.c
+++ b/os/rt/src/chregistry.c
@@ -101,8 +101,12 @@ ROMCONST chdebug_t ch_debug = {
(uint8_t)0,
#endif
(uint8_t)_offsetof(thread_t, state),
- (uint8_t)0, /* Flags no more part of the structure. */
- (uint8_t)0, /* Refs no more part of the structure. */
+ (uint8_t)_offsetof(thread_t, flags),
+#if CH_CFG_USE_DYNAMIC == TRUE
+ (uint8_t)_offsetof(thread_t, refs),
+#else
+ (uint8_t)0,
+#endif
#if CH_CFG_TIME_QUANTUM > 0
(uint8_t)_offsetof(thread_t, preempt),
#else
@@ -132,6 +136,9 @@ thread_t *chRegFirstThread(void) {
chSysLock();
tp = ch.rlist.newer;
+#if CH_CFG_USE_DYNAMIC == TRUE
+ tp->refs++;
+#endif
chSysUnlock();
return tp;
@@ -158,7 +165,16 @@ thread_t *chRegNextThread(thread_t *tp) {
/*lint -restore*/
ntp = NULL;
}
+#if CH_CFG_USE_DYNAMIC == TRUE
+ else {
+ chDbgAssert(ntp->refs < (trefs_t)255, "too many references");
+ ntp->refs++;
+ }
+#endif
chSysUnlock();
+#if CH_CFG_USE_DYNAMIC == TRUE
+ chThdRelease(tp);
+#endif
return ntp;
}
@@ -186,7 +202,6 @@ thread_t *chRegFindThreadByName(const char *name) {
return NULL;
}
-#endif /* CH_CFG_USE_REGISTRY == TRUE */
/**
* @brief Confirms that a pointer is a valid thread pointer.
@@ -212,4 +227,6 @@ thread_t *chRegFindThreadByPointer(thread_t *tp) {
return NULL;
}
+#endif /* CH_CFG_USE_REGISTRY == TRUE */
+
/** @} */
diff --git a/os/rt/src/chsys.c b/os/rt/src/chsys.c
index d9ca6d81a..18459849d 100644
--- a/os/rt/src/chsys.c
+++ b/os/rt/src/chsys.c
@@ -129,6 +129,7 @@ void chSysInit(void) {
/* Setting up the caller as current thread.*/
currp->state = CH_STATE_CURRENT;
+ currp->flags = CH_FLAG_MODE_STATIC;
/* Port layer initialization last because it depend on some of the
initializations performed before.*/
diff --git a/os/rt/src/chthreads.c b/os/rt/src/chthreads.c
index e706c0d77..0fff76604 100644
--- a/os/rt/src/chthreads.c
+++ b/os/rt/src/chthreads.c
@@ -175,6 +175,7 @@ thread_t *chThdCreateSuspendedI(const thread_descriptor_t *tdp) {
/* Initial state.*/
tp->state = CH_STATE_WTSTART;
+ tp->flags = CH_FLAG_MODE_STATIC;
/* Stack boundary.*/
tp->stklimit = tdp->wbase;