Apollo 10.0
自动驾驶开放平台
apollo::cyber::scheduler::Processor类 参考

#include <processor.h>

apollo::cyber::scheduler::Processor 的协作图:

Public 成员函数

 Processor ()
 
virtual ~Processor ()
 
void Run ()
 
void Stop ()
 
void BindContext (const std::shared_ptr< ProcessorContext > &context)
 
std::thread * Thread ()
 
std::atomic< pid_t > & Tid ()
 
std::shared_ptr< SnapshotProcSnapshot ()
 

详细描述

在文件 processor.h45 行定义.

构造及析构函数说明

◆ Processor()

apollo::cyber::scheduler::Processor::Processor ( )

在文件 processor.cc36 行定义.

36{ running_.store(true); }

◆ ~Processor()

apollo::cyber::scheduler::Processor::~Processor ( )
virtual

在文件 processor.cc38 行定义.

成员函数说明

◆ BindContext()

void apollo::cyber::scheduler::Processor::BindContext ( const std::shared_ptr< ProcessorContext > &  context)

在文件 processor.cc79 行定义.

79 {
80 context_ = context;
81 std::call_once(thread_flag_,
82 [this]() { thread_ = std::thread(&Processor::Run, this); });
83}

◆ ProcSnapshot()

std::shared_ptr< Snapshot > apollo::cyber::scheduler::Processor::ProcSnapshot ( )
inline

在文件 processor.h56 行定义.

56{ return snap_shot_; }

◆ Run()

void apollo::cyber::scheduler::Processor::Run ( )

在文件 processor.cc40 行定义.

40 {
41 tid_.store(static_cast<int>(syscall(SYS_gettid)));
42 AINFO << "processor_tid: " << tid_;
43 snap_shot_->processor_id.store(tid_);
44
45 while (cyber_likely(running_.load())) {
46 if (cyber_likely(context_ != nullptr)) {
47 auto croutine = context_->NextRoutine();
48 if (croutine) {
49 snap_shot_->execute_start_time.store(cyber::Time::Now().ToNanosecond());
50 snap_shot_->routine_name = croutine->name();
51 croutine->Resume();
52 croutine->Release();
53 } else {
54 snap_shot_->execute_start_time.store(0);
55 context_->Wait();
56 }
57 } else {
58 std::unique_lock<std::mutex> lk(mtx_ctx_);
59 cv_ctx_.wait_for(lk, std::chrono::milliseconds(10));
60 }
61 }
62}
static Time Now()
get the current time.
Definition time.cc:57
#define cyber_likely(x)
Definition macros.h:29
#define AINFO
Definition log.h:42

◆ Stop()

void apollo::cyber::scheduler::Processor::Stop ( )

在文件 processor.cc64 行定义.

64 {
65 if (!running_.exchange(false)) {
66 return;
67 }
68
69 if (context_) {
70 context_->Shutdown();
71 }
72
73 cv_ctx_.notify_one();
74 if (thread_.joinable()) {
75 thread_.join();
76 }
77}

◆ Thread()

std::thread * apollo::cyber::scheduler::Processor::Thread ( )
inline

在文件 processor.h53 行定义.

53{ return &thread_; }

◆ Tid()

std::atomic< pid_t > & apollo::cyber::scheduler::Processor::Tid ( )

在文件 processor.cc85 行定义.

85 {
86 while (tid_.load() == -1) {
87 cpu_relax();
88 }
89 return tid_;
90}
void cpu_relax()
Definition macros.h:53

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