Apollo
6.0
Open source self driving car software
modules
perception
lib
thread
thread.h
Go to the documentation of this file.
1
/******************************************************************************
2
* Copyright 2018 The Apollo Authors. All Rights Reserved.
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*****************************************************************************/
16
#pragma once
17
18
#include <string>
19
20
namespace
apollo
{
21
namespace
perception {
22
namespace
lib {
23
24
class
Thread
{
25
public
:
26
explicit
Thread
(
bool
joinable =
false
,
const
std::string &name =
"Thread"
)
27
:
tid_
(0),
started_
(false),
joinable_
(joinable),
thread_name_
(name) {}
28
29
pthread_t
tid
()
const
{
return
tid_
; }
30
31
void
set_joinable
(
bool
joinable) {
32
if
(!
started_
) {
33
joinable_
= joinable;
34
}
35
}
36
37
void
Start
();
38
39
void
Join
();
40
41
bool
IsAlive
();
42
43
std::string
get_thread_name
()
const
{
return
thread_name_
; }
44
void
set_thread_name
(
const
std::string &name) {
thread_name_
= name; }
45
46
Thread
(
const
Thread
&) =
delete
;
47
Thread
&
operator=
(
const
Thread
&) =
delete
;
48
49
protected
:
50
virtual
void
Run
() = 0;
51
52
static
void
*
ThreadRunner
(
void
*arg) {
53
Thread
*t =
reinterpret_cast<
Thread
*
>
(arg);
54
t->
Run
();
55
return
nullptr
;
56
}
57
58
pthread_t
tid_
;
59
bool
started_
;
60
bool
joinable_
;
61
std::string
thread_name_
;
62
63
private
:
64
};
65
66
}
// namespace lib
67
}
// namespace perception
68
}
// namespace apollo
apollo::perception::lib::Thread::started_
bool started_
Definition:
thread.h:59
apollo::perception::lib::Thread::tid_
pthread_t tid_
Definition:
thread.h:58
apollo
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition:
atomic_hash_map.h:25
apollo::perception::lib::Thread::set_joinable
void set_joinable(bool joinable)
Definition:
thread.h:31
apollo::perception::lib::Thread::thread_name_
std::string thread_name_
Definition:
thread.h:61
apollo::perception::lib::Thread::Start
void Start()
apollo::perception::lib::Thread::Thread
Thread(bool joinable=false, const std::string &name="Thread")
Definition:
thread.h:26
apollo::perception::lib::Thread::IsAlive
bool IsAlive()
apollo::perception::lib::Thread::operator=
Thread & operator=(const Thread &)=delete
apollo::perception::lib::Thread
Definition:
thread.h:24
apollo::perception::lib::Thread::Run
virtual void Run()=0
apollo::perception::lib::Thread::Join
void Join()
apollo::perception::lib::Thread::ThreadRunner
static void * ThreadRunner(void *arg)
Definition:
thread.h:52
apollo::perception::lib::Thread::get_thread_name
std::string get_thread_name() const
Definition:
thread.h:43
apollo::perception::lib::Thread::joinable_
bool joinable_
Definition:
thread.h:60
apollo::perception::lib::Thread::set_thread_name
void set_thread_name(const std::string &name)
Definition:
thread.h:44
apollo::perception::lib::Thread::tid
pthread_t tid() const
Definition:
thread.h:29
Generated by
1.8.13