git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8940 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
Giovanni Di Sirio 2016-02-24 11:22:05 +00:00
parent 5181b1e391
commit a2072b5560
7 changed files with 89 additions and 54 deletions

View File

@ -218,131 +218,148 @@ struct ch_thread {
/* End of the fields shared with the ReadyList structure. */ /* End of the fields shared with the ReadyList structure. */
#if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__) #if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__)
/** /**
* @brief Thread name or @p NULL. * @brief Thread name or @p NULL.
*/ */
const char *name; const char *name;
#endif #endif
/** /**
* @brief Thread stack boundary. * @brief Thread stack boundary.
* @note This pointer matches with the working area base address. * @note This pointer matches with the working area base address.
*/ */
stkalign_t *stklimit; stkalign_t *stklimit;
/** /**
* @brief Current thread state. * @brief Current thread state.
*/ */
tstate_t 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__) #if (CH_CFG_TIME_QUANTUM > 0) || defined(__DOXYGEN__)
tslices_t preempt; tslices_t preempt;
#endif #endif
#if (CH_DBG_THREADS_PROFILING == TRUE) || defined(__DOXYGEN__) #if (CH_DBG_THREADS_PROFILING == TRUE) || defined(__DOXYGEN__)
/** /**
* @brief Thread consumed time in ticks. * @brief Thread consumed time in ticks.
* @note This field can overflow. * @note This field can overflow.
*/ */
volatile systime_t time; volatile systime_t time;
#endif #endif
/** /**
* @brief State-specific fields. * @brief State-specific fields.
* @note All the fields declared in this union are only valid in the * @note All the fields declared in this union are only valid in the
* specified state or condition and are thus volatile. * specified state or condition and are thus volatile.
*/ */
union { union {
/** /**
* @brief Thread wakeup code. * @brief Thread wakeup code.
* @note This field contains the low level message sent to the thread * @note This field contains the low level message sent to the thread
* by the waking thread or interrupt handler. The value is valid * by the waking thread or interrupt handler. The value is valid
* after exiting the @p chSchWakeupS() function. * after exiting the @p chSchWakeupS() function.
*/ */
msg_t rdymsg; msg_t rdymsg;
/** /**
* @brief Thread exit code. * @brief Thread exit code.
* @note The thread termination code is stored in this field in order * @note The thread termination code is stored in this field in order
* to be retrieved by the thread performing a @p chThdWait() on * to be retrieved by the thread performing a @p chThdWait() on
* this thread. * this thread.
*/ */
msg_t exitcode; msg_t exitcode;
/** /**
* @brief Pointer to a generic "wait" object. * @brief Pointer to a generic "wait" object.
* @note This field is used to get a generic pointer to a synchronization * @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 * object and is valid when the thread is in one of the wait
* states. * states.
*/ */
void *wtobjp; void *wtobjp;
/** /**
* @brief Pointer to a generic thread reference object. * @brief Pointer to a generic thread reference object.
* @note This field is used to get a pointer to a synchronization * @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 * object and is valid when the thread is in @p CH_STATE_SUSPENDED
* state. * state.
*/ */
thread_reference_t *wttrp; thread_reference_t *wttrp;
#if (CH_CFG_USE_MESSAGES == TRUE) || defined(__DOXYGEN__) #if (CH_CFG_USE_MESSAGES == TRUE) || defined(__DOXYGEN__)
/** /**
* @brief Thread sent message. * @brief Thread sent message.
*/ */
msg_t sentmsg; msg_t sentmsg;
#endif #endif
#if (CH_CFG_USE_SEMAPHORES == TRUE) || defined(__DOXYGEN__) #if (CH_CFG_USE_SEMAPHORES == TRUE) || defined(__DOXYGEN__)
/** /**
* @brief Pointer to a generic semaphore object. * @brief Pointer to a generic semaphore object.
* @note This field is used to get a pointer to a synchronization * @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 * object and is valid when the thread is in @p CH_STATE_WTSEM
* state. * state.
*/ */
struct ch_semaphore *wtsemp; struct ch_semaphore *wtsemp;
#endif #endif
#if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__) #if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__)
/** /**
* @brief Pointer to a generic mutex object. * @brief Pointer to a generic mutex object.
* @note This field is used to get a pointer to a synchronization * @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 * object and is valid when the thread is in @p CH_STATE_WTMTX
* state. * state.
*/ */
struct ch_mutex *wtmtxp; struct ch_mutex *wtmtxp;
#endif #endif
#if (CH_CFG_USE_EVENTS == TRUE) || defined(__DOXYGEN__) #if (CH_CFG_USE_EVENTS == TRUE) || defined(__DOXYGEN__)
/** /**
* @brief Enabled events mask. * @brief Enabled events mask.
* @note This field is only valid while the thread is in the * @note This field is only valid while the thread is in the
* @p CH_STATE_WTOREVT or @p CH_STATE_WTANDEVT states. * @p CH_STATE_WTOREVT or @p CH_STATE_WTANDEVT states.
*/ */
eventmask_t ewmask; eventmask_t ewmask;
#endif #endif
} u; } u;
#if (CH_CFG_USE_WAITEXIT == TRUE) || defined(__DOXYGEN__) #if (CH_CFG_USE_WAITEXIT == TRUE) || defined(__DOXYGEN__)
/** /**
* @brief Termination waiting list. * @brief Termination waiting list.
*/ */
threads_list_t waiting; threads_list_t waiting;
#endif #endif
#if (CH_CFG_USE_MESSAGES == TRUE) || defined(__DOXYGEN__) #if (CH_CFG_USE_MESSAGES == TRUE) || defined(__DOXYGEN__)
/** /**
* @brief Messages queue. * @brief Messages queue.
*/ */
threads_queue_t msgqueue; threads_queue_t msgqueue;
#endif #endif
#if (CH_CFG_USE_EVENTS == TRUE) || defined(__DOXYGEN__) #if (CH_CFG_USE_EVENTS == TRUE) || defined(__DOXYGEN__)
/** /**
* @brief Pending events mask. * @brief Pending events mask.
*/ */
eventmask_t epending; eventmask_t epending;
#endif #endif
#if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__) #if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__)
/** /**
* @brief List of the mutexes owned by this thread. * @brief List of the mutexes owned by this thread.
* @note The list is terminated by a @p NULL in this field. * @note The list is terminated by a @p NULL in this field.
*/ */
struct ch_mutex *mtxlist; struct ch_mutex *mtxlist;
/** /**
* @brief Thread's own, non-inherited, priority. * @brief Thread's own, non-inherited, priority.
*/ */
tprio_t realprio; tprio_t realprio;
#endif #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__) #if (CH_DBG_STATISTICS == TRUE) || defined(__DOXYGEN__)
/** /**
* @brief Thread statistics. * @brief Thread statistics.
*/ */
time_measurement_t stats; time_measurement_t stats;
#endif #endif

View File

@ -35,6 +35,9 @@ endif
ifneq ($(findstring CH_CFG_USE_QUEUES TRUE,$(CHCONF)),) ifneq ($(findstring CH_CFG_USE_QUEUES TRUE,$(CHCONF)),)
KERNSRC += $(CHIBIOS)/os/rt/src/chqueues.c KERNSRC += $(CHIBIOS)/os/rt/src/chqueues.c
endif 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)),) ifneq ($(findstring CH_CFG_USE_MAILBOXES TRUE,$(CHCONF)),)
KERNSRC += $(CHIBIOS)/os/common/oslib/src/chmboxes.c KERNSRC += $(CHIBIOS)/os/common/oslib/src/chmboxes.c
endif endif
@ -47,9 +50,6 @@ endif
ifneq ($(findstring CH_CFG_USE_MEMPOOLS TRUE,$(CHCONF)),) ifneq ($(findstring CH_CFG_USE_MEMPOOLS TRUE,$(CHCONF)),)
KERNSRC += $(CHIBIOS)/os/common/oslib/src/chmempools.c KERNSRC += $(CHIBIOS)/os/common/oslib/src/chmempools.c
endif endif
ifneq ($(findstring CH_CFG_USE_DYNAMIC TRUE,$(CHCONF)),)
KERNSRC += $(CHIBIOS)/os/common/oslib/src/chdynamic.c
endif
else else
KERNSRC := $(CHIBIOS)/os/rt/src/chsys.c \ KERNSRC := $(CHIBIOS)/os/rt/src/chsys.c \
$(CHIBIOS)/os/rt/src/chdebug.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/chevents.c \
$(CHIBIOS)/os/rt/src/chmsg.c \ $(CHIBIOS)/os/rt/src/chmsg.c \
$(CHIBIOS)/os/rt/src/chqueues.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/chmboxes.c \
$(CHIBIOS)/os/common/oslib/src/chmemcore.c \ $(CHIBIOS)/os/common/oslib/src/chmemcore.c \
$(CHIBIOS)/os/common/oslib/src/chheap.c \ $(CHIBIOS)/os/common/oslib/src/chheap.c \
$(CHIBIOS)/os/common/oslib/src/chmempools.c \ $(CHIBIOS)/os/common/oslib/src/chmempools.c
$(CHIBIOS)/os/common/oslib/src/chdynamic.c
endif endif
# Required include directories # Required include directories

View File

@ -23,7 +23,6 @@
* *
* @addtogroup dynamic_threads * @addtogroup dynamic_threads
* @details Dynamic threads related APIs and services. * @details Dynamic threads related APIs and services.
* @note Compatible with RT only.
* @{ * @{
*/ */

View File

@ -101,8 +101,12 @@ ROMCONST chdebug_t ch_debug = {
(uint8_t)0, (uint8_t)0,
#endif #endif
(uint8_t)_offsetof(thread_t, state), (uint8_t)_offsetof(thread_t, state),
(uint8_t)0, /* Flags no more part of the structure. */ (uint8_t)_offsetof(thread_t, flags),
(uint8_t)0, /* Refs no more part of the structure. */ #if CH_CFG_USE_DYNAMIC == TRUE
(uint8_t)_offsetof(thread_t, refs),
#else
(uint8_t)0,
#endif
#if CH_CFG_TIME_QUANTUM > 0 #if CH_CFG_TIME_QUANTUM > 0
(uint8_t)_offsetof(thread_t, preempt), (uint8_t)_offsetof(thread_t, preempt),
#else #else
@ -132,6 +136,9 @@ thread_t *chRegFirstThread(void) {
chSysLock(); chSysLock();
tp = ch.rlist.newer; tp = ch.rlist.newer;
#if CH_CFG_USE_DYNAMIC == TRUE
tp->refs++;
#endif
chSysUnlock(); chSysUnlock();
return tp; return tp;
@ -158,7 +165,16 @@ thread_t *chRegNextThread(thread_t *tp) {
/*lint -restore*/ /*lint -restore*/
ntp = NULL; ntp = NULL;
} }
#if CH_CFG_USE_DYNAMIC == TRUE
else {
chDbgAssert(ntp->refs < (trefs_t)255, "too many references");
ntp->refs++;
}
#endif
chSysUnlock(); chSysUnlock();
#if CH_CFG_USE_DYNAMIC == TRUE
chThdRelease(tp);
#endif
return ntp; return ntp;
} }
@ -186,7 +202,6 @@ thread_t *chRegFindThreadByName(const char *name) {
return NULL; return NULL;
} }
#endif /* CH_CFG_USE_REGISTRY == TRUE */
/** /**
* @brief Confirms that a pointer is a valid thread pointer. * @brief Confirms that a pointer is a valid thread pointer.
@ -212,4 +227,6 @@ thread_t *chRegFindThreadByPointer(thread_t *tp) {
return NULL; return NULL;
} }
#endif /* CH_CFG_USE_REGISTRY == TRUE */
/** @} */ /** @} */

View File

@ -129,6 +129,7 @@ void chSysInit(void) {
/* Setting up the caller as current thread.*/ /* Setting up the caller as current thread.*/
currp->state = CH_STATE_CURRENT; currp->state = CH_STATE_CURRENT;
currp->flags = CH_FLAG_MODE_STATIC;
/* Port layer initialization last because it depend on some of the /* Port layer initialization last because it depend on some of the
initializations performed before.*/ initializations performed before.*/

View File

@ -175,6 +175,7 @@ thread_t *chThdCreateSuspendedI(const thread_descriptor_t *tdp) {
/* Initial state.*/ /* Initial state.*/
tp->state = CH_STATE_WTSTART; tp->state = CH_STATE_WTSTART;
tp->flags = CH_FLAG_MODE_STATIC;
/* Stack boundary.*/ /* Stack boundary.*/
tp->stklimit = tdp->wbase; tp->stklimit = tdp->wbase;