thread.h File Reference

Threading API. More...

Detailed Description

Threading API.

Author
Kaspar Schleiser kaspa.nosp@m.r@sc.nosp@m.hleis.nosp@m.er.d.nosp@m.e

Definition in file thread.h.

#include "clist.h"
#include "cib.h"
#include "msg.h"
#include "cpu_conf.h"
#include "sched.h"
+ Include dependency graph for thread.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _thread
 thread_t holds thread's context data. More...
 

Macros

#define THREAD_STACKSIZE_DEFAULT
 A reasonable default stack size that will suffice most smaller tasks. More...
 
#define THREAD_STACKSIZE_IDLE
 Size of the idle task's stack in bytes. More...
 
#define THREAD_EXTRA_STACKSIZE_PRINTF
 Size of the task's printf stack in bytes. More...
 
#define THREAD_STACKSIZE_MAIN   (THREAD_STACKSIZE_DEFAULT + THREAD_EXTRA_STACKSIZE_PRINTF)
 Size of the main task's stack in bytes.
 
#define THREAD_STACKSIZE_MINIMUM   (sizeof(thread_t))
 Minimum stack size.
 
#define THREAD_PRIORITY_MIN   (SCHED_PRIO_LEVELS-1)
 Least priority a thread can have.
 
#define THREAD_PRIORITY_IDLE   (THREAD_PRIORITY_MIN)
 Priority of the idle thread.
 
#define THREAD_PRIORITY_MAIN   (THREAD_PRIORITY_MIN - (SCHED_PRIO_LEVELS/2))
 Priority of the main thread.
 
Special meaning thread states
#define STATUS_NOT_FOUND   (-1)
 Describes an illegal thread status.
 
Blocked thread 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
 
#define STATUS_FLAG_BLOCKED_ANY   6
 waiting for any flag from flag_mask
 
#define STATUS_FLAG_BLOCKED_ALL   7
 waiting for all flags in flag_mask
 
#define STATUS_MBOX_BLOCKED   8
 waiting for get/put on mbox
 
Queued thread states
#define STATUS_ON_RUNQUEUE   STATUS_RUNNING
 to check if on run queue: st >= STATUS_ON_RUNQUEUE
 
#define STATUS_RUNNING   9
 currently running
 
#define STATUS_PENDING   10
 waiting to be scheduled to run
 
Optional flags for controlling a threads initial state
#define THREAD_CREATE_SLEEPING   (1)
 Set the new thread to sleeping. More...
 
#define THREAD_AUTO_FREE   (2)
 Currently not implemented.
 
#define THREAD_CREATE_WOUT_YIELD   (4)
 Do not automatically call thread_yield() after creation: the newly created thread might not run immediately. More...
 
#define THREAD_CREATE_STACKTEST   (8)
 Write markers into the thread's stack to measure stack usage (for debugging and profiling purposes)
 

Typedefs

typedef void *(* thread_task_func_t) (void *arg)
 Prototype for a thread entry function.
 

Functions

kernel_pid_t thread_create (char *stack, int stacksize, char priority, int flags, thread_task_func_t task_func, void *arg, const char *name)
 Creates a new thread. More...
 
volatile thread_tthread_get (kernel_pid_t pid)
 Retreive a thread control block by PID. More...
 
int thread_getstatus (kernel_pid_t pid)
 Returns the status of a process. More...
 
void thread_sleep (void)
 Puts the current thread into sleep mode. More...
 
void thread_yield (void)
 Lets current thread yield. More...
 
void thread_yield_higher (void)
 Lets current thread yield in favor of a higher prioritized thread. More...
 
int thread_wakeup (kernel_pid_t pid)
 Wakes up a sleeping thread. More...
 
static kernel_pid_t thread_getpid (void)
 Returns the process ID of the currently running thread. More...
 
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. More...
 
void thread_add_to_list (list_node_t *list, thread_t *thread)
 Add thread to list, sorted by priority (internal) More...
 
const char * thread_getname (kernel_pid_t pid)
 Returns the name of a process. More...
 
uintptr_t thread_measure_stack_free (char *stack)
 Measures the stack usage of a stack. More...
 
int thread_isr_stack_usage (void)
 Get the number of bytes used on the ISR stack.
 
void * thread_isr_stack_pointer (void)
 Get the current ISR stack pointer.
 
void * thread_isr_stack_start (void)
 Get the start of the ISR stack.
 
void thread_stack_print (void)
 Print the current stack to stdout.
 
void thread_print_stack (void)
 Prints human readable, ps-like thread information for debugging purposes.