mthread
0.5.1
|
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. This function will cause a Thread to pause until its resume() function is called. This function will cancel any sleep timer currently in effect. | |
bool | resume () |
Resumes a paused or sleeping Thread. | |
bool | 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. | |
bool | 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. | |
bool | 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. | |
Protected Member Functions | |
virtual bool | loop () |
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. | |
Protected Attributes | |
bool | kill_flag |
Kill flag. This variable should be checked at the beginning of every loop() function. If it is true, the Thread has been requested to be killed, and the loop() function should behave accordingly. The request can be denied by resetting it to false. | |
Private Member Functions | |
bool | call () |
Determines if the function is active and runs through a loop if appropriate. This function is called automatically by a ThreadList. | |
Private Attributes | |
unsigned long | stop_time |
The time the thread was stopped at. | |
unsigned long | wait_time |
The amount of the the thread is to wait for. | |
Mode | mode |
The thread's running mode (can be read through the get_mode() function). | |
Friends | |
class | ThreadList |
void | loop (void) |
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 | ( | void | ) | [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 SwitchInput, EventHandler, and ThreadList.
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 the Thread is to sleep for. |
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 the Thread is to sleep for |
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 the Thread is to sleep for. |