FlowControllerImpl::run()开启过程
在RTPSParticipantImpl的构造函数中会初始化FlowControllerFactory flow_controller_factory_成员:
flow_controller_factory_.init(this);
FlowControllerFactory中有个map:
std::map<std::string, std::unique_ptr<FlowController>> flow_controllers_;
会向flow_controllers_中注册几个FlowControllerImpl。
然后在RTPSParticipantImpl::create_writer中会调用如下接口:
fastdds::rtps::FlowController* flow_controller = nullptr;
//获取guid作为key
const char* flow_controller_name = param.flow_controller_name;
if (nullptr == flow_controller &&(fastdds::rtps::FASTDDS_FLOW_CONTROLLER_DEFAULT == flow_controller_name ||ASYNCHRONOUS_WRITER == param.mode))
{
//根据key从flow_controllers_中取出FlowController并初始化
flow_controller = flow_controller_factory_.retrieve_flow_controller(flow_controller_name, param);
}
从flow_controllers_中取出key == flow_controller_name 的FlowController,并调用其init方法。flow_controller_name:01.0f.f8.15.0b.12.7a.81.00.00.00.00|0.0.1.c1。
FlowController* returned_flow = nullptr;
returned_flow = flow_controllers_[async_flow_controller_name].get();
returned_flow->init();
void init() override
{
initialize_async_thread();
}
该线程用于发送数据:
initialize_async_thread()
{
bool expected = false;
if (async_mode.running.compare_exchange_strong(expected, true))
{
// Code for initializing the asynchronous thread.
async_mode.thread = std::thread(&FlowControllerImpl::run, this);
}
}
run线程开启之后会阻塞,等待发送通知:
while (async_mode.running && (async_mode.force_wait() || nullptr == (change_to_process = sched.get_next_change_nts())))
{
// Release main mutex to allow registering/unregistering writers while this thread is waiting.
lock.unlock();
//阻塞,等待通知
bool ret = async_mode.wait(in_lock);
in_lock.unlock();
lock.lock();
in_lock.lock();
if (ret)
{
sched.trigger_bandwidth_limit_reset();
}
sched.add_interested_changes_to_queue_nts();
}
}