Go to the documentation of this file.
125 #include "cpu_conf.h"
128 #ifdef MODULE_CORE_THREAD_FLAGS
136 #if defined(DEVELHELP) && !defined(CONFIG_THREAD_NAMES)
143 #define CONFIG_THREAD_NAMES
149 typedef void *(*thread_task_func_t)(
void *arg);
161 #if defined(MODULE_CORE_THREAD_FLAGS) || defined(DOXYGEN)
167 #if defined(MODULE_CORE_MSG) || defined(MODULE_CORE_THREAD_FLAGS) \
168 || defined(MODULE_CORE_MBOX) || defined(DOXYGEN)
172 #if defined(MODULE_CORE_MSG) || defined(DOXYGEN)
181 #if defined(DEVELHELP) || defined(SCHED_TEST_STACK) \
182 || defined(MODULE_MPU_STACK_GUARD) || defined(DOXYGEN)
185 #if defined(CONFIG_THREAD_NAMES) || defined(DOXYGEN)
188 #if defined(DEVELHELP) || defined(DOXYGEN)
195 #ifdef HAVE_THREAD_ARCH_T
207 #ifndef THREAD_STACKSIZE_DEFAULT
208 #error THREAD_STACKSIZE_DEFAULT must be defined per CPU
211 #define THREAD_STACKSIZE_DEFAULT
221 #ifndef THREAD_STACKSIZE_IDLE
222 #error THREAD_STACKSIZE_IDLE must be defined per CPU
225 #define THREAD_STACKSIZE_IDLE
235 #ifndef THREAD_EXTRA_STACKSIZE_PRINTF
236 #error THREAD_EXTRA_STACKSIZE_PRINTF must be defined per CPU
239 #define THREAD_EXTRA_STACKSIZE_PRINTF
246 #ifndef THREAD_STACKSIZE_MAIN
247 #define THREAD_STACKSIZE_MAIN (THREAD_STACKSIZE_DEFAULT + \
248 THREAD_EXTRA_STACKSIZE_PRINTF)
254 #ifndef THREAD_STACKSIZE_LARGE
255 #define THREAD_STACKSIZE_LARGE (THREAD_STACKSIZE_MEDIUM * 2)
261 #ifndef THREAD_STACKSIZE_MEDIUM
262 #define THREAD_STACKSIZE_MEDIUM THREAD_STACKSIZE_DEFAULT
268 #ifndef THREAD_STACKSIZE_SMALL
269 #define THREAD_STACKSIZE_SMALL (THREAD_STACKSIZE_MEDIUM / 2)
275 #ifndef THREAD_STACKSIZE_TINY
276 #define THREAD_STACKSIZE_TINY (THREAD_STACKSIZE_MEDIUM / 4)
282 #ifndef THREAD_STACKSIZE_MINIMUM
283 #define THREAD_STACKSIZE_MINIMUM (sizeof(thread_t))
290 #define THREAD_PRIORITY_MIN (SCHED_PRIO_LEVELS - 1)
296 #define THREAD_PRIORITY_IDLE (THREAD_PRIORITY_MIN)
302 #ifndef THREAD_PRIORITY_MAIN
303 #define THREAD_PRIORITY_MAIN (THREAD_PRIORITY_MIN - \
304 (SCHED_PRIO_LEVELS / 2))
314 #define THREAD_CREATE_SLEEPING (1)
319 #define THREAD_AUTO_FREE (2)
327 #define THREAD_CREATE_WOUT_YIELD (4)
333 #define THREAD_CREATE_STACKTEST (8)
476 return sched_active_pid;
488 extern volatile thread_t *sched_active_thread;
490 return (
thread_t *)sched_active_thread;
504 void *stack_start,
int stack_size);
583 #if defined(MODULE_CORE_MSG) || defined(DOXYGEN)
char * thread_stack_init(thread_task_func_t task_func, void *arg, void *stack_start, int stack_size)
Gets called upon thread creation to set CPU registers.
int16_t kernel_pid_t
Unique process identifier.
void * wait_data
used by msg, mbox and thread flags
int thread_wakeup(kernel_pid_t pid)
Wakes up a sleeping thread.
void * thread_isr_stack_pointer(void)
Get the current ISR stack pointer.
kernel_pid_t thread_create(char *stack, int stacksize, uint8_t priority, int flags, thread_task_func_t task_func, void *arg, const char *name)
Creates a new thread.
static int pid_is_valid(kernel_pid_t pid)
Determine if the given pid is valid.
static thread_t * thread_get_unchecked(kernel_pid_t pid)
Retrieve a thread control block by PID.
void thread_yield_higher(void)
Lets current thread yield in favor of a higher prioritized thread.
Messaging API for inter process communication.
void thread_sleep(void)
Puts the current thread into sleep mode.
Scheduler API definition.
char * sp
thread's stack pointer
void thread_add_to_list(list_node_t *list, thread_t *thread)
Add thread to list, sorted by priority (internal)
void thread_stack_print(void)
Print the current stack to stdout.
static kernel_pid_t thread_getpid(void)
Returns the process ID of the currently running thread.
void * thread_isr_stack_start(void)
Get the start of the ISR stack.
cib_t msg_queue
index of this [thread's message queue] (thread_t::msg_array), if any
char * stack_start
thread's stack start address
static thread_t * thread_get_active(void)
Returns a pointer to the Thread Control Block of the currently running thread.
static thread_t * thread_get(kernel_pid_t pid)
Retrieve a thread control block by PID.
void thread_yield(void)
Lets current thread yield.
void *(* thread_task_func_t)(void *arg)
Prototype for a thread entry function.
uintptr_t thread_measure_stack_free(const char *stack)
Measures the stack usage of a stack.
thread_t holds thread's context data.
uint8_t priority
thread's priority
uint16_t thread_flags_t
Type definition of thread_flags_t.
circular integer buffer structure
int thread_isr_stack_usage(void)
Get the number of bytes used on the ISR stack.
thread_flags_t flags
currently set flags
static int thread_has_msg_queue(const volatile struct _thread *thread)
Checks if a thread has an initialized message queue.
Circular integer buffer interface.
list_node_t msg_waiters
threads waiting for their message to be delivered to this thread (i.e.
void thread_print_stack(void)
Prints human readable, ps-like thread information for debugging purposes.
thread_status_t thread_getstatus(kernel_pid_t pid)
Returns the status of a process.
const char * thread_getname(kernel_pid_t pid)
Returns the name of a process.
int stack_size
thread's stack size
volatile thread_t * sched_threads[KERNEL_PID_LAST+1]
Thread table.
Describes a message object which can be sent between threads.
const char * name
thread's name
int thread_kill_zombie(kernel_pid_t pid)
Terminates zombie thread.
void thread_zombify(void)
Puts the current thread into zombie state.
kernel_pid_t pid
thread's process id
clist_node_t rq_entry
run queue entry
thread_status_t status
thread's status
msg_t * msg_array
memory holding messages sent to this thread's message queue