Merge pull request #1580 from Kijewski/thread_get

core: add `thread_get()`
dev/timer
Martine Lenders 9 years ago
commit 6999e6fb21

@ -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
*

@ -37,22 +37,24 @@ inline kernel_pid_t thread_getpid(void)
return sched_active_thread->pid;
}
int thread_getstatus(kernel_pid_t pid)
volatile tcb_t *thread_get(kernel_pid_t pid)
{
if (sched_threads[pid] == NULL) {
return STATUS_NOT_FOUND;
if ((pid != KERNEL_PID_UNDEF) && (0 <= pid) && (pid < MAXTHREADS)) {
return sched_threads[pid];
}
return NULL;
}
return sched_threads[pid]->status;
int thread_getstatus(kernel_pid_t pid)
{
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)

Loading…
Cancel
Save