Apollo 11.0
自动驾驶开放平台
apollo::perception::lib::Thread类 参考abstract

#include <thread.h>

类 apollo::perception::lib::Thread 继承关系图:
apollo::perception::lib::Thread 的协作图:

Public 成员函数

 Thread (bool joinable=false, const std::string &name="Thread")
 
pthread_t tid () const
 
void set_joinable (bool joinable)
 
void Start ()
 
void Join ()
 
bool IsAlive ()
 
std::string get_thread_name () const
 
void set_thread_name (const std::string &name)
 
 Thread (const Thread &)=delete
 
Threadoperator= (const Thread &)=delete
 

Protected 成员函数

virtual void Run ()=0
 

静态 Protected 成员函数

static void * ThreadRunner (void *arg)
 

Protected 属性

pthread_t tid_
 
bool started_
 
bool joinable_
 
std::string thread_name_
 

详细描述

在文件 thread.h24 行定义.

构造及析构函数说明

◆ Thread() [1/2]

apollo::perception::lib::Thread::Thread ( bool  joinable = false,
const std::string &  name = "Thread" 
)
inlineexplicit

在文件 thread.h26 行定义.

◆ Thread() [2/2]

apollo::perception::lib::Thread::Thread ( const Thread )
delete

成员函数说明

◆ get_thread_name()

std::string apollo::perception::lib::Thread::get_thread_name ( ) const
inline

在文件 thread.h43 行定义.

43{ return thread_name_; }

◆ IsAlive()

bool apollo::perception::lib::Thread::IsAlive ( )

在文件 thread.cc52 行定义.

52 {
53 if (tid_ == 0) {
54 return false;
55 }
56 // no signal sent, just check existence for thread
57 int ret = pthread_kill(tid_, 0);
58 if (ret == ESRCH) {
59 return false;
60 }
61 if (ret == EINVAL) {
62 AWARN << "Invalid singal.";
63 return false;
64 }
65
66 return true;
67}
#define AWARN
Definition log.h:43

◆ Join()

void apollo::perception::lib::Thread::Join ( )

在文件 thread.cc44 行定义.

44 {
45 ACHECK(joinable_) << "Thread is not joinable";
46 int result = pthread_join(tid_, nullptr);
47 CHECK_EQ(result, 0) << "Could not join thread (" << tid_ << ", "
48 << thread_name_ << ")";
49 tid_ = 0;
50}
#define ACHECK(cond)
Definition log.h:80

◆ operator=()

Thread & apollo::perception::lib::Thread::operator= ( const Thread )
delete

◆ Run()

virtual void apollo::perception::lib::Thread::Run ( )
protectedpure virtual

◆ set_joinable()

void apollo::perception::lib::Thread::set_joinable ( bool  joinable)
inline

在文件 thread.h31 行定义.

31 {
32 if (!started_) {
33 joinable_ = joinable;
34 }
35 }

◆ set_thread_name()

void apollo::perception::lib::Thread::set_thread_name ( const std::string &  name)
inline

在文件 thread.h44 行定义.

44{ thread_name_ = name; }

◆ Start()

void apollo::perception::lib::Thread::Start ( )

在文件 thread.cc26 行定义.

26 {
27 pthread_attr_t attr;
28 CHECK_EQ(pthread_attr_init(&attr), 0);
29 CHECK_EQ(
30 pthread_attr_setdetachstate(
31 &attr, joinable_ ? PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED),
32 0);
33 CHECK_EQ(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, nullptr), 0);
34 CHECK_EQ(pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, nullptr), 0);
35
36 int result = pthread_create(&tid_, &attr, &ThreadRunner, this);
37 CHECK_EQ(result, 0) << "Could not create thread (" << result << ")";
38
39 CHECK_EQ(pthread_attr_destroy(&attr), 0);
40
41 started_ = true;
42}
static void * ThreadRunner(void *arg)
Definition thread.h:52

◆ ThreadRunner()

static void * apollo::perception::lib::Thread::ThreadRunner ( void *  arg)
inlinestaticprotected

在文件 thread.h52 行定义.

52 {
53 Thread *t = reinterpret_cast<Thread *>(arg);
54 t->Run();
55 return nullptr;
56 }
Thread(bool joinable=false, const std::string &name="Thread")
Definition thread.h:26

◆ tid()

pthread_t apollo::perception::lib::Thread::tid ( ) const
inline

在文件 thread.h29 行定义.

29{ return tid_; }

类成员变量说明

◆ joinable_

bool apollo::perception::lib::Thread::joinable_
protected

在文件 thread.h60 行定义.

◆ started_

bool apollo::perception::lib::Thread::started_
protected

在文件 thread.h59 行定义.

◆ thread_name_

std::string apollo::perception::lib::Thread::thread_name_
protected

在文件 thread.h61 行定义.

◆ tid_

pthread_t apollo::perception::lib::Thread::tid_
protected

在文件 thread.h58 行定义.


该类的文档由以下文件生成: