Go to the documentation of this file.
90 tp->hdr.
pqueue.prio = prio;
93 #if CH_CFG_TIME_QUANTUM > 0
96 #if CH_CFG_USE_MUTEXES == TRUE
100 #if CH_CFG_USE_EVENTS == TRUE
103 #if CH_DBG_THREADS_PROFILING == TRUE
106 #if CH_CFG_USE_REGISTRY == TRUE
107 tp->
refs = (trefs_t)1;
113 #if CH_CFG_USE_WAITEXIT == TRUE
116 #if CH_CFG_USE_MESSAGES == TRUE
119 #if CH_DBG_STATISTICS == TRUE
126 #if (CH_DBG_FILL_THREADS == TRUE) || defined(__DOXYGEN__)
138 while (startp < endp) {
184 #if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE)
190 PORT_SETUP_CONTEXT(tp, tdp->
wbase, tp, tdp->
funcp, tdp->
arg);
219 #if CH_CFG_USE_REGISTRY == TRUE
221 "working area in use");
224 #if CH_DBG_FILL_THREADS == TRUE
226 (uint8_t *)tdp->
wend,
283 #if (CH_CFG_USE_REGISTRY == TRUE) && \
284 ((CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE))
286 "working area in use");
289 #if CH_DBG_FILL_THREADS == TRUE
291 (uint8_t *)tdp->
wend,
324 tprio_t prio,
tfunc_t pf,
void *arg) {
331 (prio <=
HIGHPRIO) && (pf != NULL));
333 #if (CH_CFG_USE_REGISTRY == TRUE) && \
334 ((CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE))
336 "working area in use");
339 #if CH_DBG_FILL_THREADS == TRUE
341 (uint8_t *)wsp + size,
350 tp = (
thread_t *)((uint8_t *)wsp + size -
353 #if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE)
355 tp->
wabase = (stkalign_t *)wsp;
359 PORT_SETUP_CONTEXT(tp, wsp, tp, pf, arg);
389 #if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__)
440 #if CH_CFG_USE_DYNAMIC == TRUE
442 #if CH_CFG_USE_HEAP == TRUE
447 #if CH_CFG_USE_MEMPOOLS == TRUE
510 #if CH_CFG_USE_WAITEXIT == TRUE
517 #if CH_CFG_USE_REGISTRY == TRUE
520 #if CH_CFG_USE_DYNAMIC == TRUE
521 if ((tp->
refs == (trefs_t)0) &&
526 if (tp->
refs == (trefs_t)0) {
539 #if (CH_CFG_USE_WAITEXIT == TRUE) || defined(__DOXYGEN__)
566 #if CH_CFG_USE_REGISTRY == TRUE
577 #if CH_CFG_USE_REGISTRY == TRUE
604 #if CH_CFG_USE_MUTEXES == TRUE
605 oldprio =
currp->realprio;
606 if ((
currp->hdr.pqueue.prio ==
currp->realprio) ||
607 (newprio >
currp->hdr.pqueue.prio)) {
608 currp->hdr.pqueue.prio = newprio;
610 currp->realprio = newprio;
612 oldprio =
currp->hdr.pqueue.prio;
613 currp->hdr.pqueue.prio = newprio;
static void chSchDoYieldS(void)
Yields the time slot.
thread_reference_t * wttrp
Pointer to a generic thread reference object.
thread_t * chThdCreateSuspended(const thread_descriptor_t *tdp)
Creates a new thread into a static memory area.
msg_t chThdSuspendTimeoutS(thread_reference_t *trp, sysinterval_t timeout)
Sends the current thread sleeping and sets a reference variable.
static void chSysLock(void)
Enters the kernel lock state.
thread_t * chSchReadyI(thread_t *tp)
Inserts a thread in the Ready List placing it behind its peers.
tprio_t realprio
Thread's own, non-inherited, priority.
eventmask_t epending
Pending events mask.
#define CH_FLAG_MODE_MASK
Thread memory mode mask.
ch_priority_queue_t pqueue
Threads ordered queues element.
#define THD_WORKING_AREA_SIZE(n)
Calculates the total Working Area size.
void chPoolFree(memory_pool_t *mp, void *objp)
Releases an object into a memory pool.
#define CH_STATE_WTSTART
Just created.
#define currp
Current thread pointer access macro.
msg_t rdymsg
Thread wakeup code.
#define CH_CFG_TIME_QUANTUM
Round robin interval.
thread_t * chThdAddRef(thread_t *tp)
Adds a reference to a thread object.
static systime_t chVTGetSystemTimeX(void)
Current system time.
Structure representing a threads queue.
thread_t * chThdCreateStatic(void *wsp, size_t size, tprio_t prio, tfunc_t pf, void *arg)
Creates a new thread into a static memory area.
uint64_t systime_t
Type of system time.
#define chDbgAssert(c, r)
Condition assertion.
#define CH_STATE_SUSPENDED
Suspended state.
stkalign_t * wend
End of the working area.
thread_t * chThdCreateSuspendedI(const thread_descriptor_t *tdp)
Creates a new thread into a static memory area.
void(* tfunc_t)(void *p)
Thread function.
struct ch_mutex * mtxlist
List of the mutexes owned by this thread.
#define CH_DBG_STACK_FILL_VALUE
Fill value for thread stack area in debug mode.
void chHeapFree(void *p)
Frees a previously allocated memory block.
void chThdResumeS(thread_reference_t *trp, msg_t msg)
Wakes up a thread waiting on a thread reference object.
static sysinterval_t chTimeDiffX(systime_t start, systime_t end)
Subtracts two system times returning an interval.
#define CH_CFG_THREAD_EXIT_HOOK(tp)
Threads finalization hook.
thread_t * chThdCreateI(const thread_descriptor_t *tdp)
Creates a new thread into a static memory area.
static bool ch_queue_notempty(const ch_queue_t *qp)
Evaluates to true if the specified queue is not empty.
static stkalign_t * chThdGetWorkingAreaX(thread_t *tp)
Returns the working area base of the specified thread.
#define CH_CFG_THREAD_INIT_HOOK(tp)
Threads initialization hook.
msg_t chSchGoSleepTimeoutS(tstate_t newstate, sysinterval_t timeout)
Puts the current thread to sleep into the specified state with timeout specification.
#define CH_FLAG_MODE_MPOOL
Thread allocated from a Memory Pool.
stkalign_t * wbase
Pointer to the working area base.
void chThdDequeueAllI(threads_queue_t *tqp, msg_t msg)
Dequeues and wakes up all threads from the threads queue object.
#define REG_INSERT(tp)
Adds a thread to the registry list.
void chThdTerminate(thread_t *tp)
Requests a thread termination.
msg_t chThdEnqueueTimeoutS(threads_queue_t *tqp, sysinterval_t timeout)
Enqueues the caller thread on a threads queue object.
#define chDbgCheck(c)
Function parameters check.
trefs_t refs
References to this thread.
#define TIME_IMMEDIATE
Zero interval specification for some functions with a timeout specification.
static void ch_list_push(ch_list_t *p, ch_list_t *lp)
Pushes an element on top of a stack list.
const char * name
Thread name or NULL.
#define MEM_IS_ALIGNED(p, a)
Returns whatever a pointer or memory size is aligned.
tfunc_t funcp
Thread function pointer.
void chThdResumeI(thread_reference_t *trp, msg_t msg)
Wakes up a thread waiting on a thread reference object.
static bool ch_list_notempty(ch_list_t *lp)
Evaluates to true if the specified list is not empty.
#define HIGHPRIO
Highest priority.
Structure representing a thread.
void _thread_memfill(uint8_t *startp, uint8_t *endp, uint8_t v)
Memory fill utility.
void chSchGoSleepS(tstate_t newstate)
Puts the current thread to sleep into the specified state.
stkalign_t * wabase
Working area base address.
thread_t * chRegFindThreadByWorkingArea(stkalign_t *wa)
Confirms that a working area is being used by some active thread.
tslices_t ticks
Number of ticks remaining to this thread.
msg_t chThdWait(thread_t *tp)
Blocks the execution of the invoking thread until the specified thread terminates then the exit code ...
#define CH_FLAG_MODE_HEAP
Thread allocated from a Memory Heap.
#define CH_STATE_FINAL
Thread terminated.
ch_queue_t msgqueue
Messages queue.
union ch_thread::@1 u
State-specific fields.
Type of a thread descriptor.
tprio_t chThdSetPriority(tprio_t newprio)
Changes the running thread priority level then reschedules if necessary.
#define MEM_ALIGN_NEXT(p, a)
Aligns to the next aligned memory address.
void * arg
Thread argument.
msg_t chThdSuspendS(thread_reference_t *trp)
Sends the current thread sleeping and sets a reference variable.
static ch_list_t * ch_list_pop(ch_list_t *lp)
Pops an element from the top of a stack list and returns it.
static void chThdDoDequeueNextI(threads_queue_t *tqp, msg_t msg)
Dequeues and wakes up one thread from the threads queue object.
void chSchRescheduleS(void)
Performs a reschedule if a higher priority thread is runnable.
static void ch_queue_init(ch_queue_t *qp)
Queue initialization.
void chDbgCheckClassI(void)
I-class functions context check.
#define CH_FLAG_TERMINATE
Termination requested flag.
#define MSG_OK
Normal wakeup message.
thread_t * _thread_init(thread_t *tp, const char *name, tprio_t prio)
Initializes a thread structure.
void chTMObjectInit(time_measurement_t *tmp)
Initializes a TimeMeasurement object.
volatile systime_t time
Thread consumed time in ticks.
void chThdYield(void)
Yields the time slot.
#define CH_FLAG_MODE_STATIC
Static thread.
systime_t chThdSleepUntilWindowed(systime_t prev, systime_t next)
Suspends the invoking thread until the system time arrives to the specified value.
uint64_t sysinterval_t
Type of time interval.
void chThdSleep(sysinterval_t time)
Suspends the invoking thread for the specified time.
static void chThdSleepS(sysinterval_t ticks)
Suspends the invoking thread for the specified number of ticks.
void * mpool
Memory Pool where the thread workspace is returned.
thread_t * chThdCreate(const thread_descriptor_t *tdp)
Creates a new thread into a static memory area.
void chThdDequeueNextI(threads_queue_t *tqp, msg_t msg)
Dequeues and wakes up one thread from the threads queue object, if any.
#define CH_STATE_QUEUED
On a queue.
const char * name
Thread name.
tstate_t state
Current thread state.
ChibiOS/RT main include file.
#define MSG_TIMEOUT
Wakeup caused by a timeout condition.
static void chSysUnlock(void)
Leaves the kernel lock state.
time_measurement_t stats
Thread statistics.
void chThdResume(thread_reference_t *trp, msg_t msg)
Wakes up a thread waiting on a thread reference object.
#define REG_REMOVE(tp)
Removes a thread from the registry list.
msg_t exitcode
Thread exit code.
ch_list_t waiting
Termination waiting list.
void chThdExitS(msg_t msg)
Terminates the current thread.
thread_t * chThdStart(thread_t *tp)
Resumes a thread created with chThdCreateI().
static bool chTimeIsInRangeX(systime_t time, systime_t start, systime_t end)
Checks if the specified time is within the specified time range.
void chThdRelease(thread_t *tp)
Releases a reference to a thread object.
tprio_t prio
Thread priority.
void chThdSleepUntil(systime_t time)
Suspends the invoking thread until the system time arrives to the specified value.
static thread_t * chThdGetSelfX(void)
Returns a pointer to the current thread_t.
static void ch_queue_insert(ch_queue_t *p, ch_queue_t *qp)
Inserts an element into a queue.
tmode_t flags
Various thread flags.
void chSchWakeupS(thread_t *ntp, msg_t msg)
Wakes up a thread.
#define CH_STATE_WTEXIT
Waiting a thread.
void chThdExit(msg_t msg)
Terminates the current thread.
ch_queue_t queue
Threads queue header.
static void ch_list_init(ch_list_t *lp)
List initialization.