Mantid
|
A small helper class to hold a handle to a static thread pool. More...
#include <FindFilesThreadPoolManager.h>
Signals | |
void | disconnectWorkers () |
Public Member Functions | |
void | createWorker (const QObject *parent, const FindFilesSearchParameters ¶meters) |
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... | |
A small helper class to hold a handle to a static thread pool.
Definition at line 27 of file FindFilesThreadPoolManager.h.
|
private |
Definition at line 29 of file FindFilesThreadPoolManager.h.
FindFilesThreadPoolManager::FindFilesThreadPoolManager | ( | ) |
Create a new thread pool manager for finding files.
Definition at line 49 of file FindFilesThreadPoolManager.cpp.
|
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().
|
private |
Connect worker to relevant signals/slots.
Connect a new worker to the listening parent.
This will hook up signals/slots for:
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().
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().
|
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.
|
signal |
Referenced by cancelWorker(), and connectWorker().
bool FindFilesThreadPoolManager::isSearchRunning | ( | ) | const |
Check if a search is already in progress.
Check if a search is currently executing.
Definition at line 122 of file FindFilesThreadPoolManager.cpp.
References m_searchIsRunning.
Referenced by MantidQt::API::FileFinderWidget::isSearching().
|
private |
Get a handle to the static file finder thread pool instance.
Get a handle to the static thread pool managed by this class.
Definition at line 33 of file FindFilesThreadPoolManager.cpp.
References tp.
Referenced by createWorker(), and waitForDone().
|
privateslot |
Mark the search as being finished.
Definition at line 134 of file FindFilesThreadPoolManager.cpp.
References m_searchIsRunning.
Referenced by connectWorker().
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.
allocator | :: The thread allocator function to user to create new worker objects |
Definition at line 60 of file FindFilesThreadPoolManager.cpp.
References m_workerAllocator.
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().
|
private |
Flag set if a search is currently running.
Definition at line 65 of file FindFilesThreadPoolManager.h.
Referenced by cancelWorker(), createWorker(), isSearchRunning(), and searchFinished().
|
private |
Handle to the allocator function for creating new worker threads.
Definition at line 63 of file FindFilesThreadPoolManager.h.
Referenced by createWorker(), and setAllocator().