1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

core: rename tcb_t -> thread_t, move into thread.h

This commit is contained in:
Kaspar Schleiser 2016-01-04 22:29:34 +01:00
parent 32d48bb16b
commit 2b010b5337
22 changed files with 152 additions and 185 deletions

View File

@ -68,7 +68,6 @@ extern "C" {
* @{ * @{
*/ */
#if ENABLE_DEBUG #if ENABLE_DEBUG
#include "tcb.h"
/** /**
* @def DEBUG_FUNC * @def DEBUG_FUNC

View File

@ -83,15 +83,20 @@
#include <stddef.h> #include <stddef.h>
#include "attributes.h" #include "attributes.h"
#include "bitarithm.h" #include "bitarithm.h"
#include "tcb.h"
#include "attributes.h" #include "attributes.h"
#include "kernel_types.h" #include "kernel_types.h"
#include "native_sched.h" #include "native_sched.h"
#include "clist.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/**
* @brief forward declaration for thread_t, defined in thread.h
*/
typedef struct _thread thread_t;
/** /**
* @def SCHED_PRIO_LEVELS * @def SCHED_PRIO_LEVELS
* @brief The number of thread priority levels * @brief The number of thread priority levels
@ -113,7 +118,7 @@ int sched_run(void);
* targeted process * targeted process
* @param[in] status The new status of this thread * @param[in] status The new status of this thread
*/ */
void sched_set_status(tcb_t *process, unsigned int status); void sched_set_status(thread_t *process, unsigned int status);
/** /**
* @brief Yield if approriate. * @brief Yield if approriate.
@ -143,12 +148,12 @@ extern volatile unsigned int sched_context_switch_request;
/** /**
* Thread table * Thread table
*/ */
extern volatile tcb_t *sched_threads[KERNEL_PID_LAST + 1]; extern volatile thread_t *sched_threads[KERNEL_PID_LAST + 1];
/** /**
* Currently active thread * Currently active thread
*/ */
extern volatile tcb_t *sched_active_thread; extern volatile thread_t *sched_active_thread;
/** /**
* Number of running (non-terminated) threads * Number of running (non-terminated) threads

View File

@ -1,91 +0,0 @@
/*
* Copyright (C) 2013 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @addtogroup core_thread
* @{
*
* @file
* @brief Thread context block definition
*
* @author Heiko Will
* @author Kaspar Schleiser <kaspar@schleiser.de>
*/
#ifndef TCB_H_
#define TCB_H_
#include <stdint.h>
#include "priority_queue.h"
#include "clist.h"
#include "cib.h"
#include "msg.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Thread status list
* @{
*/
/**
* @brief Blocked states.
* @{
*/
#define STATUS_STOPPED 0 /**< has terminated */
#define STATUS_SLEEPING 1 /**< sleeping */
#define STATUS_MUTEX_BLOCKED 2 /**< waiting for a locked mutex */
#define STATUS_RECEIVE_BLOCKED 3 /**< waiting for a message */
#define STATUS_SEND_BLOCKED 4 /**< waiting for message to be delivered*/
#define STATUS_REPLY_BLOCKED 5 /**< waiting for a message response */
/** @} */
/**
* @brief These have to be on a run queue.
* @{*/
#define STATUS_ON_RUNQUEUE STATUS_RUNNING /**< to check if on run queue:
`st >= STATUS_ON_RUNQUEUE` */
#define STATUS_RUNNING 6 /**< currently running */
#define STATUS_PENDING 7 /**< waiting to be scheduled to run */
/** @} */
/** @} */
/**
* @brief @c tcb_t holds thread's context data.
*/
typedef struct tcb_t {
char *sp; /**< thread's stack pointer */
uint8_t status; /**< thread's status */
uint8_t priority; /**< thread's priority */
kernel_pid_t pid; /**< thread's process id */
clist_node_t rq_entry; /**< run queue entry */
void *wait_data; /**< holding messages */
priority_queue_t msg_waiters; /**< threads waiting on message */
cib_t msg_queue; /**< message queue */
msg_t *msg_array; /**< memory holding messages */
#if defined DEVELHELP || defined(SCHED_TEST_STACK)
char *stack_start; /**< thread's stack start address */
#endif
#ifdef DEVELHELP
const char *name; /**< thread's name */
int stack_size; /**< thread's stack size */
#endif
} tcb_t;
#ifdef __cplusplus
}
#endif
#endif /* TCB_H_ */
/** @} */

View File

@ -22,10 +22,12 @@
#ifndef THREAD_H #ifndef THREAD_H
#define THREAD_H #define THREAD_H
#include "cpu.h" #include "priority_queue.h"
#include "cpu_conf.h" #include "clist.h"
#include "tcb.h" #include "cib.h"
#include "msg.h"
#include "arch/thread_arch.h" #include "arch/thread_arch.h"
#include "cpu_conf.h"
#include "sched.h" #include "sched.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -33,9 +35,59 @@
#endif #endif
/** /**
* @brief Describes an illegal thread status * @brief Thread status list
* @{
*/ */
#define STATUS_NOT_FOUND (-1) #define STATUS_NOT_FOUND (-1) /**< Describes an illegal thread status */
/**
* @brief Blocked states.
* @{
*/
#define STATUS_STOPPED 0 /**< has terminated */
#define STATUS_SLEEPING 1 /**< sleeping */
#define STATUS_MUTEX_BLOCKED 2 /**< waiting for a locked mutex */
#define STATUS_RECEIVE_BLOCKED 3 /**< waiting for a message */
#define STATUS_SEND_BLOCKED 4 /**< waiting for message to be delivered*/
#define STATUS_REPLY_BLOCKED 5 /**< waiting for a message response */
/** @} */
/**
* @brief These have to be on a run queue.
* @{*/
#define STATUS_ON_RUNQUEUE STATUS_RUNNING /**< to check if on run queue:
`st >= STATUS_ON_RUNQUEUE` */
#define STATUS_RUNNING 6 /**< currently running */
#define STATUS_PENDING 7 /**< waiting to be scheduled to run */
/** @} */
/** @} */
/**
* @brief @c thread_t holds thread's context data.
*/
struct _thread {
char *sp; /**< thread's stack pointer */
uint8_t status; /**< thread's status */
uint8_t priority; /**< thread's priority */
kernel_pid_t pid; /**< thread's process id */
clist_node_t rq_entry; /**< run queue entry */
void *wait_data; /**< holding messages */
priority_queue_t msg_waiters; /**< threads waiting on message */
cib_t msg_queue; /**< message queue */
msg_t *msg_array; /**< memory holding messages */
#if defined DEVELHELP || defined(SCHED_TEST_STACK)
char *stack_start; /**< thread's stack start address */
#endif
#ifdef DEVELHELP
const char *name; /**< thread's name */
int stack_size; /**< thread's stack size */
#endif
};
/** /**
* @def THREAD_STACKSIZE_DEFAULT * @def THREAD_STACKSIZE_DEFAULT
@ -74,7 +126,7 @@
* @brief Minimum stack size * @brief Minimum stack size
*/ */
#ifndef THREAD_STACKSIZE_MINIMUM #ifndef THREAD_STACKSIZE_MINIMUM
#define THREAD_STACKSIZE_MINIMUM (sizeof(tcb_t)) #define THREAD_STACKSIZE_MINIMUM (sizeof(thread_t))
#endif #endif
/** /**
@ -128,8 +180,8 @@
* 1. the new thread's stack is initialized depending on the platform * 1. the new thread's stack is initialized depending on the platform
* 2. the new thread is added to the scheduler to be run * 2. the new thread is added to the scheduler to be run
* *
* As RIOT is using a fixed priority scheduling algorithm, threads * As RIOT is using a fixed priority scheduling algorithm, threads are
* are scheduled base on their priority. The priority is fixed for every thread * scheduled based on their priority. The priority is fixed for every thread
* and specified during the threads creation by the *priority* parameter. * and specified during the threads creation by the *priority* parameter.
* *
* A low value for *priority* number means the thread having a high priority * A low value for *priority* number means the thread having a high priority
@ -142,15 +194,16 @@
* In addition to the priority, the *flags* argument can be used to alter the * In addition to the priority, the *flags* argument can be used to alter the
* newly created threads behavior after creation. The following flags are available: * newly created threads behavior after creation. The following flags are available:
* - THREAD_CREATE_SLEEPING the newly created thread will be put to sleeping * - THREAD_CREATE_SLEEPING the newly created thread will be put to sleeping
* state and must be waken up manually * state and must be woken up manually
* - THREAD_CREATE_WOUT_YIELD the newly created thread will not run * - THREAD_CREATE_WOUT_YIELD the newly created thread will not run
* immediately after creation * immediately after creation
* - THREAD_CREATE_STACKTEST write markers into the thread's stack to measure * - THREAD_CREATE_STACKTEST write markers into the thread's stack to measure
* the stack's memory usage (for debugging and * the stack's memory usage (for debugging and
* profiling purposes) * profiling purposes)
* *
* @note Currently we support creating threads from within an ISR, however it is considered * @note Currently we support creating threads from within an ISR, however it
* to be a bad programming practice and we strongly discourage it. * is considered to be a bad programming practice and we strongly discourage
* it.
* *
* @param[out] stack start address of the preallocated stack memory * @param[out] stack start address of the preallocated stack memory
* @param[in] stacksize the size of the thread's stack in bytes * @param[in] stacksize the size of the thread's stack in bytes
@ -180,7 +233,7 @@ kernel_pid_t thread_create(char *stack,
* @param[in] pid Thread to retreive. * @param[in] pid Thread to retreive.
* @return `NULL` if the PID is invalid or there is no such thread. * @return `NULL` if the PID is invalid or there is no such thread.
*/ */
volatile tcb_t *thread_get(kernel_pid_t pid); volatile thread_t *thread_get(kernel_pid_t pid);
/** /**
* @brief Returns the status of a process * @brief Returns the status of a process
@ -234,7 +287,6 @@ void thread_yield_higher(void);
*/ */
int thread_wakeup(kernel_pid_t pid); int thread_wakeup(kernel_pid_t pid);
/** /**
* @brief Returns the process ID of the currently running thread * @brief Returns the process ID of the currently running thread
* *
@ -242,6 +294,7 @@ int thread_wakeup(kernel_pid_t pid);
*/ */
static inline kernel_pid_t thread_getpid(void) static inline kernel_pid_t thread_getpid(void)
{ {
extern volatile kernel_pid_t sched_active_pid;
return sched_active_pid; return sched_active_pid;
} }

View File

@ -26,7 +26,7 @@
#include "sched.h" #include "sched.h"
#include "msg.h" #include "msg.h"
#include "priority_queue.h" #include "priority_queue.h"
#include "tcb.h" #include "thread.h"
#include "irq.h" #include "irq.h"
#include "cib.h" #include "cib.h"
@ -37,7 +37,7 @@
static int _msg_receive(msg_t *m, int block); static int _msg_receive(msg_t *m, int block);
static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block, unsigned state); static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block, unsigned state);
static int queue_msg(tcb_t *target, const msg_t *m) static int queue_msg(thread_t *target, const msg_t *m)
{ {
int n = cib_put(&(target->msg_queue)); int n = cib_put(&(target->msg_queue));
if (n < 0) { if (n < 0) {
@ -81,7 +81,7 @@ static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block, unsigned sta
} }
#endif /* DEVELHELP */ #endif /* DEVELHELP */
tcb_t *target = (tcb_t*) sched_threads[target_pid]; thread_t *target = (thread_t*) sched_threads[target_pid];
m->sender_pid = sched_active_pid; m->sender_pid = sched_active_pid;
@ -140,7 +140,7 @@ static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block, unsigned sta
newstatus = STATUS_SEND_BLOCKED; newstatus = STATUS_SEND_BLOCKED;
} }
sched_set_status((tcb_t*) sched_active_thread, newstatus); sched_set_status((thread_t*) sched_active_thread, newstatus);
DEBUG("msg_send: %" PRIkernel_pid ": Back from send block.\n", DEBUG("msg_send: %" PRIkernel_pid ": Back from send block.\n",
sched_active_thread->pid); sched_active_thread->pid);
@ -169,7 +169,7 @@ int msg_send_to_self(msg_t *m)
unsigned state = disableIRQ(); unsigned state = disableIRQ();
m->sender_pid = sched_active_pid; m->sender_pid = sched_active_pid;
int res = queue_msg((tcb_t *) sched_active_thread, m); int res = queue_msg((thread_t *) sched_active_thread, m);
restoreIRQ(state); restoreIRQ(state);
return res; return res;
@ -183,7 +183,7 @@ int msg_send_int(msg_t *m, kernel_pid_t target_pid)
} }
#endif /* DEVELHELP */ #endif /* DEVELHELP */
tcb_t *target = (tcb_t *) sched_threads[target_pid]; thread_t *target = (thread_t *) sched_threads[target_pid];
if (target == NULL) { if (target == NULL) {
DEBUG("msg_send_int(): target thread does not exist\n"); DEBUG("msg_send_int(): target thread does not exist\n");
@ -214,7 +214,7 @@ int msg_send_receive(msg_t *m, msg_t *reply, kernel_pid_t target_pid)
{ {
assert(sched_active_pid != target_pid); assert(sched_active_pid != target_pid);
unsigned state = disableIRQ(); unsigned state = disableIRQ();
tcb_t *me = (tcb_t*) sched_threads[sched_active_pid]; thread_t *me = (thread_t*) sched_threads[sched_active_pid];
sched_set_status(me, STATUS_REPLY_BLOCKED); sched_set_status(me, STATUS_REPLY_BLOCKED);
me->wait_data = (void*) reply; me->wait_data = (void*) reply;
@ -226,7 +226,7 @@ int msg_reply(msg_t *m, msg_t *reply)
{ {
unsigned state = disableIRQ(); unsigned state = disableIRQ();
tcb_t *target = (tcb_t*) sched_threads[m->sender_pid]; thread_t *target = (thread_t*) sched_threads[m->sender_pid];
assert(target != NULL); assert(target != NULL);
if (target->status != STATUS_REPLY_BLOCKED) { if (target->status != STATUS_REPLY_BLOCKED) {
@ -251,7 +251,7 @@ int msg_reply(msg_t *m, msg_t *reply)
int msg_reply_int(msg_t *m, msg_t *reply) int msg_reply_int(msg_t *m, msg_t *reply)
{ {
tcb_t *target = (tcb_t*) sched_threads[m->sender_pid]; thread_t *target = (thread_t*) sched_threads[m->sender_pid];
if (target->status != STATUS_REPLY_BLOCKED) { if (target->status != STATUS_REPLY_BLOCKED) {
DEBUG("msg_reply_int(): %" PRIkernel_pid ": Target \"%" PRIkernel_pid DEBUG("msg_reply_int(): %" PRIkernel_pid ": Target \"%" PRIkernel_pid
@ -282,7 +282,7 @@ static int _msg_receive(msg_t *m, int block)
DEBUG("_msg_receive: %" PRIkernel_pid ": _msg_receive.\n", DEBUG("_msg_receive: %" PRIkernel_pid ": _msg_receive.\n",
sched_active_thread->pid); sched_active_thread->pid);
tcb_t *me = (tcb_t*) sched_threads[sched_active_pid]; thread_t *me = (thread_t*) sched_threads[sched_active_pid];
int queue_index = -1; int queue_index = -1;
@ -330,7 +330,7 @@ static int _msg_receive(msg_t *m, int block)
else { else {
DEBUG("_msg_receive: %" PRIkernel_pid ": _msg_receive(): Waking up waiting thread.\n", DEBUG("_msg_receive: %" PRIkernel_pid ": _msg_receive(): Waking up waiting thread.\n",
sched_active_thread->pid); sched_active_thread->pid);
tcb_t *sender = (tcb_t*) node->data; thread_t *sender = (thread_t*) node->data;
if (queue_index >= 0) { if (queue_index >= 0) {
/* We've already got a message from the queue. As there is a /* We've already got a message from the queue. As there is a
@ -366,7 +366,7 @@ int msg_avail(void)
DEBUG("msg_available: %" PRIkernel_pid ": msg_available.\n", DEBUG("msg_available: %" PRIkernel_pid ": msg_available.\n",
sched_active_thread->pid); sched_active_thread->pid);
tcb_t *me = (tcb_t*) sched_active_thread; thread_t *me = (thread_t*) sched_active_thread;
int queue_index = -1; int queue_index = -1;
@ -381,7 +381,7 @@ int msg_init_queue(msg_t *array, int num)
{ {
/* check if num is a power of two by comparing to its complement */ /* check if num is a power of two by comparing to its complement */
if (num && (num & (num - 1)) == 0) { if (num && (num & (num - 1)) == 0) {
tcb_t *me = (tcb_t*) sched_active_thread; thread_t *me = (thread_t*) sched_active_thread;
me->msg_array = array; me->msg_array = array;
cib_init(&(me->msg_queue), num); cib_init(&(me->msg_queue), num);
return 0; return 0;

View File

@ -23,7 +23,7 @@
#include <inttypes.h> #include <inttypes.h>
#include "mutex.h" #include "mutex.h"
#include "tcb.h" #include "thread.h"
#include "atomic.h" #include "atomic.h"
#include "sched.h" #include "sched.h"
#include "thread.h" #include "thread.h"
@ -63,7 +63,7 @@ static void mutex_wait(struct mutex_t *mutex)
return; return;
} }
sched_set_status((tcb_t*) sched_active_thread, STATUS_MUTEX_BLOCKED); sched_set_status((thread_t*) sched_active_thread, STATUS_MUTEX_BLOCKED);
priority_queue_node_t n; priority_queue_node_t n;
n.priority = (unsigned int) sched_active_thread->priority; n.priority = (unsigned int) sched_active_thread->priority;
@ -100,7 +100,7 @@ void mutex_unlock(struct mutex_t *mutex)
return; return;
} }
tcb_t *process = (tcb_t *) next->data; thread_t *process = (thread_t *) next->data;
DEBUG("mutex_unlock: waking up waiting thread %" PRIkernel_pid "\n", process->pid); DEBUG("mutex_unlock: waking up waiting thread %" PRIkernel_pid "\n", process->pid);
sched_set_status(process, STATUS_PENDING); sched_set_status(process, STATUS_PENDING);
@ -117,7 +117,7 @@ void mutex_unlock_and_sleep(struct mutex_t *mutex)
if (ATOMIC_VALUE(mutex->val) != 0) { if (ATOMIC_VALUE(mutex->val) != 0) {
priority_queue_node_t *next = priority_queue_remove_head(&(mutex->queue)); priority_queue_node_t *next = priority_queue_remove_head(&(mutex->queue));
if (next) { if (next) {
tcb_t *process = (tcb_t *) next->data; thread_t *process = (thread_t *) next->data;
DEBUG("%s: waking up waiter.\n", process->name); DEBUG("%s: waking up waiter.\n", process->name);
sched_set_status(process, STATUS_PENDING); sched_set_status(process, STATUS_PENDING);
} }
@ -126,7 +126,7 @@ void mutex_unlock_and_sleep(struct mutex_t *mutex)
} }
} }
DEBUG("%s: going to sleep.\n", sched_active_thread->name); DEBUG("%s: going to sleep.\n", sched_active_thread->name);
sched_set_status((tcb_t*) sched_active_thread, STATUS_SLEEPING); sched_set_status((thread_t*) sched_active_thread, STATUS_SLEEPING);
restoreIRQ(irqstate); restoreIRQ(irqstate);
thread_yield_higher(); thread_yield_higher();
} }

View File

@ -45,8 +45,8 @@ volatile int sched_num_threads = 0;
volatile unsigned int sched_context_switch_request; volatile unsigned int sched_context_switch_request;
volatile tcb_t *sched_threads[KERNEL_PID_LAST + 1]; volatile thread_t *sched_threads[KERNEL_PID_LAST + 1];
volatile tcb_t *sched_active_thread; volatile thread_t *sched_active_thread;
volatile kernel_pid_t sched_active_pid = KERNEL_PID_UNDEF; volatile kernel_pid_t sched_active_pid = KERNEL_PID_UNDEF;
@ -62,13 +62,13 @@ int sched_run(void)
{ {
sched_context_switch_request = 0; sched_context_switch_request = 0;
tcb_t *active_thread = (tcb_t *)sched_active_thread; thread_t *active_thread = (thread_t *)sched_active_thread;
/* The bitmask in runqueue_bitcache is never empty, /* The bitmask in runqueue_bitcache is never empty,
* since the threading should not be started before at least the idle thread was started. * since the threading should not be started before at least the idle thread was started.
*/ */
int nextrq = bitarithm_lsb(runqueue_bitcache); int nextrq = bitarithm_lsb(runqueue_bitcache);
tcb_t *next_thread = clist_get_container(sched_runqueues[nextrq], tcb_t, rq_entry); thread_t *next_thread = clist_get_container(sched_runqueues[nextrq], thread_t, rq_entry);
DEBUG("sched_run: active thread: %" PRIkernel_pid ", next thread: %" PRIkernel_pid "\n", DEBUG("sched_run: active thread: %" PRIkernel_pid ", next thread: %" PRIkernel_pid "\n",
(active_thread == NULL) ? KERNEL_PID_UNDEF : active_thread->pid, (active_thread == NULL) ? KERNEL_PID_UNDEF : active_thread->pid,
@ -113,7 +113,7 @@ int sched_run(void)
next_thread->status = STATUS_RUNNING; next_thread->status = STATUS_RUNNING;
sched_active_pid = next_thread->pid; sched_active_pid = next_thread->pid;
sched_active_thread = (volatile tcb_t *) next_thread; sched_active_thread = (volatile thread_t *) next_thread;
DEBUG("sched_run: done, changed sched_active_thread.\n"); DEBUG("sched_run: done, changed sched_active_thread.\n");
@ -127,7 +127,7 @@ void sched_register_cb(void (*callback)(uint32_t, uint32_t))
} }
#endif #endif
void sched_set_status(tcb_t *process, unsigned int status) void sched_set_status(thread_t *process, unsigned int status)
{ {
if (status >= STATUS_ON_RUNQUEUE) { if (status >= STATUS_ON_RUNQUEUE) {
if (!(process->status >= STATUS_ON_RUNQUEUE)) { if (!(process->status >= STATUS_ON_RUNQUEUE)) {
@ -154,7 +154,7 @@ void sched_set_status(tcb_t *process, unsigned int status)
void sched_switch(uint16_t other_prio) void sched_switch(uint16_t other_prio)
{ {
tcb_t *active_thread = (tcb_t *) sched_active_thread; thread_t *active_thread = (thread_t *) sched_active_thread;
uint16_t current_prio = active_thread->priority; uint16_t current_prio = active_thread->priority;
int on_runqueue = (active_thread->status >= STATUS_ON_RUNQUEUE); int on_runqueue = (active_thread->status >= STATUS_ON_RUNQUEUE);
@ -185,7 +185,7 @@ NORETURN void sched_task_exit(void)
sched_threads[sched_active_pid] = NULL; sched_threads[sched_active_pid] = NULL;
sched_num_threads--; sched_num_threads--;
sched_set_status((tcb_t *)sched_active_thread, STATUS_STOPPED); sched_set_status((thread_t *)sched_active_thread, STATUS_STOPPED);
sched_active_thread = NULL; sched_active_thread = NULL;
cpu_switch_context_exit(); cpu_switch_context_exit();

View File

@ -29,7 +29,7 @@
#include "bitarithm.h" #include "bitarithm.h"
#include "sched.h" #include "sched.h"
volatile tcb_t *thread_get(kernel_pid_t pid) volatile thread_t *thread_get(kernel_pid_t pid)
{ {
if (pid_is_valid(pid)) { if (pid_is_valid(pid)) {
return sched_threads[pid]; return sched_threads[pid];
@ -39,14 +39,14 @@ volatile tcb_t *thread_get(kernel_pid_t pid)
int thread_getstatus(kernel_pid_t pid) int thread_getstatus(kernel_pid_t pid)
{ {
volatile tcb_t *t = thread_get(pid); volatile thread_t *t = thread_get(pid);
return t ? (int) t->status : STATUS_NOT_FOUND; return t ? (int) t->status : STATUS_NOT_FOUND;
} }
#ifdef DEVELHELP #ifdef DEVELHELP
const char *thread_getname(kernel_pid_t pid) const char *thread_getname(kernel_pid_t pid)
{ {
volatile tcb_t *t = thread_get(pid); volatile thread_t *t = thread_get(pid);
return t ? t->name : NULL; return t ? t->name : NULL;
} }
#endif #endif
@ -58,7 +58,7 @@ void thread_sleep(void)
} }
unsigned state = disableIRQ(); unsigned state = disableIRQ();
sched_set_status((tcb_t *)sched_active_thread, STATUS_SLEEPING); sched_set_status((thread_t *)sched_active_thread, STATUS_SLEEPING);
restoreIRQ(state); restoreIRQ(state);
thread_yield_higher(); thread_yield_higher();
} }
@ -69,7 +69,7 @@ int thread_wakeup(kernel_pid_t pid)
unsigned old_state = disableIRQ(); unsigned old_state = disableIRQ();
tcb_t *other_thread = (tcb_t *) sched_threads[pid]; thread_t *other_thread = (thread_t *) sched_threads[pid];
if (other_thread && other_thread->status == STATUS_SLEEPING) { if (other_thread && other_thread->status == STATUS_SLEEPING) {
DEBUG("thread_wakeup: Thread is sleeping.\n"); DEBUG("thread_wakeup: Thread is sleeping.\n");
@ -91,7 +91,7 @@ int thread_wakeup(kernel_pid_t pid)
void thread_yield(void) void thread_yield(void)
{ {
unsigned old_state = disableIRQ(); unsigned old_state = disableIRQ();
tcb_t *me = (tcb_t *)sched_active_thread; thread_t *me = (thread_t *)sched_active_thread;
if (me->status >= STATUS_ON_RUNQUEUE) { if (me->status >= STATUS_ON_RUNQUEUE) {
clist_advance(&sched_runqueues[me->priority]); clist_advance(&sched_runqueues[me->priority]);
} }
@ -137,13 +137,13 @@ kernel_pid_t thread_create(char *stack, int stacksize, char priority, int flags,
} }
/* make room for the thread control block */ /* make room for the thread control block */
stacksize -= sizeof(tcb_t); stacksize -= sizeof(thread_t);
/* round down the stacksize to a multiple of tcb_t alignments (usually 16/32bit) */ /* round down the stacksize to a multiple of thread_t alignments (usually 16/32bit) */
stacksize -= stacksize % ALIGN_OF(tcb_t); stacksize -= stacksize % ALIGN_OF(thread_t);
/* allocate our thread control block at the top of our stackspace */ /* allocate our thread control block at the top of our stackspace */
tcb_t *cb = (tcb_t *) (stack + stacksize); thread_t *cb = (thread_t *) (stack + stacksize);
#if defined(DEVELHELP) || defined(SCHED_TEST_STACK) #if defined(DEVELHELP) || defined(SCHED_TEST_STACK)
if (flags & THREAD_CREATE_STACKTEST) { if (flags & THREAD_CREATE_STACKTEST) {

View File

@ -20,12 +20,12 @@
void thread_print_msg_queue(void) void thread_print_msg_queue(void)
{ {
volatile tcb_t *tcb = sched_active_thread; volatile thread_t *thread = sched_active_thread;
volatile cib_t *msg_queue = &tcb->msg_queue; volatile cib_t *msg_queue = &thread->msg_queue;
msg_t *msg_array = tcb->msg_array; msg_t *msg_array = thread->msg_array;
unsigned int i = msg_queue->read_count & msg_queue->mask; unsigned int i = msg_queue->read_count & msg_queue->mask;
printf("Message queue of thread %" PRIkernel_pid "\n", tcb->pid); printf("Message queue of thread %" PRIkernel_pid "\n", thread->pid);
printf(" size: %u (avail: %d)\n", msg_queue->mask + 1, printf(" size: %u (avail: %d)\n", msg_queue->mask + 1,
cib_avail((cib_t *)msg_queue)); cib_avail((cib_t *)msg_queue));

View File

@ -26,7 +26,7 @@
#include "board.h" #include "board.h"
#include "cpu.h" #include "cpu.h"
#include "thread.h" #include "sched.h"
#include "periph/timer.h" #include "periph/timer.h"
#include "periph_conf.h" #include "periph_conf.h"

View File

@ -38,7 +38,7 @@ static void __enter_thread_mode(void);
* @brief Since AVR doesn't support direct manipulation of the program counter we * @brief Since AVR doesn't support direct manipulation of the program counter we
* model a stack like it would be left by __context_save(). * model a stack like it would be left by __context_save().
* The resulting layout in memory is the following: * The resulting layout in memory is the following:
* ---------------tcb_t (not created by thread_arch_stack_init) ---------- * ---------------thread_t (not created by thread_arch_stack_init) ----------
* local variables (a temporary value and the stackpointer) * local variables (a temporary value and the stackpointer)
* ----------------------------------------------------------------------- * -----------------------------------------------------------------------
* a marker (AFFE) - for debugging purposes (helps finding the stack * a marker (AFFE) - for debugging purposes (helps finding the stack

View File

@ -19,7 +19,7 @@
*/ */
#include "cpu.h" #include "cpu.h"
#include "thread.h" #include "sched.h"
#include "periph/gpio.h" #include "periph/gpio.h"
/* Static IOCON registers definition */ /* Static IOCON registers definition */

View File

@ -40,7 +40,7 @@ void condition_variable::notify_one() noexcept {
priority_queue_node_t* head = priority_queue_remove_head(&m_queue); priority_queue_node_t* head = priority_queue_remove_head(&m_queue);
int other_prio = -1; int other_prio = -1;
if (head != NULL) { if (head != NULL) {
tcb_t* other_thread = (tcb_t*)sched_threads[head->data]; thread_t* other_thread = (thread_t*)sched_threads[head->data];
if (other_thread) { if (other_thread) {
other_prio = other_thread->priority; other_prio = other_thread->priority;
sched_set_status(other_thread, STATUS_PENDING); sched_set_status(other_thread, STATUS_PENDING);
@ -61,7 +61,7 @@ void condition_variable::notify_all() noexcept {
if (head == NULL) { if (head == NULL) {
break; break;
} }
tcb_t* other_thread = (tcb_t*)sched_threads[head->data]; thread_t* other_thread = (thread_t*)sched_threads[head->data];
if (other_thread) { if (other_thread) {
auto max_prio auto max_prio
= [](int a, int b) { return (a < 0) ? b : ((a < b) ? a : b); }; = [](int a, int b) { return (a < 0) ? b : ((a < b) ? a : b); };

View File

@ -52,13 +52,15 @@ extern "C" {
/** /**
* A generic pipe. * A generic pipe.
*/ */
typedef struct riot_pipe typedef struct riot_pipe {
{ ringbuffer_t *rb; /**< Wrapped ringbuffer. */
ringbuffer_t *rb; /**< Wrapped ringbuffer. */ thread_t *read_blocked; /**< A thread that wants to write to this
tcb_t *read_blocked; /**< A thread that wants to write to this full pipe. */ full pipe. */
tcb_t *write_blocked; /**< A thread that wants to read from this empty pipe. */ thread_t *write_blocked; /**< A thread that wants to read from this
void (*free)(void *); /**< Function to call by pipe_free(). Used like `pipe->free(pipe)`. */ empty pipe. */
} pipe_t; void (*free)(void *); /**< Function to call by pipe_free(). Used like
`pipe->free(pipe)`. */
} pipe_t;
/** /**
* @brief Initialize a pipe. * @brief Initialize a pipe.

View File

@ -34,8 +34,8 @@ typedef unsigned (*ringbuffer_op_t)(ringbuffer_t *restrict rb, char *buf, unsign
static ssize_t pipe_rw(ringbuffer_t *rb, static ssize_t pipe_rw(ringbuffer_t *rb,
void *buf, void *buf,
size_t n, size_t n,
tcb_t **other_op_blocked, thread_t **other_op_blocked,
tcb_t **this_op_blocked, thread_t **this_op_blocked,
ringbuffer_op_t ringbuffer_op) ringbuffer_op_t ringbuffer_op)
{ {
if (n == 0) { if (n == 0) {
@ -48,7 +48,7 @@ static ssize_t pipe_rw(ringbuffer_t *rb,
unsigned count = ringbuffer_op(rb, buf, n); unsigned count = ringbuffer_op(rb, buf, n);
if (count > 0) { if (count > 0) {
tcb_t *other_thread = *other_op_blocked; thread_t *other_thread = *other_op_blocked;
int other_prio = -1; int other_prio = -1;
if (other_thread) { if (other_thread) {
*other_op_blocked = NULL; *other_op_blocked = NULL;
@ -69,9 +69,9 @@ static ssize_t pipe_rw(ringbuffer_t *rb,
return 0; return 0;
} }
else { else {
*this_op_blocked = (tcb_t *) sched_active_thread; *this_op_blocked = (thread_t *) sched_active_thread;
sched_set_status((tcb_t *) sched_active_thread, STATUS_SLEEPING); sched_set_status((thread_t *) sched_active_thread, STATUS_SLEEPING);
restoreIRQ(old_state); restoreIRQ(old_state);
thread_yield_higher(); thread_yield_higher();
} }

View File

@ -18,7 +18,7 @@
#define __SYS__POSIX__PTHREAD_RWLOCK__H #define __SYS__POSIX__PTHREAD_RWLOCK__H
#include "priority_queue.h" #include "priority_queue.h"
#include "tcb.h" #include "thread.h"
#include <errno.h> #include <errno.h>
#include <stdbool.h> #include <stdbool.h>
@ -59,12 +59,11 @@ typedef struct pthread_rwlock
/** /**
* @brief Internal structure that stores one waiting thread. * @brief Internal structure that stores one waiting thread.
*/ */
typedef struct __pthread_rwlock_waiter_node typedef struct __pthread_rwlock_waiter_node {
{ bool is_writer; /**< `false`: reader; `true`: writer */
bool is_writer; /**< `false`: reader; `true`: writer */ thread_t *thread; /**< waiting thread */
tcb_t *thread; /**< waiting thread */ priority_queue_node_t qnode; /**< Node to store in `pthread_rwlock_t::queue`. */
priority_queue_node_t qnode; /**< Node to store in `pthread_rwlock_t::queue`. */ bool continue_; /**< This is not a spurious wakeup. */
bool continue_; /**< This is not a spurious wakeup. */
} __pthread_rwlock_waiter_node_t; } __pthread_rwlock_waiter_node_t;
/** /**

View File

@ -99,7 +99,7 @@ int pthread_barrier_wait(pthread_barrier_t *barrier)
++count; ++count;
next->cont = 1; next->cont = 1;
tcb_t *other = (tcb_t *) sched_threads[next->pid]; thread_t *other = (thread_t *) sched_threads[next->pid];
switch_prio = priority_min(switch_prio, other->priority); switch_prio = priority_min(switch_prio, other->priority);
sched_set_status(other, STATUS_PENDING); sched_set_status(other, STATUS_PENDING);
} }

View File

@ -142,7 +142,7 @@ int pthread_cond_signal(struct pthread_cond_t *cond)
priority_queue_node_t *head = priority_queue_remove_head(&(cond->queue)); priority_queue_node_t *head = priority_queue_remove_head(&(cond->queue));
int other_prio = -1; int other_prio = -1;
if (head != NULL) { if (head != NULL) {
tcb_t *other_thread = (tcb_t *) sched_threads[head->data]; thread_t *other_thread = (thread_t *) sched_threads[head->data];
if (other_thread) { if (other_thread) {
other_prio = other_thread->priority; other_prio = other_thread->priority;
sched_set_status(other_thread, STATUS_PENDING); sched_set_status(other_thread, STATUS_PENDING);
@ -176,7 +176,7 @@ int pthread_cond_broadcast(struct pthread_cond_t *cond)
break; break;
} }
tcb_t *other_thread = (tcb_t *) sched_threads[head->data]; thread_t *other_thread = (thread_t *) sched_threads[head->data];
if (other_thread) { if (other_thread) {
other_prio = max_prio(other_prio, other_thread->priority); other_prio = max_prio(other_prio, other_thread->priority);
sched_set_status(other_thread, STATUS_PENDING); sched_set_status(other_thread, STATUS_PENDING);

View File

@ -122,7 +122,7 @@ static int pthread_rwlock_lock(pthread_rwlock_t *rwlock,
/* queue for the lock */ /* queue for the lock */
__pthread_rwlock_waiter_node_t waiting_node = { __pthread_rwlock_waiter_node_t waiting_node = {
.is_writer = is_writer, .is_writer = is_writer,
.thread = (tcb_t *) sched_active_thread, .thread = (thread_t *) sched_active_thread,
.qnode = { .qnode = {
.next = NULL, .next = NULL,
.data = (uintptr_t) &waiting_node, .data = (uintptr_t) &waiting_node,

View File

@ -19,7 +19,7 @@
#include "thread.h" #include "thread.h"
#include "sched.h" #include "sched.h"
#include "tcb.h" #include "thread.h"
#include "kernel_types.h" #include "kernel_types.h"
#ifdef MODULE_SCHEDSTATISTICS #ifdef MODULE_SCHEDSTATISTICS
@ -66,7 +66,7 @@ void ps(void)
"state"); "state");
for (kernel_pid_t i = KERNEL_PID_FIRST; i <= KERNEL_PID_LAST; i++) { for (kernel_pid_t i = KERNEL_PID_FIRST; i <= KERNEL_PID_LAST; i++) {
tcb_t *p = (tcb_t *)sched_threads[i]; thread_t *p = (thread_t *)sched_threads[i];
if (p != NULL) { if (p != NULL) {
int state = p->status; /* copy state */ int state = p->status; /* copy state */

View File

@ -11,7 +11,7 @@
* @{ * @{
* *
* @file * @file
* @brief Print the size of tcb_t. * @brief Print the size of thread_t.
* *
* @author René Kijewski <rene.kijewski@fu-berlin.de> * @author René Kijewski <rene.kijewski@fu-berlin.de>
* *
@ -21,15 +21,15 @@
#include <stdio.h> #include <stdio.h>
#include <stddef.h> #include <stddef.h>
#include "tcb.h" #include "thread.h"
#define P(NAME) printf("\t%-*s%4zu%4zu\n", 11, #NAME, sizeof(((tcb_t *) 0)->NAME), offsetof(tcb_t, NAME)); #define P(NAME) printf("\t%-*s%4zu%4zu\n", 11, #NAME, sizeof(((thread_t *) 0)->NAME), offsetof(thread_t, NAME));
int main(void) int main(void)
{ {
puts("\tmember, sizeof, offsetof"); puts("\tmember, sizeof, offsetof");
printf("sizeof(tcb_t): %zu\n", sizeof(tcb_t)); printf("sizeof(thread_t): %zu\n", sizeof(thread_t));
P(sp); P(sp);
P(status); P(status);

View File

@ -33,7 +33,7 @@ static char receiver_stack[THREAD_STACKSIZE_DEFAULT];
typedef struct { typedef struct {
void (*run)(void); void (*run)(void);
tcb_t *main_thread; thread_t *main_thread;
mutex_t mutexes[2]; mutex_t mutexes[2];
} test_ubjson_receiver_data_t; } test_ubjson_receiver_data_t;
@ -80,7 +80,7 @@ void test_ubjson_test(void (*sender_fun)(void), void (*receiver_fun)(void))
{ {
test_ubjson_receiver_data_t data = { test_ubjson_receiver_data_t data = {
.run = receiver_fun, .run = receiver_fun,
.main_thread = (tcb_t *) sched_active_thread, .main_thread = (thread_t *) sched_active_thread,
.mutexes = { MUTEX_INIT, MUTEX_INIT }, .mutexes = { MUTEX_INIT, MUTEX_INIT },
}; };
mutex_lock(&data.mutexes[0]); mutex_lock(&data.mutexes[0]);