1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-25 06:23:53 +01:00

Merge pull request #1580 from Kijewski/thread_get

core: add `thread_get()`
This commit is contained in:
Martine Lenders 2014-08-16 21:48:49 +02:00
commit 6999e6fb21
2 changed files with 22 additions and 10 deletions

View File

@ -79,6 +79,16 @@ kernel_pid_t thread_create(char *stack,
void *(*function)(void *arg),
void *arg,
const char *name);
/**
* @brief Retreive a thread control block by PID.
* @details This is a bound-checked variant of accessing `sched_threads[pid]` directly.
* If you know that the PID is valid, then don't use this function.
* @param[in] pid Thread to retreive.
* @return `NULL` if the PID is invalid or there is no such thread.
*/
volatile tcb_t *thread_get(kernel_pid_t pid);
/**
* @brief Returns the status of a process
*

View File

@ -37,22 +37,24 @@ inline kernel_pid_t thread_getpid(void)
return sched_active_thread->pid;
}
volatile tcb_t *thread_get(kernel_pid_t pid)
{
if ((pid != KERNEL_PID_UNDEF) && (0 <= pid) && (pid < MAXTHREADS)) {
return sched_threads[pid];
}
return NULL;
}
int thread_getstatus(kernel_pid_t pid)
{
if (sched_threads[pid] == NULL) {
return STATUS_NOT_FOUND;
}
return sched_threads[pid]->status;
volatile tcb_t *t = thread_get(pid);
return t ? t->status : STATUS_NOT_FOUND;
}
const char *thread_getname(kernel_pid_t pid)
{
if (sched_threads[pid] == NULL) {
return NULL;
}
return sched_threads[pid]->name;
volatile tcb_t *t = thread_get(pid);
return t ? t->name : NULL;
}
void thread_sleep(void)