Apollo 11.0
自动驾驶开放平台
apollo::cyber::io::Poller类 参考

#include <poller.h>

apollo::cyber::io::Poller 的协作图:

Public 类型

using RequestPtr = std::shared_ptr< PollRequest >
 
using RequestMap = std::unordered_map< int, RequestPtr >
 
using CtrlParamMap = std::unordered_map< int, PollCtrlParam >
 

Public 成员函数

virtual ~Poller ()
 
void Shutdown ()
 
bool Register (const PollRequest &req)
 
bool Unregister (const PollRequest &req)
 

详细描述

在文件 poller.h 第 36 行定义.

成员类型定义说明

◆ CtrlParamMap

using apollo::cyber::io::Poller::CtrlParamMap = std::unordered_map<int, PollCtrlParam>

在文件 poller.h 第 40 行定义.

◆ RequestMap

using apollo::cyber::io::Poller::RequestMap = std::unordered_map<int, RequestPtr>

在文件 poller.h 第 39 行定义.

◆ RequestPtr

在文件 poller.h 第 38 行定义.

构造及析构函数说明

◆ ~Poller()

apollo::cyber::io::Poller::~Poller ( )
virtual

在文件 poller.cc 第 45 行定义.

45{ Shutdown(); }

成员函数说明

◆ Register()

bool apollo::cyber::io::Poller::Register ( const PollRequest &  req)

在文件 poller.cc 第 54 行定义.

54 {
55 if (is_shutdown_.load()) {
56 return false;
57 }
58
59 if (req.fd < 0 || req.callback == nullptr) {
60 AERROR << "input is invalid";
61 return false;
62 }
63
64 PollCtrlParam ctrl_param{};
65 ctrl_param.fd = req.fd;
66 ctrl_param.event.data.fd = req.fd;
67 ctrl_param.event.events = req.events;
68
69 {
70 WriteLockGuard<AtomicRWLock> lck(poll_data_lock_);
71 if (requests_.count(req.fd) == 0) {
72 ctrl_param.operation = EPOLL_CTL_ADD;
73 requests_[req.fd] = std::make_shared<PollRequest>();
74 } else {
75 ctrl_param.operation = EPOLL_CTL_MOD;
76 }
77 *requests_[req.fd] = req;
78 ctrl_params_[ctrl_param.fd] = ctrl_param;
79 }
80
81 Notify();
82 return true;
83}
#define AERROR
Definition log.h:44

◆ Shutdown()

void apollo::cyber::io::Poller::Shutdown ( )

在文件 poller.cc 第 47 行定义.

47 {
48 if (is_shutdown_.exchange(true)) {
49 return;
50 }
51 Clear();
52}

◆ Unregister()

bool apollo::cyber::io::Poller::Unregister ( const PollRequest &  req)

在文件 poller.cc 第 85 行定义.

85 {
86 if (is_shutdown_.load()) {
87 return false;
88 }
89
90 if (req.fd < 0 || req.callback == nullptr) {
91 AERROR << "input is invalid";
92 return false;
93 }
94
95 {
96 WriteLockGuard<AtomicRWLock> lck(poll_data_lock_);
97 auto size = requests_.erase(req.fd);
98 if (size == 0) {
99 AERROR << "unregister failed, can't find fd: " << req.fd;
100 return false;
101 }
102
103 PollCtrlParam ctrl_param;
104 ctrl_param.operation = EPOLL_CTL_DEL;
105 ctrl_param.fd = req.fd;
106 ctrl_params_[ctrl_param.fd] = ctrl_param;
107 }
108
109 Notify();
110 return true;
111}

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