SourceXtractorPlusPlus  0.11
Please provide a description of the project.
Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
SourceXtractor::MultithreadedMeasurement Class Reference

#include <MultithreadedMeasurement.h>

Inheritance diagram for SourceXtractor::MultithreadedMeasurement:
[legend]
Collaboration diagram for SourceXtractor::MultithreadedMeasurement:
[legend]

Public Types

using SourceToRowConverter = std::function< Euclid::Table::Row(const SourceInterface &)>
 

Public Member Functions

 MultithreadedMeasurement (SourceToRowConverter source_to_row, int worker_threads_nb)
 
void handleMessage (const std::shared_ptr< SourceGroupInterface > &source_group) override
 
void startThreads () override
 
void waitForThreads () override
 
- Public Member Functions inherited from SourceXtractor::Measurement
virtual ~Measurement ()=default
 
- Public Member Functions inherited from SourceXtractor::Observer< std::shared_ptr< SourceGroupInterface > >
virtual ~Observer ()=default
 
- Public Member Functions inherited from SourceXtractor::Observable< std::shared_ptr< SourceGroupInterface > >
virtual ~Observable ()=default
 Destructor. More...
 
virtual void addObserver (std::shared_ptr< Observer< std::shared_ptr< SourceGroupInterface > >> observer)
 Adds an Observer that will be notified when notify Observers is called. More...
 
virtual void removeObserver (std::shared_ptr< Observer< std::shared_ptr< SourceGroupInterface > >> observer)
 Removes a previously added Observer from the list of Observers to notify. More...
 

Static Public Attributes

static std::recursive_mutex g_global_mutex
 

Private Member Functions

void workerThreadLoop ()
 
void outputThreadLoop ()
 

Static Private Member Functions

static void workerThreadStatic (MultithreadedMeasurement *measurement, int id)
 
static void outputThreadStatic (MultithreadedMeasurement *measurement, int id)
 

Private Attributes

SourceToRowConverter m_source_to_row
 
std::shared_ptr< std::threadm_output_thread
 
int m_worker_threads_nb
 
std::vector< std::shared_ptr< std::thread > > m_worker_threads
 
int m_active_threads
 
std::mutex m_active_threads_mutex
 
int m_group_counter
 
std::atomic_bool m_input_done
 
std::atomic_bool m_abort_raised
 
std::condition_variable m_new_input
 
std::list< std::pair< int, std::shared_ptr< SourceGroupInterface > > > m_input_queue
 
std::mutex m_input_queue_mutex
 
std::condition_variable m_new_output
 
std::list< std::pair< int, std::shared_ptr< SourceGroupInterface > > > m_output_queue
 
std::mutex m_output_queue_mutex
 

Additional Inherited Members

- Protected Member Functions inherited from SourceXtractor::Observable< std::shared_ptr< SourceGroupInterface > >
void notifyObservers (const std::shared_ptr< SourceGroupInterface > &message) const
 

Detailed Description

Definition at line 37 of file MultithreadedMeasurement.h.

Member Typedef Documentation

◆ SourceToRowConverter

Definition at line 40 of file MultithreadedMeasurement.h.

Constructor & Destructor Documentation

◆ MultithreadedMeasurement()

SourceXtractor::MultithreadedMeasurement::MultithreadedMeasurement ( SourceToRowConverter  source_to_row,
int  worker_threads_nb 
)
inline

Definition at line 41 of file MultithreadedMeasurement.h.

Member Function Documentation

◆ handleMessage()

void MultithreadedMeasurement::handleMessage ( const std::shared_ptr< SourceGroupInterface > &  source_group)
overridevirtual

Implements SourceXtractor::Observer< std::shared_ptr< SourceGroupInterface > >.

Definition at line 69 of file MultithreadedMeasurement.cpp.

References m_group_counter, m_input_queue, m_input_queue_mutex, m_new_input, and std::condition_variable::notify_one().

Here is the call graph for this function:

◆ outputThreadLoop()

void MultithreadedMeasurement::outputThreadLoop ( )
private

Definition at line 159 of file MultithreadedMeasurement.cpp.

References m_active_threads, m_active_threads_mutex, m_new_output, m_output_queue, m_output_queue_mutex, SourceXtractor::Observable< std::shared_ptr< SourceGroupInterface > >::notifyObservers(), and std::condition_variable::wait_for().

Referenced by outputThreadStatic().

Here is the call graph for this function:

◆ outputThreadStatic()

void MultithreadedMeasurement::outputThreadStatic ( MultithreadedMeasurement measurement,
int  id 
)
staticprivate

Definition at line 100 of file MultithreadedMeasurement.cpp.

References Elements::Logging::debug(), e, Elements::Logging::fatal(), SourceXtractor::logger, m_abort_raised, and outputThreadLoop().

Referenced by startThreads().

Here is the call graph for this function:

◆ startThreads()

void MultithreadedMeasurement::startThreads ( )
overridevirtual

Implements SourceXtractor::Measurement.

Definition at line 39 of file MultithreadedMeasurement.cpp.

References std::vector< T >::emplace_back(), m_active_threads, m_output_thread, m_worker_threads, m_worker_threads_nb, outputThreadStatic(), and workerThreadStatic().

Here is the call graph for this function:

◆ waitForThreads()

void MultithreadedMeasurement::waitForThreads ( )
overridevirtual

Implements SourceXtractor::Measurement.

Definition at line 50 of file MultithreadedMeasurement.cpp.

References Elements::Logging::debug(), std::thread::join(), SourceXtractor::logger, m_input_done, m_input_queue_mutex, m_new_input, m_output_thread, m_worker_threads, m_worker_threads_nb, and std::condition_variable::notify_all().

Here is the call graph for this function:

◆ workerThreadLoop()

void MultithreadedMeasurement::workerThreadLoop ( )
private

Definition at line 116 of file MultithreadedMeasurement.cpp.

References m_active_threads, m_active_threads_mutex, m_input_done, m_input_queue, m_input_queue_mutex, m_new_input, m_new_output, m_output_queue, m_output_queue_mutex, m_source_to_row, std::condition_variable::notify_one(), and std::condition_variable::wait_for().

Referenced by workerThreadStatic().

Here is the call graph for this function:

◆ workerThreadStatic()

void MultithreadedMeasurement::workerThreadStatic ( MultithreadedMeasurement measurement,
int  id 
)
staticprivate

Definition at line 84 of file MultithreadedMeasurement.cpp.

References Elements::Logging::debug(), e, Elements::Logging::fatal(), SourceXtractor::logger, m_abort_raised, and workerThreadLoop().

Referenced by startThreads().

Here is the call graph for this function:

Member Data Documentation

◆ g_global_mutex

std::recursive_mutex MultithreadedMeasurement::g_global_mutex
static

◆ m_abort_raised

std::atomic_bool SourceXtractor::MultithreadedMeasurement::m_abort_raised
private

Definition at line 73 of file MultithreadedMeasurement.h.

Referenced by outputThreadStatic(), and workerThreadStatic().

◆ m_active_threads

int SourceXtractor::MultithreadedMeasurement::m_active_threads
private

Definition at line 69 of file MultithreadedMeasurement.h.

Referenced by outputThreadLoop(), startThreads(), and workerThreadLoop().

◆ m_active_threads_mutex

std::mutex SourceXtractor::MultithreadedMeasurement::m_active_threads_mutex
private

Definition at line 70 of file MultithreadedMeasurement.h.

Referenced by outputThreadLoop(), and workerThreadLoop().

◆ m_group_counter

int SourceXtractor::MultithreadedMeasurement::m_group_counter
private

Definition at line 72 of file MultithreadedMeasurement.h.

Referenced by handleMessage().

◆ m_input_done

std::atomic_bool SourceXtractor::MultithreadedMeasurement::m_input_done
private

Definition at line 73 of file MultithreadedMeasurement.h.

Referenced by waitForThreads(), and workerThreadLoop().

◆ m_input_queue

std::list<std::pair<int, std::shared_ptr<SourceGroupInterface> > > SourceXtractor::MultithreadedMeasurement::m_input_queue
private

Definition at line 75 of file MultithreadedMeasurement.h.

Referenced by handleMessage(), and workerThreadLoop().

◆ m_input_queue_mutex

std::mutex SourceXtractor::MultithreadedMeasurement::m_input_queue_mutex
private

Definition at line 76 of file MultithreadedMeasurement.h.

Referenced by handleMessage(), waitForThreads(), and workerThreadLoop().

◆ m_new_input

std::condition_variable SourceXtractor::MultithreadedMeasurement::m_new_input
private

Definition at line 74 of file MultithreadedMeasurement.h.

Referenced by handleMessage(), waitForThreads(), and workerThreadLoop().

◆ m_new_output

std::condition_variable SourceXtractor::MultithreadedMeasurement::m_new_output
private

Definition at line 78 of file MultithreadedMeasurement.h.

Referenced by outputThreadLoop(), and workerThreadLoop().

◆ m_output_queue

std::list<std::pair<int, std::shared_ptr<SourceGroupInterface> > > SourceXtractor::MultithreadedMeasurement::m_output_queue
private

Definition at line 79 of file MultithreadedMeasurement.h.

Referenced by outputThreadLoop(), and workerThreadLoop().

◆ m_output_queue_mutex

std::mutex SourceXtractor::MultithreadedMeasurement::m_output_queue_mutex
private

Definition at line 80 of file MultithreadedMeasurement.h.

Referenced by outputThreadLoop(), and workerThreadLoop().

◆ m_output_thread

std::shared_ptr<std::thread> SourceXtractor::MultithreadedMeasurement::m_output_thread
private

Definition at line 64 of file MultithreadedMeasurement.h.

Referenced by startThreads(), and waitForThreads().

◆ m_source_to_row

SourceToRowConverter SourceXtractor::MultithreadedMeasurement::m_source_to_row
private

Definition at line 62 of file MultithreadedMeasurement.h.

Referenced by workerThreadLoop().

◆ m_worker_threads

std::vector<std::shared_ptr<std::thread> > SourceXtractor::MultithreadedMeasurement::m_worker_threads
private

Definition at line 67 of file MultithreadedMeasurement.h.

Referenced by startThreads(), and waitForThreads().

◆ m_worker_threads_nb

int SourceXtractor::MultithreadedMeasurement::m_worker_threads_nb
private

Definition at line 66 of file MultithreadedMeasurement.h.

Referenced by startThreads(), and waitForThreads().


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