#include <kernel.h>
Public Member Functions | |
short int | get_priority () |
void | set_priority (short int pr) |
void | terminate () |
void | wakeup () |
short int | IRQget_priority () |
void | IRQwakeup () |
Static Public Member Functions | |
static Thread * | create (void(*startfunc)(void *), unsigned int stacksize, short int priority=1, void *argv=NULL) |
static void | yield () |
static void | do_terminate () |
static bool | test_terminate () |
static void | sleep (unsigned int ms) |
static Thread * | get_current_thread () |
static bool | exists (Thread *p) |
static void | wait () |
static Thread * | IRQget_current_thread () |
static void | IRQwait () |
static const int * | get_stack_bottom () |
Friends | |
void | IRQfind_next_thread () |
Thread * miosix::Thread::create | ( | void(*)(void *) | startfunc, | |
unsigned int | stacksize, | |||
short int | priority = 1 , |
|||
void * | argv = NULL | |||
) | [static] |
Producer method, creates a new thread.
startfunc | the entry point function for the thread | |
stacksize | size of thread stack, its minimum is the constant STACK_MIN. The size of the stack must be divisible by 4, otherwise it will be rounded to a number divisible by 4. | |
priority | the thread's priority, between 0 (lower) and PRIORITY_MAX-1 (higher) | |
argv | a void* pointer that is passed as pararmeter to the entry point function |
void miosix::Thread::yield | ( | ) | [static] |
When called, suggests the kernel to pause the current thread, and run another one.
CANNOT be called when the kernel is paused.
void miosix::Thread::do_terminate | ( | ) | [static] |
void threadfunc(void *argv) { string s="Hello world"; Thread::do_terminate(); }
bool miosix::Thread::test_terminate | ( | ) | [static] |
This method needs to be called periodically inside the thread's main loop.
void miosix::Thread::sleep | ( | unsigned int | ms | ) | [static] |
Put the thread to sleep for a number of milliseconds.
The actual precision depends on the kernel tick used. If the specified wait time is lower than the tick accuracy, the thread will be put to sleep for one tick.
Maximum sleep time is (2^32-1) / TICK_FREQ. If a sleep time higher than that value is specified, the behaviour is undefined.
ms | the number of millisecond. If it is ==0 this method will return immediately |
Thread * miosix::Thread::get_current_thread | ( | ) | [static] |
Return a pointer to the Thread class of the current thread.
bool miosix::Thread::exists | ( | Thread * | p | ) | [static] |
Check if a thread exists
p | thread to check |
short int miosix::Thread::get_priority | ( | ) |
Returns the priority of a thread.
To get the priority of the current thread use:
Thread::get_current_thread()->get_priority();
void miosix::Thread::set_priority | ( | short int | pr | ) |
Set the priority of a thread.
To set the priority of the current thread use:
Thread::get_current_thread()->set_priority(pr);
pr | desired priority. Must be 0<=pr<PRIORITY_MAX |
Calls error_handler(INVALID_PARAMETERS) if pr is not within bounds.
Can be called when the kernel is paused.
void miosix::Thread::terminate | ( | ) |
Suggests a thread to terminate itself. Note that this method only makes test_terminate() return true on the specified thread. If the thread does not call test_terminate(), or if it calls it but does not delete itself by returning from entry point function, it will NEVER terminate. The user is responsible for implementing correctly this functionality.
Thread termination is implemented like this to give time to a thread to deallocate resources, close files... before terminating.
Can be called when the kernel is paused.
void miosix::Thread::wait | ( | ) | [static] |
void miosix::Thread::wakeup | ( | ) |
Wakeup a thread.
Can be called when the kernel is paused.
Thread * miosix::Thread::IRQget_current_thread | ( | ) | [static] |
Same as get_current_thread(), but meant to be used insida an IRQ, when interrupts are disabled or when the kernel is paused.
short int miosix::Thread::IRQget_priority | ( | ) |
Same as get_priority(), but meant to be used inside an IRQ, when interrupts are disabled or when the kernel is paused.
void miosix::Thread::IRQwait | ( | ) | [static] |
Same as wait(), but is meant to be used only inside an IRQ or when interrupts are disabled.
Note: this method is meant to put the current thread in wait status in a piece of code where interrupts are disbled; it returns immediately, so the user is responsible for re-enabling interrupts and calling yield to effectively put the thread in wait status.
miosix_private::disable_interrupts(); ... Thread::IRQwait();//Return immediately miosix_private::enable_interrupts(); miosix::Thread::yield();//After this, thread is in wait status
void miosix::Thread::IRQwakeup | ( | ) |
Same as wakeup(), but is meant to be used only inside an IRQ or when interrupts are disabled.
const int * miosix::Thread::get_stack_bottom | ( | ) | [static] |
This is the lowest level method of the Thread class. It is only meant to implement functions to check the available stack in a thread.
Any other use is discouraged, since this method may change in future versions.
Returned pointer is constant because modifying the stack through it must be avoided.
void IRQfind_next_thread | ( | ) | [friend] |
This function is used to developed interrupt driven peripheral drivers.
Can be used ONLY inside an IRQ (and not when interrupts are disabled) to find next thread in READY status. If the kernel is paused, does nothing. Can be used for example if an IRQ causes a higher priority thread to be woken, to change context. Note that to use this function the IRQ must use the macros to save/restore context defined in portability.h