mthread 0.5
|
Provides thread functionality. More...
#include <mthread.h>
Public Types | |
enum | Mode { run_mode, pause_mode, sleep_mode, sleep_milli_mode, sleep_micro_mode, kill_mode } |
Various running modes for a Thread. More... | |
Public Member Functions | |
Thread () | |
Constructor. | |
virtual | ~Thread () |
Destructor. | |
Mode | get_mode () const |
Returns the running mode for the Thread. | |
bool | kill (bool force=false) |
Kills a Thread. | |
bool | pause () |
Pauses a Thread. | |
bool | resume () |
Resumes a paused or sleeping Thread. | |
bool | sleep (unsigned long t) |
Puts the Thread to sleep for a certain number of seconds. | |
bool | sleep_micro (unsigned long t) |
Puts the Thread to sleep for a certain number of microseconds. | |
bool | sleep_milli (unsigned long t) |
Puts the Thread to sleep for a certain number of milliseconds. | |
Protected Member Functions | |
virtual bool | loop () |
The Thread's main loop. | |
Protected Attributes | |
bool | kill_flag |
Kill flag. | |
Private Member Functions | |
bool | call () |
Determines if the function is active and runs through a loop if appropriate. | |
Private Attributes | |
unsigned long | stop_time |
The time at which the thread was stopped. | |
unsigned long | wait_time |
The amount of time for which the thread is to wait. | |
Mode | mode |
The Thread's running mode (can be read externally through the get_mode() function). | |
Friends | |
class | ThreadList |
void | loop () |
Provides thread functionality.
enum Thread::Mode |
Various running modes for a Thread.
bool Thread::call | ( | ) | [private] |
Determines if the function is active and runs through a loop if appropriate.
This function is called automatically by a ThreadList.
Thread::Mode Thread::get_mode | ( | ) | const |
Returns the running mode for the Thread.
bool Thread::kill | ( | bool | force = false | ) |
Kills a Thread.
force | If true, the Thread will be killed immediately on the next call without running any more loops, if false, the Thread will have to opportunity to terminate cleanly but will be resumed if sleeping or paused. |
bool Thread::loop | ( | ) | [protected, virtual] |
The Thread's main loop.
This function is to be overridden. It takes the place of the loop function found in most Arduino programs. A single loop() should run as quickly as possible, as it will hold up other Thread objects while it is executing.
Reimplemented in ThreadList, EventHandler, and SwitchInput.
bool Thread::pause | ( | ) |
bool Thread::resume | ( | ) |
Resumes a paused or sleeping Thread.
bool Thread::sleep | ( | unsigned long | t | ) |
Puts the Thread to sleep for a certain number of seconds.
If already running, the thread's loop() function will be allowed to finish, but will not be called again until the timeout has expired or the resume() or kill() function has been called.
t | The number of seconds for which the Thread is to sleep. |
bool Thread::sleep_micro | ( | unsigned long | t | ) |
Puts the Thread to sleep for a certain number of microseconds.
If already running, the thread's loop() function will be allowed to finish, but will not be called again until the timeout has expired or the resume() or kill() function has been called.
t | The number of microseconds for which the Thread is to sleep. |
bool Thread::sleep_milli | ( | unsigned long | t | ) |
Puts the Thread to sleep for a certain number of milliseconds.
If already running, the thread's loop() function will be allowed to finish, but will not be called again until the timeout has expired or the resume() or kill() function has been called.
t | The number of milliseconds for which the Thread is to sleep. |
bool Thread::kill_flag [protected] |