OSSIM - Open Source Software Image Map
Version 1.9.0 (20180803)
|
Thread is an abstract class. More...
#include <Thread.h>
Classes | |
class | Interrupt |
This is an Interrupt exception that is thrown if the. More... | |
Public Member Functions | |
Thread () | |
Constructor for this thread. More... | |
virtual | ~Thread () |
Destructor for this thread. More... | |
void | start () |
Will actually start the thread and will call the. More... | |
bool | isRunning () const |
bool | isInterruptable () const |
This is typically set if. More... | |
virtual void | cancel () |
This basically requests that the thread be canceled. More... | |
virtual void | setCancel (bool flag) |
virtual void | waitForCompletion () |
Convenience to allow one to wait for this thread to finish it's work. More... | |
void | pause () |
Enables the thread to be paused. More... | |
void | resume () |
This will resume a blocked thread. More... | |
bool | isPaused () const |
Static Public Member Functions | |
static void | sleepInSeconds (ossim_uint64 seconds) |
Utility method to allow one to sleep in seconds. More... | |
static void | sleepInMilliSeconds (ossim_uint64 millis) |
Utility method to allow one to sleep in milliseconds. More... | |
static void | sleepInMicroSeconds (ossim_uint64 micros) |
Utility method to allow one to sleep in microseconds. More... | |
static std::thread::id | getCurrentThreadId () |
Utility method to get the current thread ID. More... | |
static ossim_uint64 | getNumberOfProcessors () |
Utility to return the number of processors (concurrent threads) More... | |
static void | yieldCurrentThread () |
Will yield the current thread. More... | |
Protected Member Functions | |
virtual void | run ()=0 |
This method must be overriden and is the main entry point for any work that needs to be done. More... | |
virtual void | interrupt () |
This is the interrupt interface and will cause an internal exception that is caught by. More... | |
virtual void | runInternal () |
runInternal sets up internal flags such as setting m_running to true and checks to make sure it's not interrupted and will then call the More... | |
Private Member Functions | |
void | setInterruptable (bool flag) |
Private Attributes | |
std::shared_ptr< std::thread > | m_thread |
std::atomic< bool > | m_running |
std::atomic< bool > | m_interrupt |
std::shared_ptr< ossim::Barrier > | m_pauseBarrier |
std::condition_variable | m_runningCondition |
std::mutex | m_runningMutex |
Thread is an abstract class.
It provides a general purpose thread interface that handles preliminary setup of the std c++11 thread. It allows one to derive from Thread and override the run method. Your thread should have calls to interrupt() whenever your thread is in a location that is interruptable. If cancel is called then any thread that is interruptable will throw an Interrupt and be caught in the base Thread class and then exit the thread.
Example:
ossim::Thread::Thread | ( | ) |
Constructor for this thread.
Definition at line 3 of file Thread.cpp.
|
virtual |
Destructor for this thread.
It will determine if this thread is joinable to the main thread and if so it will do a join before continuing. If this is not done then an exeption is thrown by the std.
Definition at line 10 of file Thread.cpp.
|
inlinevirtual |
This basically requests that the thread be canceled.
we will make these virtual just in case derived classes want to set conditions
Reimplemented in ossimJobThreadQueue.
Definition at line 117 of file Thread.h.
|
static |
Utility method to get the current thread ID.
Definition at line 93 of file Thread.cpp.
|
static |
Utility to return the number of processors (concurrent threads)
Definition at line 88 of file Thread.cpp.
Referenced by ossim::getNumberOfThreads().
|
protectedvirtual |
This is the interrupt interface and will cause an internal exception that is caught by.
Definition at line 103 of file Thread.cpp.
Referenced by ossimJobThreadQueue::run().
|
inline |
bool ossim::Thread::isPaused | ( | ) | const |
Definition at line 68 of file Thread.cpp.
Referenced by ossimJobThreadQueue::setJobQueue().
|
inline |
Definition at line 100 of file Thread.h.
Referenced by ossimJobThreadQueue::cancel(), ossimJobThreadQueue::setJobQueue(), and ossimJobThreadQueue::startThreadForQueue().
void ossim::Thread::pause | ( | ) |
Enables the thread to be paused.
If the interrupt is called it will block the thread
Definition at line 58 of file Thread.cpp.
Referenced by ossimJobThreadQueue::setJobQueue().
void ossim::Thread::resume | ( | ) |
This will resume a blocked thread.
Definition at line 63 of file Thread.cpp.
Referenced by ossimJobThreadQueue::setJobQueue().
|
protectedpure virtual |
This method must be overriden and is the main entry point for any work that needs to be done.
Implemented in ossimJobThreadQueue.
|
protectedvirtual |
runInternal sets up internal flags such as setting m_running to true and checks to make sure it's not interrupted and will then call the
runInternal also will trap any Interrupt exceptions. If the thread is interruptable and the work calls interrupt then an exception is thrown and the work is stopped and the execution of the thread is marked as not running and returns.
Definition at line 117 of file Thread.cpp.
Referenced by start().
|
virtual |
flag | if true will enable the thread to be interruptable and if false the thread is not interruptable. |
Definition at line 37 of file Thread.cpp.
|
private |
Definition at line 112 of file Thread.cpp.
|
static |
Utility method to allow one to sleep in microseconds.
micros | to sleep |
Definition at line 83 of file Thread.cpp.
Referenced by ossimHlzTool::computeHLZ(), and ossimViewshedTool::computeViewshed().
|
static |
Utility method to allow one to sleep in milliseconds.
millis | to sleep |
Definition at line 78 of file Thread.cpp.
|
static |
Utility method to allow one to sleep in seconds.
seconds | to sleep |
Definition at line 73 of file Thread.cpp.
void ossim::Thread::start | ( | ) |
Will actually start the thread and will call the.
Definition at line 22 of file Thread.cpp.
References runInternal().
Referenced by ossimJobThreadQueue::startThreadForQueue().
|
virtual |
Convenience to allow one to wait for this thread to finish it's work.
Allow this to be overriden.
Definition at line 49 of file Thread.cpp.
|
static |
Will yield the current thread.
Definition at line 98 of file Thread.cpp.
Referenced by ossimJobThreadQueue::cancel(), and ossimJobThreadQueue::run().
|
private |
|
private |
|
private |