FastDDS源码解析 九

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();
    }
}

  • 9
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值