CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
ThreadGroup.h
Go to the documentation of this file.
1
// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2
// de Barcelona (UAB).
3
//
4
// This work is licensed under the terms of the MIT license.
5
// For a copy, see <https://opensource.org/licenses/MIT>.
6
7
#pragma once
8
9
#include "
carla/Debug.h
"
10
#include "
carla/NonCopyable.h
"
11
12
#include <thread>
13
#include <vector>
14
15
namespace
carla
{
16
17
class
ThreadGroup
:
private
NonCopyable
{
18
public
:
19
20
ThreadGroup
() =
default
;
21
22
~ThreadGroup
() {
23
JoinAll
();
24
}
25
26
template
<
typename
F>
27
void
CreateThread
(F &&functor) {
28
_threads
.emplace_back(std::forward<F>(functor));
29
}
30
31
template
<
typename
F>
32
void
CreateThreads
(
size_t
count, F functor) {
33
_threads
.reserve(
_threads
.size() + count);
34
for
(
size_t
i = 0u; i < count; ++i) {
35
CreateThread
(functor);
36
}
37
}
38
39
void
JoinAll
() {
40
for
(
auto
&thread :
_threads
) {
41
DEBUG_ASSERT_NE
(thread.get_id(), std::this_thread::get_id());
42
if
(thread.joinable()) {
43
thread.join();
44
}
45
}
46
_threads
.clear();
47
}
48
49
private
:
50
51
std::vector<std::thread>
_threads
;
52
};
53
54
}
// namespace carla
Debug.h
DEBUG_ASSERT_NE
#define DEBUG_ASSERT_NE(lhs, rhs)
Definition
Debug.h:77
NonCopyable.h
carla::NonCopyable::NonCopyable
NonCopyable()=default
carla::ThreadGroup::~ThreadGroup
~ThreadGroup()
Definition
ThreadGroup.h:22
carla::ThreadGroup::_threads
std::vector< std::thread > _threads
Definition
ThreadGroup.h:51
carla::ThreadGroup::JoinAll
void JoinAll()
Definition
ThreadGroup.h:39
carla::ThreadGroup::CreateThreads
void CreateThreads(size_t count, F functor)
Definition
ThreadGroup.h:32
carla::ThreadGroup::ThreadGroup
ThreadGroup()=default
carla::ThreadGroup::CreateThread
void CreateThread(F &&functor)
Definition
ThreadGroup.h:27
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
Generated by
1.18.0