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

#include <classic_context.h>

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

Public 成员函数

 ClassicContext ()
 
 ClassicContext (const std::string &group_name)
 
std::shared_ptr< CRoutineNextRoutine () override
 
void Wait () override
 
void Shutdown () override
 

静态 Public 成员函数

static void Notify (const std::string &group_name)
 
static bool RemoveCRoutine (const std::shared_ptr< CRoutine > &cr)
 

静态 Public 属性

static CR_GROUP cr_group_
 
static RQ_LOCK_GROUP rq_locks_
 
static GRP_WQ_CV cv_wq_
 
static GRP_WQ_MUTEX mtx_wq_
 
static NOTIFY_GRP notify_grp_
 

额外继承的成员函数

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

详细描述

在文件 classic_context.h52 行定义.

构造及析构函数说明

◆ ClassicContext() [1/2]

apollo::cyber::scheduler::ClassicContext::ClassicContext ( )

在文件 classic_context.cc37 行定义.

37{ InitGroup(DEFAULT_GROUP_NAME); }
#define DEFAULT_GROUP_NAME

◆ ClassicContext() [2/2]

apollo::cyber::scheduler::ClassicContext::ClassicContext ( const std::string &  group_name)
explicit

在文件 classic_context.cc39 行定义.

39 {
40 InitGroup(group_name);
41}

成员函数说明

◆ NextRoutine()

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

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

在文件 classic_context.cc52 行定义.

52 {
53 if (cyber_unlikely(stop_.load())) {
54 return nullptr;
55 }
56
57 for (int i = MAX_PRIO - 1; i >= 0; --i) {
58 ReadLockGuard<AtomicRWLock> lk(lq_->at(i));
59 for (auto& cr : multi_pri_rq_->at(i)) {
60 if (!cr->Acquire()) {
61 continue;
62 }
63
64 if (cr->UpdateState() == RoutineState::READY) {
65 return cr;
66 }
67
68 cr->Release();
69 }
70 }
71
72 return nullptr;
73}
#define cyber_unlikely(x)
Definition macros.h:30

◆ Notify()

void apollo::cyber::scheduler::ClassicContext::Notify ( const std::string &  group_name)
static

在文件 classic_context.cc92 行定义.

92 {
93 (&mtx_wq_[group_name])->Mutex().lock();
94 notify_grp_[group_name]++;
95 (&mtx_wq_[group_name])->Mutex().unlock();
96 cv_wq_[group_name].Cv().notify_one();
97}

◆ RemoveCRoutine()

bool apollo::cyber::scheduler::ClassicContext::RemoveCRoutine ( const std::shared_ptr< CRoutine > &  cr)
static

在文件 classic_context.cc99 行定义.

99 {
100 auto grp = cr->group_name();
101 auto prio = cr->priority();
102 auto crid = cr->id();
103 WriteLockGuard<AtomicRWLock> lk(ClassicContext::rq_locks_[grp].at(prio));
104 auto& croutines = ClassicContext::cr_group_[grp].at(prio);
105 for (auto it = croutines.begin(); it != croutines.end(); ++it) {
106 if ((*it)->id() == crid) {
107 auto cr = *it;
108 cr->Stop();
109 while (!cr->Acquire()) {
110 std::this_thread::sleep_for(std::chrono::microseconds(1));
111 AINFO_EVERY(1000) << "waiting for task " << cr->name() << " completion";
112 }
113 croutines.erase(it);
114 cr->Release();
115 return true;
116 }
117 }
118 return false;
119}
#define AINFO_EVERY(freq)
Definition log.h:82

◆ Shutdown()

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

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

在文件 classic_context.cc84 行定义.

84 {
85 stop_.store(true);
86 mtx_wrapper_->Mutex().lock();
87 notify_grp_[current_grp] = std::numeric_limits<unsigned char>::max();
88 mtx_wrapper_->Mutex().unlock();
89 cw_->Cv().notify_all();
90}
std::condition_variable & Cv()
Definition cv_wrapper.h:29

◆ Wait()

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

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

在文件 classic_context.cc75 行定义.

75 {
76 std::unique_lock<std::mutex> lk(mtx_wrapper_->Mutex());
77 cw_->Cv().wait_for(lk, std::chrono::milliseconds(1000),
78 [&]() { return notify_grp_[current_grp] > 0; });
79 if (notify_grp_[current_grp] > 0) {
80 notify_grp_[current_grp]--;
81 }
82}

类成员变量说明

◆ cr_group_

CR_GROUP apollo::cyber::scheduler::ClassicContext::cr_group_
static

在文件 classic_context.h64 行定义.

◆ cv_wq_

GRP_WQ_CV apollo::cyber::scheduler::ClassicContext::cv_wq_
static

在文件 classic_context.h66 行定义.

◆ mtx_wq_

GRP_WQ_MUTEX apollo::cyber::scheduler::ClassicContext::mtx_wq_
static

在文件 classic_context.h67 行定义.

◆ notify_grp_

NOTIFY_GRP apollo::cyber::scheduler::ClassicContext::notify_grp_
static

在文件 classic_context.h68 行定义.

◆ rq_locks_

RQ_LOCK_GROUP apollo::cyber::scheduler::ClassicContext::rq_locks_
static

在文件 classic_context.h65 行定义.


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