neic-glass3  1.4.6
Public Member Functions | List of all members
glass3::util::ThreadPool Class Reference

glass3::util::ThreadPool class More...

#include <threadpool.h>

Inheritance diagram for glass3::util::ThreadPool:
Inheritance graph
Collaboration diagram for glass3::util::ThreadPool:
Collaboration graph

Public Member Functions

 ThreadPool ()
 ThreadPool constructor. More...
 
 ThreadPool (std::string poolName, int numThreads=5, int sleepTime=100, int checkInterval=300)
 An advanced constructor that sets up the ThreadPool with a provided pool name, number of threads, sleep between jobs time and status check interval. More...
 
 ~ThreadPool ()
 ThreadPool destructor. More...
 
void addJob (std::function< void()> newJob)
 add a new job for for the thread pool to process More...
 
int getJobQueueSize ()
 Retrieve the current number of jobs in the queue. More...
 
glass3::util::WorkState work () override
 ThreadBaseClass work function. More...
 
- Public Member Functions inherited from glass3::util::ThreadBaseClass
 ThreadBaseClass ()
 ThreadBaseClass constructor. More...
 
 ThreadBaseClass (std::string threadName, int sleepTimeMS=100, int numThreads=1, int checkInterval=300)
 An advanced constructor that sets up the ThreadBaseClass with a provided thread name, sleep between work time duration, number of threads, and statsus check interval. More...
 
 ~ThreadBaseClass ()
 ThreadBaseClass destructor. More...
 
virtual bool start ()
 work thread start function More...
 
virtual bool stop ()
 work thread stop function More...
 
int getNumThreads ()
 Retrieves the number of work threads. More...
 
void setNumThreads (int numThreads)
 Sets the number of work threads. More...
 
void setThreadHealth (bool health=true)
 Function to set thread health. More...
 
virtual bool healthCheck ()
 work threads check function More...
 
void setSleepTime (int sleepTimeMS)
 Sets the time to sleep between work() calls. More...
 
int getSleepTime ()
 Retrieves the time to sleep between work() calls. More...
 
glass3::util::ThreadState getWorkThreadsState ()
 Function to get the work threads state. More...
 
void setHealthCheckInterval (int interval)
 Function to set work threads health check interval. More...
 
int getHealthCheckInterval ()
 Function to retrieve the work threads health check interval. More...
 
bool getTerminate ()
 Function to retrieve whether the thread should terminate. More...
 
const std::string & getThreadName ()
 Function to retrieve the name of the work threads. More...
 
std::time_t getAllLastHealthy (size_t *pThreadId)
 Function to retrieve the oldest time any of the work threads last updated their health status as healthy. More...
 
- Public Member Functions inherited from glass3::util::BaseClass
 BaseClass ()
 BaseClass constructor. More...
 
virtual ~BaseClass ()
 BaseClass destructor. More...
 
virtual bool setup (std::shared_ptr< const json::Object > config)
 BaseClass configuration function. More...
 
virtual void clear ()
 BaseClass clear function. More...
 
const std::shared_ptr< const json::Object > getConfig ()
 
bool getSetup ()
 Retrieves the class member boolean flag indicating whether the class has been setup, set to true if setup was successful. More...
 
const std::string & getDefaultAgencyId ()
 Function to retrieve the name of the default agency id. More...
 
void setDefaultAgencyId (const std::string &id)
 Function to set the name of the default agency id. More...
 
const std::string & getDefaultAuthor ()
 Function to retrieve the name of the default author. More...
 
void setDefaultAuthor (const std::string &author)
 Function to set the name of the default author. More...
 

Additional Inherited Members

- Protected Member Functions inherited from glass3::util::ThreadBaseClass
void setWorkThreadsState (glass3::util::ThreadState state)
 Function to set threads state. More...
 
void workLoop ()
 ThreadBaseClass work loop function. More...
 
void setLastHealthy (std::time_t now)
 Function to set the last time the work thread was healthy. More...
 
- Protected Attributes inherited from glass3::util::ThreadBaseClass
std::vector< std::thread > m_WorkThreads
 the std::vector that contains the work std::thread objects More...
 
std::map< std::thread::id, std::atomic< int > > m_ThreadHealthMap
 A std::map containing the epoch times as std::atomic<double>> that each work thread was last marked as healthy, identified by the thread id. More...
 
- Protected Attributes inherited from glass3::util::BaseClass
std::shared_ptr< const json::Object > m_Config
 A shared pointer to the json::Object that holds the configuration. More...
 
std::atomic< bool > m_bIsSetup
 the boolean flag indicating whether the class has been setup, set to true if setup was successful. More...
 
std::string m_DefaultAgencyID
 A std::string containing the default agency id to use in parsing if one is not provided. More...
 
std::string m_DefaultAuthor
 A std::string containing the default author to use in parsing if one is not provided. More...
 

Detailed Description

glass3::util::ThreadPool class

This class supports creating, starting, stopping, and monitoring a pool of threads that perform various jobs, managing a FIFO queue for jobs to be processed, and allowing for specific pool name and sleep between jobs.

This class inherits from util::threadbaseclass

Constructor & Destructor Documentation

glass3::util::ThreadPool::ThreadPool ( )

ThreadPool constructor.

The constructor for the ThreadPool class. Initializes members to default values.

glass3::util::ThreadPool::ThreadPool ( std::string  poolName,
int  numThreads = 5,
int  sleepTime = 100,
int  checkInterval = 300 
)
explicit

An advanced constructor that sets up the ThreadPool with a provided pool name, number of threads, sleep between jobs time and status check interval.

The advanced constructor for the ThreadPool class. Initializes members to provided values.

Parameters
poolName- A std::string containing the name of the thread pool
numThreads- An integer containing the number of threads in the pool. Default 5
sleepTime- An integer containing the amount of time to sleep in milliseconds between jobs. Default 100
checkInterval- An integer containing the amount of time in seconds between status checks. -1 to disable status checks. Default 300.
glass3::util::ThreadPool::~ThreadPool ( )

ThreadPool destructor.

The destructor for the ThreadPool class.

Member Function Documentation

void glass3::util::ThreadPool::addJob ( std::function< void()>  newJob)

add a new job for for the thread pool to process

Adds a job, as signified by a general-purpose polymorphic function wrapper bound to the function to run, to the queue of jobs to be run by the thread pool.

Parameters
newJob- A std::function<void()> bound to the function containing the job to run
int glass3::util::ThreadPool::getJobQueueSize ( )

Retrieve the current number of jobs in the queue.

Retrieves the number of pending (queued but not started) jobs stored in m_JobQueue

Returns
an integer containing the current number of jobs in the queue
glass3::util::WorkState glass3::util::ThreadPool::work ( )
overridevirtual

ThreadBaseClass work function.

This function is a pure virtual work function. It is intended that the derived class implement the desired thread work by overriding this function

Returns
This function returns glass3::util::WorkState, indicating whether the work was successful, encountered an error, or was idle (no work to perform

Implements glass3::util::ThreadBaseClass.


The documentation for this class was generated from the following files: