Thread group class.
More...
#include <ThreadGroup.h>
|
|
using | thread_list = std::list< std::thread * > |
| | Typedef for thread list type.
|
| |
|
using | thread_list_iter = thread_list::iterator |
| | Typedef for thread list iterator type.
|
| |
Thread group class.
This class implements a thread group similar to boost's example implementation but using std::thread instead of boost::thread.
It is the responsibility of the caller of ~ThreadGroup() to make sure that all threads held in the thread group have been joined. This can be done by calling ThreadGroup::JoinAll().
◆ AddThread()
| void core_lib::threads::ThreadGroup::AddThread |
( |
std::thread * |
threadPtr | ) |
|
Add thread to group.
- Parameters
-
| [in] | threadPtr | - Pointer to thread. |
Throws std::runtime_error if called with a thread that already belongs to the thread group.
◆ CreateThread()
template<typename F >
| std::thread* core_lib::threads::ThreadGroup::CreateThread |
( |
F && |
threadfunction | ) |
|
|
inline |
Create and add thread to group.
- Parameters
-
| [in] | threadfunction | - Thread function to use with created thread. |
- Returns
- Pointer to the created thread.
◆ DeleteThread()
| void core_lib::threads::ThreadGroup::DeleteThread |
( |
std::thread * |
threadPtr | ) |
|
|
staticprivate |
Delete thread object.
- Parameters
-
| [in] | threadPtr | - Pointer to thread. |
◆ Empty()
| bool core_lib::threads::ThreadGroup::Empty |
( |
| ) |
const |
Check if we have any threads registered.
- Returns
- True if no threads registered, false otherwise.
◆ IsThisThreadIn()
| bool core_lib::threads::ThreadGroup::IsThisThreadIn |
( |
| ) |
const |
Is current thread in group.
- Returns
- True if in group, false otherwise.
◆ IsThisThreadInNoMutex()
| bool core_lib::threads::ThreadGroup::IsThisThreadInNoMutex |
( |
| ) |
const |
|
private |
Is current thread in group (no mutex).
- Returns
- True if in group, false otherwise.
◆ IsThreadIn() [1/2]
| bool core_lib::threads::ThreadGroup::IsThreadIn |
( |
std::thread * |
threadPtr | ) |
const |
Is given thread in group.
- Parameters
-
| [in] | threadPtr | - Pointer to thread. |
- Returns
- True if in group, false otherwise.
◆ IsThreadIn() [2/2]
| bool core_lib::threads::ThreadGroup::IsThreadIn |
( |
const std::thread::id & |
id | ) |
const |
Is given thread in group.
- Parameters
-
- Returns
- True if in group, false otherwise.
◆ IsThreadInNoMutex()
| bool core_lib::threads::ThreadGroup::IsThreadInNoMutex |
( |
const std::thread::id & |
id | ) |
const |
|
private |
Is given thread in group (no mutex).
- Parameters
-
- Returns
- True if in group, false otherwise.
◆ JoinAll()
| bool core_lib::threads::ThreadGroup::JoinAll |
( |
| ) |
|
Call join on all registered threads.
- Returns
- True if join successful, false otherwise.
◆ RemoveThread() [1/2]
| void core_lib::threads::ThreadGroup::RemoveThread |
( |
std::thread * |
threadPtr | ) |
|
Remove thread from group.
- Parameters
-
| [in] | threadPtr | - Pointer to thread. |
◆ RemoveThread() [2/2]
| std::thread * core_lib::threads::ThreadGroup::RemoveThread |
( |
const std::thread::id & |
id | ) |
|
Remove thread from group.
- Parameters
-
- Returns
- Pointer to thread.
This function returns nullptr if the id cannot be found. Also this function should only be called if the thread for this ID has not been joined else the ID will be invalid.
◆ Size()
| size_t core_lib::threads::ThreadGroup::Size |
( |
| ) |
const |
Get the number of threads registered.
- Returns
- Number of threads.
The documentation for this class was generated from the following files: