classes及messages
全局配置
class GlobalData
成员变量 | 值 |
---|
CyberConfig config_ | CHECK(InitConfig()) |
std::string host_ip_ | InitHostInfo() |
:string host_name_ | InitHostInfo() |
int process_id_ | getpid() |
std::string process_group_ | “cyber_default_” + std::to_string(process_id_) |
std::string sched_name_ | “CYBER_DEFAULT” |
bool is_reality_mode_ | true |
static AtomicHashMap<uint64_t, std::string, 512> node_id_map_ | |
static AtomicHashMap<uint64_t, std::string, 256> channel_id_map_ | |
static AtomicHashMap<uint64_t, std::string, 256> service_id_map_ | |
static AtomicHashMap<uint64_t, std::string, 256> task_id_map_ | |
message CyberConfig
成员变量 |
---|
optional SchedulerConf scheduler_conf = 1; |
optional TransportConf transport_conf = 2; |
optional RunModeConf run_mode_conf = 3; |
class AtomicHashMap
成员变量 | 值 |
---|
Bucket table_[TableSize] | TableSize=128默认 |
uint64_t capacity_ | TableSize |
uint64_t mode_num_ | capacity_-1 |
enum State:std::unit8_t
成员变量 |
---|
STATE_UNINITIALIZED |
STATE_INITIALIZED |
STATE_SHUTTING_DOWN |
STATE_SHUTDOWN |
class Transport /单例
成员变量 | 值 |
---|
std::atomic is_shutdown_ | |
ParticipantPtr participant_ | |
NotifierPtr notifier_ | |
IntraDispatcherPtr intra_dispatcher_ | |
ShmDispatcherPtr shm_dispatcher_ | |
RtpsDispatcherPtr rtps_dispatcher_ | |
成员函数 | 属性 |
---|
CreateTransmitter(const RoleAttributes& attr,const OptionalMode& mode = OptionalMode::HYBRID) | public |
CreateReceiver(const RoleAttributes& attr,const OptionalMode& mode = OptionalMode::HYBRID) | public |
class TopologyManager /单例
成员变量 | 值 |
---|
std::atomic init_ | |
NodeManagerPtr node_manager_ | |
ChannelManagerPtr channel_manager_ | |
ServiceManagerPtr service_manager_ | |
transport::ParticipantPtr participant_ | |
ParticipantListener* participant_listener_ | |
ChangeSignal change_signal_ | |
PartNameContainer participant_names_ | |
通信
class Node
成员变量 | 值 |
---|
std::string node_name_ | 节点名字 |
std::string name_space_ | 一般为空 |
std::mutex readers_mutex_ | |
std::map<std::string, std::shared_ptr> readers_ | readers_.emplace(std::make_pair(channel_name, reader)); |
std::unique_ptr node_channel_impl_ | new NodeChannelImpl(node_name) |
std::unique_ptr node_service_impl_# | new NodeServiceImpl(node_name) |
messages RoleAttributes
成员变量 |
---|
optional string host_name = 1; |
optional string host_ip = 2; |
optional int32 process_id = 3; |
optional string node_name = 4; |
optional uint64 node_id = 5; // hash value of node_name |
// especially for WRITER and READER |
optional string channel_name = 6; |
optional uint64 channel_id = 7; // hash value of channel_name |
optional string message_type = 8; |
optional bytes proto_desc = 9; |
optional uint64 id = 10; |
optional QosProfile qos_profile = 11; |
optional SocketAddr socket_addr = 12; // reserved for socket communication |
// especially for SERVER and CLIENT |
optional string service_name = 13; |
optional uint64 service_id = 14; |
class NodeChannelImpl
class NodeChannelImpl 成员变量 | 值 |
---|
bool is_reality_mode_ | 假定true |
string node_name_ | 节点名字 |
proto::RoleAttributes node_attr_ | 见下表 |
NodeManagerPtr node_manager_ | service_discovery::TopologyManager::Instance()->node_manager(); |
成员变量proto::RoleAttributes node_attr_ | |
---|
optional string host_name = 1; | common::GlobalData::Instance()->HostName() |
optional string host_ip = 2; | common::GlobalData::Instance()->HostIp() |
optional int32 process_id = 3; | common::GlobalData::Instance()->ProcessId() |
string node_name = 4; | node_name |
optional uint64 node_id = 5; // hash value of node_name | common::GlobalData::RegisterNode(node_name) |
// especially for WRITER and READER | |
optional string channel_name = 6; | |
optional uint64 channel_id = 7; // hash value of channel_name | |
optional string message_type = 8; | |
optional bytes proto_desc = 9; | |
optional uint64 id = 10; | |
optional QosProfile qos_profile = 11; | |
optional SocketAddr socket_addr = 12; // reserved for socket communication | |
// especially for SERVER and CLIENT | |
optional string service_name = 13; | |
optional uint64 service_id = 14; | |
部分成员函数 | 局部变量 |
---|
CreateWriter(const proto::RoleAttributes& role_attr) | new_attr FillInAttr(&new_attr);//为new_attr赋初值 |
CreateReader(const proto::RoleAttributes& role_attr, const CallbackFunc& reader_func, uint32_t pending_queue_size) | new_attr FillInAttr(&new_attr);//为new_attr赋初值 |
CreateWriter/CreateReader 局部变量 new_attr_ | |
---|
optional string host_name = 1; | node_attr_.host_name() |
optional string host_ip = 2; | node_attr_.host_ip() |
optional int32 process_id = 3; | node_attr_.process_id() |
string node_name = 4; | node_name |
optional uint64 node_id = 5; // hash value of node_name | common::GlobalData::RegisterNode(node_name) |
// especially for WRITER and READER | |
optional string channel_name = 6; | channel_name |
optional uint64 channel_id = 7; // hash value of channel_name | GlobalData::RegisterChannel(channel_name); |
optional string message_type = 8; | message::MessageType() |
optional bytes proto_desc = 9; | message::GetDescriptorString(attr->message_type(), &proto_desc); |
optional uint64 id = 10; | |
optional QosProfile qos_profile = 11; | attr->mutable_qos_profile()->CopyFrom(transport::QosProfileConf::QOS_PROFILE_DEFAULT); |
optional SocketAddr socket_addr = 12; // reserved for socket communication | |
// especially for SERVER and CLIENT | |
optional string service_name = 13; | |
optional uint64 service_id = 14; | |
class Manager
using ChangeSignal = base::Signal<const ChangeMsg&>;
成员变量/protected | 值 |
---|
std::atomic is_shutdown_ | false |
std::atomic is_discovery_started_ | false |
int allowed_role_ | 0 |
ChangeType change_type_ | proto::ChangeType::CHANGE_PARTICIPANT |
std::string host_name_ | host_name_ = common::GlobalData::Instance()->HostName() |
int process_id_ | common::GlobalData::Instance()->ProcessId() |
std::string channel_name_ | “” |
eprosima::fastrtps::Publisher* publisher_ | nullptr |
eprosima::fastrtps::Subscriber* subscriber_; | nullptr |
SubscriberListener* listener_; | nullptr |
ChangeSignal signal_ | signal_(msg),修改于Manager::Notify(const ChangeMsg& msg) |
部分成员函数 | 局部变量 |
---|
Join(const RoleAttributes& attr, RoleType role, bool need_publish) 其中attr=node_attr_,need_publish=true | ChangeMsg msg ;Convert(attr, role, OperateType::OPT_JOIN, &msg); |
ChangeConnection AddChangeListener(const ChangeFunc& func) | |
| |
| |
| |
message ChangeMsg
成员变量 | 值 |
---|
optional uint64 timestamp = 1; | cyber::Time::Now().ToNanosecond() |
optional ChangeType change_type = 2; | change_type_ |
optional OperateType operate_type = 3; | OperateType::OPT_JOIN |
optional RoleType role_type = 4; | proto::RoleType::ROLE_WRITER或NODE或… |
optional RoleAttributes role_attr = 5; | NodeChannelImpl类中node_attr_或Writer中的role_attr__ |
class NodeManager
using NodeWarehouse = SingleValueWarehouse
class NodeManager : public Manager | 值 |
---|
NodeWarehouse nodes_ | SingleValueWarehouse nodes_ |
allowed_role_ | allowed_role_ | (1 << RoleType::ROLE_NODE) |
change_type_ | ChangeType::CHANGE_NODE; |
channel_name_ | “node_change_broadcast” |
class ChannelManager
using WriterWarehouse = MultiValueWarehouse;
using ReaderWarehouse = MultiValueWarehouse;
class ChannelManager : public Manager | 值 |
---|
ExemptedMessageTypes exempted_msg_types_ | emplace(message::MessageType< message::RawMessage>()); emplace(message::MessageType< message::PyMessageWrap>()); |
Graph node_graph_ | node_graph_.Insert(e),其中e为ChannelManager::DisposeJoin函数中Edge e; |
WriterWarehouse node_writers_ | node_writers_.Add(role->attributes().node_id(), role),在ChannelManager::DisposeJoin中 |
ReaderWarehouse node_readers_ | node_readers_.node_readers_.Add(role->attributes().node_id(), role) |
WriterWarehouse channel_writers_ | channel_writers_.Add(role->attributes().channel_id(), role) |
ReaderWarehouse channel_readers_ | channel_readers_.Add(role->attributes().channel_id(), role) |
allowed_role_ | allowed_role_|(1 << RoleType::ROLE_WRITER)|1 << (RoleType::ROLE_READER) |
change_type_ | ChangeType::CHANGE_CHANNEL |
channel_name_ | channel_name_ = “channel_change_broadcast”; |
class MultiValueWarehouse
class MultiValueWarehouse : public WarehouseBase | 值 |
---|
RoleMap roles_ | std::unordered_multimap<uint64_t, RolePtr> roles_ |
base::AtomicRWLock rw_lock_ | |
class WriterBase
成员变量/protected | 值 |
---|
proto::RoleAttributes role_attr_ | role_attr__.id=transmitter_->id().HashValue(), 其他部分与new_attr相同 |
mutable std::mutex lock_ | |
bool init_ | true |
class Writer
class Writer : public WriterBase | 值 |
---|
TransmitterPtr transmitter_ | transport::Transport::Instance()->CreateTransmitter(role_attr_) =std::make_shared<ShmTransmitter>(modified_attr) |
ChangeConnection change_conn_ | channel_manager_->AddChangeListener(std::bind( &Writer::OnChannelChange, this, std::placeholders::_1)); =Connection |
service_discovery::ChannelManagerPtr channel_manager_ | service_discovery::TopologyManager::Instance()-> channel_manager(); |
class Endpoint
成员变量/protected | 值 |
---|
bool enabled_ | true |
Identity id_ | id() |
RoleAttributes attr_ | Writer或Reader类中的role_attr_ |
class Transmitter
class Transmitter : public Endpoint /protected | 值 |
---|
uint64_t seq_num_ | 0 |
MessageInfo msg_info_ | msg_info_.set_sender_id(this->id_); msg_info_.set_seq_num(this->seq_num_); |
class MessageInfo
成员变量 | 值 |
---|
Identity sender_id_ | msg_info_.set_sender_id(this->id_); 其中this->id_在Transmitter中 |
uint64_t seq_num_ | msg_info_.set_seq_num(this->seq_num_); 其中this->seq_num_在Transmitter中 |
Identity spare_id_ | msg_info_.set_seq_num(NextSeqNum()); 在Transmitter::Transmit函数中实现 |
class ReadableInfo
函数bool ShmTransmitter::Transmit(const M& msg, const MessageInfo& msg_info)中
ReadableInfo readable_info(host_id__, wb.index, channel_id_);
成员变量 | 值 |
---|
uint64_t host_id_ | host_id_,在bool ShmTransmitter::Transmit函数 |
uint32_t block_index_ | wb.index |
uint64_t channel_id_ | channel_id_ |
class ShmTransmitter
class ShmTransmitter : public Transmitter | 值 |
---|
SegmentPtr segment_ | std::make_shared(channel_id_, WRITE_ONLY) |
uint64_t channel_id_ | attr.channel_id(), 其中attr=Writer中的role_attr_ |
uint64_t host_id_ | common::Hash(attr.host_ip()) |
NotifierPtr notifier_ | NotifierFactory::CreateNotifier()=ConditionNtifier::Instance() |
成员函数 | 局部变量 |
---|
ShmTransmitter::Transmit(const M& msg, const MessageInfo& msg_info) | WritableBlock wb |
class Segment
ShmTransmitter::Enable()函数中
segment_ = std::make_shared(channel_id_, WRITE_ONLY);
bool Segment::OpenOrCreate()
成员函数 | 值 |
---|
bool init_ | false |
key_t id_ | static_cast<key_t>(channel_id) |
ReadWriteMode mode_ | WRITE_ONLY |
ShmConf conf_ | conf_() |
state_ | nullptr |
Block* blocks_ | nullptr |
void* managed_shm_ | nullptr |
std::mutex block_buf_lock_ | block_buf_lock_() |
std::unordered_map<uint32_t, uint8_t*> block_buf_addrs_ | block_buf_addrs_() |
struct WritableBlock
Segment::AcquireBlockToWrite(std::size_t msg_size, WritableBlock* writable_block)
成员函数 | 初始值 |
---|
uint32_t index | writable_block->index = index |
Block* block | writable_block->block = &blocks_[index] |
uint8_t* buf | writable_block->buf = block_buf_addrs_[index] ,保存msg及msg_info_ |
class Block
ShmTransmitter::Transmit(const M& msg, const MessageInfo& msg_info)
成员变量 | 值 |
---|
volatile std::atomic<int32_t> lock_num_ = {0}; | |
uint64_t msg_size_; | wb.block->set_msg_size(msg_size) |
uint64_t msg_info_size_; | wb.block->set_msg_info_size(MessageInfo::kSize) |
class Vertice
成员变量 | 值 |
---|
std::string value_ | msg.role_attr().node_name() ,其中msg为Manager::Join函数中的ChangeMsg msg; |
class Edge
成员变量 | 值 |
---|
Vertice src_ | v(msg.role_attr().node_name()),其中msg为Manager::Join函数中的ChangeMsg msg; |
Vertice dst_ | v(msg.role_attr().node_name()) |
std::string value_ | msg.role_attr().channel_name() |
class PerfEventCache
单例
成员变量 | 值 |
---|
std::thread io_thread_ | |
std::ofstream of_ | |
bool enable_trans_perf_ = false | |
bool enable_sched_perf_ = false | |
std::atomic shutdown_ = {false} | |
base::BoundedQueue event_queue_ | EventBasePtr e = std::make_shared() event_queue_.Enqueue(e) |
const int kFlushSize = 512 | |
const uint64_t kEventQueueSize = 8192 | |
class EventBase
成员变量/protected | 值 |
---|
int etype_ | |
int eid_ | |
uint64_t stamp_ | |
class TransportEvent
PerfEventCache::Instance()->AddTransportEvent(
TransPerf::TRANS_FROM, attr_.channel_id(), msg_info_.seq_num())
class TransportEvent : public EventBase | 值 |
---|
uint64_t msg_seq_ = 0; | msg_seq=msg_info_.seq_num() |
uint64_t channel_id_ = UINT64_MAX; | channel_id=attr_.channel_id() |
int etype_ | EventType::TRANS_EVENT |
int eid_ | static_cast(event_id),其中event_id=TransPerf::TRANS_FROM |
uint64_t stamp_ | Time::Now().ToNanosecond() |
class NotifierFactory
成员函数 | 属性 |
---|
static NotifierPtr CreateNotifier() | public |
static NotifierPtr CreateConditionNotifier() | private |
static NotifierPtr CreateMulticastNotifier() | private |
class NotifierBase
成员函数 | 属性 |
---|
virtual ~NotifierBase() = default | public |
virtual void Shutdown() = 0 | public |
virtual bool Notify(const ReadableInfo& info) = 0 | public |
virtual bool Listen(int timeout_ms, ReadableInfo* info) = 0 | public |
class MulticastNotifier
class MulticastNotifier : public NotifierBase | 值 |
---|
int notify_fd_ = -1 | |
struct sockaddr_in notify_addr_ | |
int listen_fd_ = -1 | |
struct sockaddr_in listen_addr_ | |
std::atomic is_shutdown_ = {false} | |
class ConditionNotifier
const uint32_t kBufLength = 4096;
class ConditionNotifier : public NotifierBase | 值 |
---|
key_t key_ = 0 | |
void* managed_shm_ = nullptr | |
size_t shm_size_ = 0 | |
Indicator* indicator_ = nullptr | 见下表 |
uint64_t next_listen_num_ = 0 | |
std::atomic is_shutdown_ = {false} | |
bool ConditionNotifier::Notify(const ReadableInfo& info)
ndicator* indicator_ | 值 |
---|
std::mutex mtx; | |
std::condition_variable cv; | indicator_->cv.notify_all() |
uint64_t written_info_num = 0; | ++indicator_->written_info_num |
ReadableInfo infos[kBufLength]; | indicator_->infos[idx] = info |
class ReaderBase
成员变量/protected | 值 |
---|
proto::RoleAttributes role_attr_ | role_attr__.id=receiver_->id().HashValue(), 其他部分与new_attr相同 |
std::atomic init_ | true |
class Reader
class Reader : public ReaderBase | 值 |
---|
double latest_recv_time_sec_ = -1.0 | |
double second_to_lastest_recv_time_sec_ = -1.0 | |
uint32_t pending_queue_size_ | const uint32_t DEFAULT_PENDING_QUEUE_SIZE = 1 |
CallbackFunc reader_func_ | reader_fun,用户回调函数 |
ReceiverPtr receiver_ = nullptr | ReceiverManager::Instance()->GetReceiver(role_attr_) |
std::string croutine_name_ | role_attr_.node_name() + "" + role_attr.channel_name() |
BlockerPtr blocker_ = nullptr | 见下表 |
ChangeConnection change_conn_ | channel_manager_->AddChangeListener(std::bind( &Writer::OnChannelChange, this, std::placeholders::_1)); =Connection |
service_discovery::ChannelManagerPtr channel_manager_ = nullptr | service_discovery::TopologyManager::Instance()->channel_manager() |
成员函数 | 局部变量 |
---|
Reader::Reader(const proto::RoleAttributes& role_attr, const CallbackFunc& reader_func, uint32_t pending_queue_size) | blocker_.reset(new blocker::Blocker(blocker::BlockerAttr(role_attr.qos_profile().depth(), role_attr.channel_name()))); |
bool Reader::Init() | std::function<void(const std::shared_ptr&)> func; auto dv = std::make_shared< data::DataVisitor>( |
struct BlockerAttr
成员变量 | 值 |
---|
size_t capacity | role_attr.qos_profile().depth() |
std::string channel_name | role_attr.channel_name() |
class Blocker
class Blocker : public BlockerBase | 值 |
---|
BlockerAttr attr_ | blocker::BlockerAttr(role_attr.qos_profile().depth(), role_attr.channel_name()) |
MessageQueue observed_msg_queue_ | |
MessageQueue published_msg_queue_ | |
mutable std::mutex msg_mutex_ | |
CallbackMap published_callbacks_ | |
mutable std::mutex cb_mutex_ | |
MessageType dummy_msg_ | dummy_msg_() |
class ReceiverManager
成员变量 | 值 |
---|
std::unordered_map<std::string,typename std::shared_ptr< transport::Receiver>> receiver_map_; | 函数GetReceiver(const proto::RoleAttributes& role_attr)中修改 |
std::mutex receiver_map_mutex_; | |
class DataNotifier
using NotifyVector = std::vector < std::shared_ptr>;
成员变量 | 值 |
---|
std::mutex notifies_map_mutex_; | |
AtomicHashMap<uint64_t, NotifyVector> notifies_map_; | |
struct Notifier
成员变量 | 值 |
---|
std::function<void()> callback | |
class DataVisitorBase
成员变量 | 值 |
---|
uint64_t next_msg_index_ = 0 | |
DataNotifier* data_notifier_ | DataNotifier::Instance(),data_notifier_->AddNotifier(buffer_.channel_id(), notifier_) |
std::shared_ptr notifier_ | notifier_->callback = callback,在RegisterNotifyCallback函数中 |
class DataVisitor
bool Reader::Init()函数中
auto dv = std::make_shared < data::DataVisitor>(role_attr_.channel_id(), pending_queue_size_);
class DataVisitor<M0, NullType, NullType, NullType> : public DataVisitorBase | 值 |
---|
ChannelBuffer buffer_ | buffer_(channel_id, new BufferType(queue_size)) |
class ChannelBuffer
using BufferType = CacheBuffer< std::shared_ptr>;
成员变量 | 值 |
---|
uint64_t channel_id_ | channel_id |
std::shared_ptr buffer_ | new BufferType(queue_size) |
class CacheBuffer
成员变量 | 值 |
---|
uint64_t head_ = 0; | |
uint64_t tail_ = 0; | |
uint64_t capacity_ = 0; | queue_size+1 |
std::vector buffer_; | buffer_.resize(capacity_); |
mutable std::mutex mutex_; | |
class DataDispatcher
using BufferVector =
std::vector< std::weak_ptr< CacheBuffer< std::shared_ptr>>>;
成员变量 | 值 |
---|
DataNotifier* notifier_ | DataNotifier::Instance() |
std::mutex buffers_map_mutex_ | |
AtomicHashMap<uint64_t, BufferVector> buffers_map_ | 修改于DataDispatcher::Instance()->AddBuffer(buffer_) |
class RoutineFactory
using VoidFunc = std::function<void()>;
using CreateRoutineFunc = std::function<VoidFunc()>;
成员变量 | 值 |
---|
std::shared_ptr < data::DataVisitorBase> data_visitor_ = nullptr | dv,函数bool Reader::Init()中 |
CreateRoutineFunc create_routine | 函数CreateRoutineFactory中 |
class Signal
using ConnectionType = Connection<Args…>;
成员变量 | 值 |
---|
SlotList slots_ | cb=OnChannelChange; slot = std::make_shared<Slot<Args…>>(cb); slots_.emplace_back(slot); |
std::mutex mutex_ | |
class Slot
cb=OnChannelChange;
slot = std::make_shared<Slot<Args…>>(cb);
成员变量 | 值 |
---|
Callback cb_ | cb |
bool connected_ | true默认 |
class Connection
using SlotPtr = std::shared_ptr<Slot<Args…>>;
using SignalPtr = Signal<Args…>*;
Connection在函数 ConnectionType Connect(const Callback& cb)中创建
return ConnectionType(slot, this);
成员变量 | 值 |
---|
SlotPtr slot_ | slot |
SignalPtr signal_ | signal |
class Receiver
using MessagePtr = std::shared_ptr;
using MessageListener = std::function<void( const MessagePtr&, const MessageInfo&, const RoleAttributes&)>;
class Receiver : public Endpoint | 值 |
---|
MessageListener msg_listener | msg_listener,在ReceiverManager::GetReceiver中修改 |
class ShmReceiver
using ShmDispatcherPtr = ShmDispatcher*;
class ShmReceiver : public Receiver | 值 |
---|
ShmDispatcherPtr dispatcher_ | ShmDispatcher::Instance() |
.
class Dispatcher
成员变量/protected | 值 |
---|
std::atomic is_shutdown_; | false |
AtomicHashMap<uint64_t, ListenerHandlerBasePtr> msg_listeners_; | |
base::AtomicRWLock rw_lock_; | |
class ShmDispatcher
using SegmentContainer = std::unordered_map<uint64_t, SegmentPtr>;
成员变量 | 值 |
---|
uint64_t host_id_ | common::Hash(GlobalData::Instance()->HostIp()) |
SegmentContainer segments_ | |
std::unordered_map<uint64_t, uint32_t> previous_indexes_ | |
AtomicRWLock segments_lock_ | |
std::thread thread_ | std::thread(&ShmDispatcher::ThreadFunc, this); scheduler::Instance()->SetInnerThreadAttr(&thread_, “shm_disp”); |
NotifierPtr notifier_ | NotifierFactory::CreateNotifier()=ConditionNotifier::Instance() |
struct Indicator
成员变量 | 值 |
---|
std::mutex mtx | |
std::condition_variable cv | |
uint64_t written_info_num = 0 | |
ReadableInfo infos[kBufLength] | kBufLength = 4096 |
class ListenerHandlerBase
成员变量 | 值 |
---|
bool is_raw_message_ = false | |
class ListenerHandler
using Message = std::shared_ptr;
using MessageSignal = base::Signal<const Message&, const MessageInfo&>;
using Listener = std::function<void(const Message&, const MessageInfo&)>;
using MessageConnection =base::Connection<const Message&, const MessageInfo&>;
using ConnectionMap = std::unordered_map<uint64_t, MessageConnection>;
using SignalPtr = std::shared_ptr;
using MessageSignalMap = std::unordered_map<uint64_t, SignalPtr>;
class ListenerHandler : public ListenerHandlerBase | 值 |
---|
MessageSignal signal_ | |
ConnectionMap signal_conns_ | |
MessageSignalMap signals_ | |
std::unordered_map<uint64_t, ConnectionMap> signals_conns_ | |
base::AtomicRWLock rw_lock_ | |
调度
class Scheduler
成员变量 /protected | 值 |
---|
AtomicRWLock id_cr_lock_ | class |
std::unordered_map<uint64_t, std::mutex> id_cr_wl_ | |
std::mutex cr_wl_mtx_ | |
std::unordered_map<uint64_t, std::shared_ptr> id_cr_ | id_cr_[cr->id()] = cr,在SchedulerClassic::DispatchTask中 |
std::vector< std::shared_ptr> pctxs_ | pctxs_.emplace_back(ctx),在SchedulerClassic::CreateProcessor()函数中 |
std::vector< std::shared_ptr> processors_ | processors_.emplace_back(proc) |
uint32_t proc_num_ = 0 | |
uint32_t task_pool_size_ = 0 | |
std::atomic stop_ | |
成员函数 | 值 |
---|
bool CreateTask(const RoutineFactory& factory, const std::string& name) | |
bool CreateTask(std::function<void()>&& func, const std::string& name, std::shared_ptr visitor = nullptr); | |
class SchedulerChoreography
class SchedulerChoreography : public Scheduler | 值 |
---|
std::unordered_map<std::string, ChoreographyTask> cr_confs_ | |
std::unordered_map<std::string, InnerThread> inner_thr_confs_ | |
int32_t choreography_processor_prio_ | |
int32_t pool_processor_prio_ | |
std::string choreography_affinity_ | |
std::string pool_affinity_ | |
std::string choreography_processor_policy_ | |
std::string pool_processor_policy_ | |
std::vector choreography_cpuset_ | |
std::vector pool_cpuset_ | |
class SchedulerClassic
class SchedulerClassic : public Scheduler | 值 |
---|
std::unordered_map<std::string, ClassicTask> cr_confs_ | cr_confs_[task.name()] = task,在SchedulerClassic 构造函数中,一个read是一个task |
ClassicConf classic_conf_ | classic_conf_ = cfg.scheduler_conf().classic_conf(); |
class CRoutine
在函数Scheduler::CreateTask中
auto cr = std::make_shared(func);
成员变量 | 值 |
---|
std::string name_ | name=role_attr_.node_name() + "" + role_attr.channel_name(); |
std::chrono::steady_clock::time_point wake_time_ | std::chrono::steady_clock::now() |
RoutineFunc func_ | func |
RoutineState state_ | RoutineState::READY |
std::atomic_flag lock_ = ATOMIC_FLAG_INIT | |
std::atomic_flag updated_ = ATOMIC_FLAG_INIT | test_and_set(std::memory_order_release) |
std::shared_ptr context_ | context_pool->GetObject() |
bool force_stop_ = false | |
int processor_id_ = -1; | |
uint32_t priority_ = 0; | cr->set_priority(task.prio()) |
uint64_t id_ = 0; | GlobalData::RegisterTaskName(name) ,其中name=role_attr_.node_name() + "" + role_attr.channel_name(); |
std::string group_name_ | cr->set_group_name(task.group_name()) |
static thread_local CRoutine *current_routine_ | |
static thread_local char *main_stack_ | |
class CCObjectPool
成员变量 | 值 |
---|
std::atomic free_head_ | free_head_.store({0, node_arena_}, std::memory_order_relaxed) |
Node *node_arena_ = nullptr | static_cast<Node *>(CheckedCalloc(capacity_, sizeof(Node))) |
uint32_t capacity_ = 0 | routine_num = 100 |
class Processor
成员变量 | 值 |
---|
std::shared_ptr context_ | proc->BindContext(ctx); |
std::condition_variable cv_ctx_ | |
std::once_flag thread_flag_ | |
std::mutex mtx_ctx_ | |
std::thread thread_ | thread_ = std::thread(&Processor::Run, this); |
std::atomic<pid_t> tid_{-1} | |
std::atomic running_{false} | |
class ProcessorContext
成员变量 | 值 |
---|
bool stop_ = false | |
alignas(CACHELINE_SIZE) std::atomic_flag notified_ = ATOMIC_FLAG_INIT | |
class ClassicContext
static constexpr uint32_t MAX_PRIO = 20;
#define DEFAULT_GROUP_NAME “default_grp”
using CROUTINE_QUEUE = std::vector< std::shared_ptr>;
using MULTI_PRIO_QUEUE = std::array<CROUTINE_QUEUE, MAX_PRIO>;
using CR_GROUP = std::unordered_map<std::string, MULTI_PRIO_QUEUE>;
using LOCK_QUEUE = std::array<base::AtomicRWLock, MAX_PRIO>;
using RQ_LOCK_GROUP = std::unordered_map<std::string, LOCK_QUEUE>;
using GRP_WQ_MUTEX = std::unordered_map<std::string, std::mutex>;
using GRP_WQ_CV = std::unordered_map<std::string, std::condition_variable> ;
成员变量 | 值 |
---|
std::string group_name_ | ctx->SetGroupName(group_name); |
alignas(CACHELINE_SIZE) static RQ_LOCK_GROUP rq_locks_ | ClassicContext::rq_locks_[group_name],在SchedulerClassic::CreateProcessor()函数中 |
alignas(CACHELINE_SIZE) static CR_GROUP cr_group | ClassicContext::cr_group_[group_name] ,在SchedulerClassic::CreateProcessor()中 cr_group_[cr->group_name()].at(cr->priority()) |
alignas(CACHELINE_SIZE) static GRP_WQ_MUTEX mtx_wq_ | .emplace_back(cr);ClassicContext::mtx_wq_[group_name] |
alignas(CACHELINE_SIZE) static GRP_WQ_CV cv_wq_ | ClassicContext::cv_wq_[group_name],在SchedulerClassic::CreateProcessor()函数中;cv_wq_[group_name].notify_one(),在void ClassicContext::Notify(const std::string& group_name) 函数中 |
std::chrono::steady_clock::time_point wake_time_; | |
bool need_sleep_ = false; | |
struct RoutineContext
constexpr size_t STACK_SIZE = 8 * 1024 * 1024;
constexpr size_t REGISTERS_SIZE = 56;
成员变量 | 值 |
---|
char stack[STACK_SIZE] | |
char* sp = nullptr | |
模块
class AbstractClassFactoryBase
成员变量 | 值 |
---|
std::vector<ClassLoader*> relative_class_loaders_ | |
std::string relative_library_path_ | |
std::string base_class_name_ | |
std::string class_name_ | |