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

#include <choreography_context.h>

类 apollo::cyber::scheduler::ChoreographyContext 继承关系图:
apollo::cyber::scheduler::ChoreographyContext 的协作图:

Public 成员函数

bool RemoveCRoutine (uint64_t crid)
 
std::shared_ptr< CRoutineNextRoutine () override
 
bool Enqueue (const std::shared_ptr< CRoutine > &)
 
void Notify ()
 
void Wait () override
 
void Shutdown () override
 

额外继承的成员函数

- Protected 属性 继承自 apollo::cyber::scheduler::ProcessorContext
std::atomic< bool > stop_ {false}
 

详细描述

在文件 choreography_context.h38 行定义.

成员函数说明

◆ Enqueue()

bool apollo::cyber::scheduler::ChoreographyContext::Enqueue ( const std::shared_ptr< CRoutine > &  cr)

在文件 choreography_context.cc55 行定义.

55 {
56 WriteLockGuard<AtomicRWLock> lock(rq_lk_);
57 cr_queue_.emplace(cr->priority(), cr);
58 return true;
59}

◆ NextRoutine()

std::shared_ptr< CRoutine > apollo::cyber::scheduler::ChoreographyContext::NextRoutine ( )
overridevirtual

实现了 apollo::cyber::scheduler::ProcessorContext.

在文件 choreography_context.cc35 行定义.

35 {
36 if (cyber_unlikely(stop_.load())) {
37 return nullptr;
38 }
39
40 ReadLockGuard<AtomicRWLock> lock(rq_lk_);
41 for (auto it : cr_queue_) {
42 auto cr = it.second;
43 if (!cr->Acquire()) {
44 continue;
45 }
46
47 if (cr->UpdateState() == RoutineState::READY) {
48 return cr;
49 }
50 cr->Release();
51 }
52 return nullptr;
53}
#define cyber_unlikely(x)
Definition macros.h:30

◆ Notify()

void apollo::cyber::scheduler::ChoreographyContext::Notify ( )

在文件 choreography_context.cc61 行定义.

61 {
62 mtx_wq_.lock();
63 notify++;
64 mtx_wq_.unlock();
65 cv_wq_.notify_one();
66}

◆ RemoveCRoutine()

bool apollo::cyber::scheduler::ChoreographyContext::RemoveCRoutine ( uint64_t  crid)

在文件 choreography_context.cc85 行定义.

85 {
86 WriteLockGuard<AtomicRWLock> lock(rq_lk_);
87 for (auto it = cr_queue_.begin(); it != cr_queue_.end();) {
88 auto cr = it->second;
89 if (cr->id() == crid) {
90 cr->Stop();
91 while (!cr->Acquire()) {
92 std::this_thread::sleep_for(std::chrono::milliseconds(1));
93 AINFO_EVERY(1000) << "waiting for task " << cr->name() << " completion";
94 }
95 it = cr_queue_.erase(it);
96 cr->Release();
97 return true;
98 }
99 ++it;
100 }
101 return false;
102}
#define AINFO_EVERY(freq)
Definition log.h:82

◆ Shutdown()

void apollo::cyber::scheduler::ChoreographyContext::Shutdown ( )
overridevirtual

重载 apollo::cyber::scheduler::ProcessorContext .

在文件 choreography_context.cc77 行定义.

77 {
78 stop_.store(true);
79 mtx_wq_.lock();
80 notify = std::numeric_limits<unsigned char>::max();
81 mtx_wq_.unlock();
82 cv_wq_.notify_all();
83}

◆ Wait()

void apollo::cyber::scheduler::ChoreographyContext::Wait ( )
overridevirtual

实现了 apollo::cyber::scheduler::ProcessorContext.

在文件 choreography_context.cc68 行定义.

68 {
69 std::unique_lock<std::mutex> lk(mtx_wq_);
70 cv_wq_.wait_for(lk, std::chrono::milliseconds(1000),
71 [&]() { return notify > 0; });
72 if (notify > 0) {
73 notify--;
74 }
75}

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