Mantid
Loading...
Searching...
No Matches
Signals | Public Member Functions | Static Public Member Functions | Private Types | Private Slots | Private Member Functions | Private Attributes | List of all members
MantidQt::API::FindFilesThreadPoolManager Class Reference

A small helper class to hold a handle to a static thread pool. More...

#include <FindFilesThreadPoolManager.h>

Inheritance diagram for MantidQt::API::FindFilesThreadPoolManager:

Signals

void disconnectWorkers ()
 

Public Member Functions

void createWorker (const QObject *parent, const FindFilesSearchParameters &parameters)
 Create a new worker thread. This will cancel any currently running threads. More...
 
 FindFilesThreadPoolManager ()
 Create a new thread pool manager for finding files. More...
 
bool isSearchRunning () const
 Check if a search is already in progress. More...
 
void setAllocator (ThreadAllocator allocator)
 Set the worker object allocator for this thread pool. More...
 
void waitForDone ()
 Block execution and wait for all threads to finish processing. More...
 

Static Public Member Functions

static void destroyThreadPool ()
 Destroy the static thread pool instance. More...
 

Private Types

using ThreadAllocator = std::function< FindFilesWorker *(const FindFilesSearchParameters &)>
 

Private Slots

void searchFinished ()
 Mark the search as being finished. More...
 

Private Member Functions

void cancelWorker ()
 Cancel the currently running worker. More...
 
void connectWorker (const QObject *parent, const FindFilesWorker *worker)
 Connect worker to relevant signals/slots. More...
 
const std::unique_ptr< QThreadPool > & poolInstance () const
 Get a handle to the static file finder thread pool instance. More...
 

Private Attributes

bool m_searchIsRunning
 Flag set if a search is currently running. More...
 
ThreadAllocator m_workerAllocator
 Handle to the allocator function for creating new worker threads. More...
 

Detailed Description

A small helper class to hold a handle to a static thread pool.

Definition at line 27 of file FindFilesThreadPoolManager.h.

Member Typedef Documentation

◆ ThreadAllocator

Definition at line 29 of file FindFilesThreadPoolManager.h.

Constructor & Destructor Documentation

◆ FindFilesThreadPoolManager()

FindFilesThreadPoolManager::FindFilesThreadPoolManager ( )

Create a new thread pool manager for finding files.

Definition at line 49 of file FindFilesThreadPoolManager.cpp.

Member Function Documentation

◆ cancelWorker()

void FindFilesThreadPoolManager::cancelWorker ( )
private

Cancel the currently running worker.

This will disconnect any signals from the worker and then let the internal QThreadPool clean up the worker at a later time.

Definition at line 107 of file FindFilesThreadPoolManager.cpp.

References disconnectWorkers(), and m_searchIsRunning.

Referenced by createWorker().

◆ connectWorker()

void FindFilesThreadPoolManager::connectWorker ( const QObject *  parent,
const FindFilesWorker worker 
)
private

Connect worker to relevant signals/slots.

Connect a new worker to the listening parent.

This will hook up signals/slots for:

  • Returning the result of the search
  • Indicating when the search is finished
  • When the search is cancelled
Parameters
parent:: the listening parent object waiting for search results
worker:: the worker to connect signals/slots for.

Definition at line 89 of file FindFilesThreadPoolManager.cpp.

References disconnectWorkers(), and searchFinished().

Referenced by createWorker().

◆ createWorker()

void FindFilesThreadPoolManager::createWorker ( const QObject *  parent,
const FindFilesSearchParameters parameters 
)

Create a new worker thread. This will cancel any currently running threads.

Definition at line 62 of file FindFilesThreadPoolManager.cpp.

References cancelWorker(), connectWorker(), m_searchIsRunning, m_workerAllocator, and poolInstance().

Referenced by MantidQt::API::FileFinderWidget::runFindFiles().

◆ destroyThreadPool()

void MantidQt::API::FindFilesThreadPoolManager::destroyThreadPool ( )
static

Destroy the static thread pool instance.

Destroy the static thread pool managed by this class.

This should be used to destroy the static thread pool at the end of the application's lifetime.

Definition at line 44 of file FindFilesThreadPoolManager.cpp.

References tp.

◆ disconnectWorkers

void MantidQt::API::FindFilesThreadPoolManager::disconnectWorkers ( )
signal

Referenced by cancelWorker(), and connectWorker().

◆ isSearchRunning()

bool FindFilesThreadPoolManager::isSearchRunning ( ) const

Check if a search is already in progress.

Check if a search is currently executing.

Returns
true if the current worker object is null

Definition at line 122 of file FindFilesThreadPoolManager.cpp.

References m_searchIsRunning.

Referenced by MantidQt::API::FileFinderWidget::isSearching().

◆ poolInstance()

const std::unique_ptr< QThreadPool > & FindFilesThreadPoolManager::poolInstance ( ) const
private

Get a handle to the static file finder thread pool instance.

Get a handle to the static thread pool managed by this class.

Returns
a unique pointer to the QThreadPool

Definition at line 33 of file FindFilesThreadPoolManager.cpp.

References tp.

Referenced by createWorker(), and waitForDone().

◆ searchFinished

void FindFilesThreadPoolManager::searchFinished ( )
privateslot

Mark the search as being finished.

Definition at line 134 of file FindFilesThreadPoolManager.cpp.

References m_searchIsRunning.

Referenced by connectWorker().

◆ setAllocator()

void FindFilesThreadPoolManager::setAllocator ( ThreadAllocator  allocator)

Set the worker object allocator for this thread pool.

Set the allocator function for the thread pool.

This is currently used for unit testing so that a fake QRunnable object can be used in place of a real worker.

Parameters
allocator:: The thread allocator function to user to create new worker objects

Definition at line 60 of file FindFilesThreadPoolManager.cpp.

References m_workerAllocator.

◆ waitForDone()

void FindFilesThreadPoolManager::waitForDone ( )

Block execution and wait for all threads to finish processing.

Wait for all threads in the pool to finish running.

Warning: This call will block execution until ALL threads in the pool have finished executing. Using this in a GUI thread will cause the GUI to freeze up.

Definition at line 130 of file FindFilesThreadPoolManager.cpp.

References poolInstance().

Member Data Documentation

◆ m_searchIsRunning

bool MantidQt::API::FindFilesThreadPoolManager::m_searchIsRunning
private

Flag set if a search is currently running.

Definition at line 65 of file FindFilesThreadPoolManager.h.

Referenced by cancelWorker(), createWorker(), isSearchRunning(), and searchFinished().

◆ m_workerAllocator

ThreadAllocator MantidQt::API::FindFilesThreadPoolManager::m_workerAllocator
private

Handle to the allocator function for creating new worker threads.

Definition at line 63 of file FindFilesThreadPoolManager.h.

Referenced by createWorker(), and setAllocator().


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