Mantid
Loading...
Searching...
No Matches
Signals | Public Member Functions | Static Public Member Functions | Private Types | 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.
 
 FindFilesThreadPoolManager ()
 Create a new thread pool manager for finding files.
 
bool isSearchRunning () const
 Check if a search is already in progress.
 
void setAllocator (ThreadAllocator allocator)
 Set the worker object allocator for this thread pool.
 
void waitForDone ()
 Block execution and wait for all threads to finish processing.
 

Static Public Member Functions

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

Private Types

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

Private Member Functions

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

Private Attributes

ThreadAllocator m_workerAllocator
 Handle to the allocator function for creating new worker threads.
 

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 103 of file FindFilesThreadPoolManager.cpp.

References disconnectWorkers().

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 88 of file FindFilesThreadPoolManager.cpp.

References disconnectWorkers().

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_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 at least one worker thread is active

Definition at line 117 of file FindFilesThreadPoolManager.cpp.

References poolInstance().

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(), isSearchRunning(), and waitForDone().

◆ 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 125 of file FindFilesThreadPoolManager.cpp.

References poolInstance().

Member Data Documentation

◆ m_workerAllocator

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

Handle to the allocator function for creating new worker threads.

Definition at line 59 of file FindFilesThreadPoolManager.h.

Referenced by createWorker(), and setAllocator().


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