mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
core/thread: Add/change helper access functions
- Add `thread_get_active()` to access the TCB - Add `thread_get_unchecked()` as fast alternative to `thread_get()` - Drop `volatile` qualifier in `thread_get()` - Right now every caller of this function does this. It is better to contain this undefined behavior to at least one place in code
This commit is contained in:
parent
e81d0050d1
commit
4a31578982
@ -349,6 +349,17 @@ kernel_pid_t thread_create(char *stack,
|
||||
void *arg,
|
||||
const char *name);
|
||||
|
||||
/**
|
||||
* @brief Retrieve a thread control block by PID.
|
||||
* @pre @p pid is valid
|
||||
* @param[in] pid Thread to retrieve.
|
||||
* @return `NULL` if the PID is invalid or there is no such thread.
|
||||
*/
|
||||
static inline thread_t *thread_get_unchecked(kernel_pid_t pid)
|
||||
{
|
||||
return (thread_t *)sched_threads[pid];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Retrieve a thread control block by PID.
|
||||
* @details This is a bound-checked variant of accessing `sched_threads[pid]` directly.
|
||||
@ -356,10 +367,10 @@ kernel_pid_t thread_create(char *stack,
|
||||
* @param[in] pid Thread to retrieve.
|
||||
* @return `NULL` if the PID is invalid or there is no such thread.
|
||||
*/
|
||||
static inline volatile thread_t *thread_get(kernel_pid_t pid)
|
||||
static inline thread_t *thread_get(kernel_pid_t pid)
|
||||
{
|
||||
if (pid_is_valid(pid)) {
|
||||
return sched_threads[pid];
|
||||
return thread_get_unchecked(pid);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@ -449,6 +460,20 @@ static inline kernel_pid_t thread_getpid(void)
|
||||
return sched_active_pid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns a pointer to the Thread Control Block of the currently
|
||||
* running thread
|
||||
*
|
||||
* @return Pointer to the TCB of the currently running thread, or `NULL` if
|
||||
* no thread is running
|
||||
*/
|
||||
static inline thread_t *thread_get_active(void)
|
||||
{
|
||||
extern volatile thread_t *sched_active_thread;
|
||||
|
||||
return (thread_t *)sched_active_thread;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets called upon thread creation to set CPU registers
|
||||
*
|
||||
@ -495,7 +520,7 @@ const char *thread_getname(kernel_pid_t pid);
|
||||
*
|
||||
* Only works if the thread was created with the flag THREAD_CREATE_STACKTEST.
|
||||
*
|
||||
* @param[in] stack the stack you want to measure. try `sched_active_thread->stack_start`
|
||||
* @param[in] stack the stack you want to measure. Try `thread_get_active()->stack_start`
|
||||
*
|
||||
* @return the amount of unused space of the thread's stack
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user