|
PiImageStreamer
|
#include <RunnableClass.h>

Public Member Functions | |
| RunnableClass (std::string threadName, int priority=0) | |
| virtual | ~RunnableClass () |
| virtual void | resetThreadDiagnostics () |
| virtual void | printInformation () |
| virtual double | getCPUUsageInfo () |
| virtual pid_t | getThreadID () |
| virtual void | start () final |
| virtual void | setPriority (int priority) final |
| virtual int | getPriority () final |
| virtual void | run ()=0 |
| virtual bool | isShutdown () final |
| virtual bool | isStarted () final |
| virtual void | stopThreadExecution () |
| virtual void | waitForShutdown () |
Static Public Member Functions | |
| static void | printThreads () |
| static void | resetAllThreadInformation () |
Protected Member Functions | |
| virtual void | startChildRunnables () |
| virtual void | stopChildRunnables () |
Protected Attributes | |
| std::thread * | myThread = NULL |
| pthread_t | executingThread = 0 |
| pid_t | myOSThreadID = 0 |
| std::string | myName |
| std::atomic< bool > | keepGoing {true} |
| std::atomic< bool > | runCompleted {false} |
| std::atomic< bool > | runStarted {false} |
| int | priority = -1 |
Static Protected Attributes | |
| static std::list< RunnableClass * > | runningThreads |
Private Member Functions | |
| virtual void | invokeRunMethod () final |
This is the runnable class, which mimics the runnable interface from Java. It is a virtual class which should not directly be instantiated.
| RunnableClass::RunnableClass | ( | std::string | threadName, |
| int | priority = 0 |
||
| ) |
This is the default constructor for the class.
| threadName | This is the name of the thread in a human readable format. |
| priority | This is the priority for the task. By default, will be 0 unless another priority is passed into the constructor. |
This is the default constructor for the class. The thread name is padded or truncated to 23 characters so that the diagnostic table lines up, and the instance is added to the list of threads.
| threadName | This is the name of the thread in a human readable format. |
| priority | This is the priority for the task. |
|
virtual |
This is the default destructor for the class. It deletes the thread object. The thread must have been joined (waitForShutdown()) or detached before the object is destroyed.
If the thread is not NULL, delete it.
|
virtual |
This method will return the CPU usage for the given task. The usage will be as a percentage value.
This method will return the CPU usage for the given task. The usage will be as a percentage value.
Note that for a simple runnable class, we do not currently have this metric.
Reimplemented in SWE4211RPi::FreeRunningRepeatingTask, and SWE4211RPi::PeriodicTask.

|
finalvirtual |
This method will obtain the priority set for this runnable class.

|
virtual |
This method will obtain the thread ID for this runnable.
|
finalprivatevirtual |
This private method initializes the runnable class. It is actually the method invoked when the thread starts. It applies the priority, records the thread IDs, and then calls the run method.
This private method initializes the runnable class. It is actually the method invoked when the thread starts. If a priority greater than 0 has been set, the thread is switched to the real time scheduler at that priority. The thread IDs are recorded, and then the run method is called.


|
finalvirtual |
This method will determine if the given thread is shutdown.
|
finalvirtual |
This method will determine if the given runnable class has been started or not.
|
virtual |
This method will print out information about the given thread. The info will be dependent upon the given thread.
Reimplemented in SWE4211RPi::FreeRunningRepeatingTask, and SWE4211RPi::PeriodicTask.


|
static |
This method will print out to the console each of the registered threads, their thread ID's, and their diagnostics.

|
static |
This method will reset the thread information which is dynamic in nature and changes as the robot runs. This predominantly impacts threads which are not part of the Runnable class.

|
virtual |
This method will reset thread diagnostics back to their default values.
Reimplemented in SWE4211RPi::FreeRunningRepeatingTask, and SWE4211RPi::PeriodicTask.

|
pure virtual |
This is the virtual run method. It will execute the given code that is to be executed by this class.
Implemented in SWE4211RPi::NetworkManager, SWE4211RPi::NetworkTransmissionManager, StatusDisplay, SWE4211RPi::FreeRunningRepeatingTask, SWE4211RPi::GenericThreadInfo, and SWE4211RPi::PeriodicTask.

|
finalvirtual |
This method will set the priority for the given task, using the real time FIFO scheduler as well as setting the priority. If the thread has already started, the scheduler is also changed immediately.
| priority | This is the priority for the task. It must be between 0 and 99, with 99 being the highest priority. Values above the scheduler maximum are clamped to the maximum. |
This method will set the priority for the given task. If the thread has already started, the scheduler is also changed immediately. Note that sched_setscheduler(0, ...) applies to the calling thread, so the change at run time is only applied to this runnable when setPriority() is called from its own thread.
| priority | This is the priority for the task. It must be between 0 and 99, with 99 being the highest priority. Values above the scheduler maximum are clamped to the maximum. |

|
finalvirtual |
This method is the start method. It is final and is not overridden in child classes. The purpose of this method is to start any child runnables and then instantiate a new thread that invokes the run method. The thread runs at the priority set with setPriority() (or passed to the constructor).
This method is the start method. The purpose of this method is to start any child runnables and then instantiate a new thread that invokes the run method. It does nothing if the run method has already started.


|
protectedvirtual |
This method will start up any runnable objects which are contained within a class that implements the Runnable interface. If there are no other objects that are runnable, there is no need to override this method. However, if a child class contains an instance of a runnable object, then this method must be overridden in the derived class.
This default implementation does nothing.
Reimplemented in SWE4211RPi::FreeRunningRepeatingTask, and SWE4211RPi::PeriodicTask.

|
protectedvirtual |
This method will stop any runnable objects which are contained within a class that implements the Runnable interface. If there are no other objects that are runnable, there is no need to override this method. However, if a child class contains an instance of a runnable object, then this method must be overridden in the derived class.
This default implementation does nothing.
Reimplemented in SWE4211RPi::FreeRunningRepeatingTask, and SWE4211RPi::PeriodicTask.

|
virtual |
This method will stop the execution of the given class. It sets keepGoing to false and stops any child runnables. It does not wait for the thread to finish; use waitForShutdown() for that.
This method will stop the execution of the given class.
Stop the thread by changing the value of keepGoing if the thread is running. If there is a child class that has a Runnable object inside of it, then stop is called on that object through stopChildRunnables(). The check and the change are done in one atomic exchange so that if two threads (for example, main and this thread handling a shutdown broadcast) call this method at the same time, only one of them stops the child runnables.
Reimplemented in SWE4211RPi::PulsedGPIOPin, SWE4211RPi::NetworkManager, and SWE4211RPi::NetworkTransmissionManager.


|
virtual |
This method will block waiting for the given thread to terminate before continuing. This should be overridden if any child class has it's own runnable objects encapsulated within it.
This method will block waiting for the given thread to terminate before continuing. If a class that is derived from this class has a child class with a Runnable object, this method must be overridden to wait for the child method to shutdown.
If thread is joinable
Join the thread and wait for shutdown.
|
protected |
This attribute is the executing thread. It is set when the thread is started and then is cached afterwards.
|
protected |
This variable will determine whether or not the given thread is to continue executing. If this goes to false, then the thread is to shutdown in an appropriate manner. It is atomic because it is written by other threads (for example, main calling stopThreadExecution()) while this thread reads it.
|
protected |
This is the name of the thread. It is shown as a string so that it can easily be viewed in human-readable format.
|
protected |
This is the thread id (tid) for this task.
|
protected |
This is the instance of the thread that is to be executed by this class. At instantiation it is NULL. It will be instantiated when the start method of the class is invoked.
|
protected |
This is the priority of the given thread. A value of 0 or less indicates no change in the priority and to use the default (non real time) scheduler. For a runnable class, this must be set before the class starts. For other derived classes, it may be changeable at run time.
|
protected |
This variable will determine if the current Runnable class has completed execution and the run method has returned. It is atomic because it is written by this thread and read by other threads.
|
staticprotected |
This is a list of all of the running threads which have been started by this set of libraries.
This is a class scoped variable which holds a list of every runnable that has been constructed. Entries are added by the constructor and are not removed.
|
protected |
This variable will determine whether or not the current task has been started or not. It is atomic because it is written by this thread and read by other threads.